[PATCH 08/11] perf intel-pt: Time filter logged perf events

From: Adrian Hunter
Date: Thu Jul 09 2020 - 13:37:31 EST


Change the debug logging (when used with the --time option) to time filter
logged perf events, but allow that to be overridden by using "d2" instead
of plain "d".

By default that can greatly reduce the size of the log file.

Signed-off-by: Adrian Hunter <adrian.hunter@xxxxxxxxx>
---
tools/perf/Documentation/perf-intel-pt.txt | 3 +++
tools/perf/util/intel-pt.c | 20 +++++++++++++++++---
2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/tools/perf/Documentation/perf-intel-pt.txt b/tools/perf/Documentation/perf-intel-pt.txt
index 85a2ff804900..9a90e2db4e4a 100644
--- a/tools/perf/Documentation/perf-intel-pt.txt
+++ b/tools/perf/Documentation/perf-intel-pt.txt
@@ -882,6 +882,9 @@ decoded packets and instructions. Note that this option slows down the decoder
and that the resulting file may be very large. The "d" option may be followed
by a number which has the following effect:
1 Suppress logging of perf events
+ 2 Log all perf events
+By default, logged perf events are filtered by any specified time ranges, but
+value 2 overrides that.

In addition, the period of the "instructions" event can be specified. e.g.

diff --git a/tools/perf/util/intel-pt.c b/tools/perf/util/intel-pt.c
index d90375659244..597120dd6b77 100644
--- a/tools/perf/util/intel-pt.c
+++ b/tools/perf/util/intel-pt.c
@@ -50,6 +50,7 @@
#define INTEL_PT_ERR_SUPPRESS_LOST 2

#define INTEL_PT_LOG_SUPPRESS_EV 1
+#define INTEL_PT_LOG_ALL_EV 2

struct range {
u64 start;
@@ -254,9 +255,22 @@ static void intel_pt_dump_sample(struct perf_session *session,
intel_pt_dump(pt, sample->aux_sample.data, sample->aux_sample.size);
}

-static bool intel_pt_log_events(struct intel_pt *pt)
+static bool intel_pt_log_events(struct intel_pt *pt, u64 tm)
{
- return !(pt->synth_opts.log_flags & INTEL_PT_LOG_SUPPRESS_EV);
+ struct perf_time_interval *range = pt->synth_opts.ptime_range;
+ int n = pt->synth_opts.range_num;
+
+ if (pt->synth_opts.log_flags & INTEL_PT_LOG_ALL_EV)
+ return true;
+
+ if (pt->synth_opts.log_flags & INTEL_PT_LOG_SUPPRESS_EV)
+ return false;
+
+ /* perf_time__ranges_skip_sample does not work if time is zero */
+ if (!tm)
+ tm = 1;
+
+ return !n || !perf_time__ranges_skip_sample(range, n, tm);
}

static int intel_pt_do_fix_overlap(struct intel_pt *pt, struct auxtrace_buffer *a,
@@ -2752,7 +2766,7 @@ static int intel_pt_process_event(struct perf_session *session,
if (!err && event->header.type == PERF_RECORD_TEXT_POKE)
err = intel_pt_text_poke(pt, event);

- if (intel_pt_enable_logging && intel_pt_log_events(pt)) {
+ if (intel_pt_enable_logging && intel_pt_log_events(pt, sample->time)) {
intel_pt_log("event %u: cpu %d time %"PRIu64" tsc %#"PRIx64" ",
event->header.type, sample->cpu, sample->time, timestamp);
intel_pt_log_event(event);
--
2.25.1