[PATCH] perf record: enable multiplexing scaling via -R

From: Stephane Eranian
Date: Mon Aug 21 2017 - 15:14:19 EST


This patch allows perf record to request that event
timing be recorded in each sample. The timing consists
of time_enabled and time_running. These two values are
used to compute the multiplexing correction, i.e.,
how long an event was actually measured by the hardware.

To activate, the user must use:
$ perf record -a -R ....

The patch works by forcing PERF_SAMPLE_READ in raw mode (-R),
i.e., reading of the event group in each sample.

The side effect is that both time_running and time_enable are
captured + an empty four byte RAW section. This way we leverage
an existing perf record mode and do not add yet another option.

With this patch, it is possible to evaluate the total number
of occurrences of each sampling event even when multiplexing is
active.

Signed-off-by: Stephane Eranian <eranian@xxxxxxxxxx>
---
tools/perf/Documentation/perf-record.txt | 2 ++
tools/perf/util/evsel.c | 5 +++++
2 files changed, 7 insertions(+)

diff --git a/tools/perf/Documentation/perf-record.txt b/tools/perf/Documentation/perf-record.txt
index 9bdea047c5db..6a0bfd29bac9 100644
--- a/tools/perf/Documentation/perf-record.txt
+++ b/tools/perf/Documentation/perf-record.txt
@@ -270,6 +270,8 @@ OPTIONS
-R::
--raw-samples::
Collect raw sample records from all opened counters (default for tracepoint counters).
+With this option, each sample includes at least: CPU, timestamp, time running/enabled
+(multiplexing scaling factor).

-C::
--cpu::
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 3735c9e0080d..3305c0b10161 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -852,6 +852,9 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts,
attr->sample_id_all = perf_missing_features.sample_id_all ? 0 : 1;
attr->inherit = !opts->no_inherit;
attr->write_backward = opts->overwrite ? 1 : 0;
+ attr->read_format = PERF_FORMAT_TOTAL_TIME_ENABLED |
+ PERF_FORMAT_TOTAL_TIME_RUNNING |
+ PERF_FORMAT_ID;

perf_evsel__set_sample_bit(evsel, IP);
perf_evsel__set_sample_bit(evsel, TID);
@@ -945,6 +948,8 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts,
perf_evsel__set_sample_bit(evsel, TIME);
perf_evsel__set_sample_bit(evsel, RAW);
perf_evsel__set_sample_bit(evsel, CPU);
+ perf_evsel__set_sample_bit(evsel, ID);
+ perf_evsel__set_sample_bit(evsel, READ);
}

if (opts->sample_address)
--
2.7.4