perf record: Add an option to take an AUX snapshot on exit
Alexander Shishkin
reviewerPATCH 1/1 perf record: Add an option to take an AUX snapshot on exit
It is sometimes useful to generate a snapshot when perf record exits; I've been using a wrapper script around the workload that would do a killall -USR2 perf when the workload exits.
This patch makes it easier and also works when perf record is attached to a pre-existing task. A new snapshot option 'e' can be specified in -S to enable this behavior:
root@elsewhere:~# perf record -e intel_pt// -Se sleep 1 [ perf record: Woken up 2 times to write data ] [ perf record: Captured and wrote 0.085 MB perf.data ]
--- tools/perf/Documentation/perf-record.txt | 11 ++++++++--- tools/perf/builtin-record.c | 4 ++++ tools/perf/perf.h | 1 + tools/perf/util/auxtrace.c | 10 ++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-record.txt +8 -3
@@ -387,9 +387,14 @@ CLOCK_BOOTTIME, CLOCK_REALTIME and CLOCK_TAI. -S:: --snapshot:: Select AUX area tracing Snapshot Mode. This option is valid only with an -AUX area tracing event. Optionally the number of bytes to capture per -snapshot can be specified. In Snapshot Mode, trace data is captured only when -signal SIGUSR2 is received. +AUX area tracing event. Optionally, certain snapshot capturing parameters +can be specified in a string that follows this option: + 'e': take one last snapshot on exit; guarantees that there is at least one + snapshot in the output file; + <size>: if the PMU supports this, specify the desired snapshot size. + +In Snapshot Mode trace data is captured only when signal SIGUSR2 is received +and on exit if the above 'e' option is given. --proc-map-timeout:: When processing pre-existing threads /proc/XXX/mmap, it may take a long time,
tools/perf/builtin-record.c +4 -0
@@ -1136,6 +1136,10 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) disabled = true; } } + +if (opts->auxtrace_snapshot_on_exit) +record__read_auxtrace_snapshot (rec); +trigger_off (&auxtrace_snapshot_trigger);trigger_off (&switch_output_trigger);
tools/perf/perf.h +1 -0
@@ -50,6 +50,7 @@ struct record_opts {bool running_time;bool full_auxtrace;bool auxtrace_snapshot_mode; +bool auxtrace_snapshot_on_exit;bool record_namespaces;bool record_switch_events;bool all_kernel;
tools/perf/util/auxtrace.c +10 -0
@@ -564,6 +564,16 @@ int auxtrace_parse_snapshot_options(struct auxtrace_record *itr,if (!str)return 0 ; +/* PMU-agnostic options */ +switch (*str) { +case 'e' : + opts->auxtrace_snapshot_on_exit = true; + str++; +break ; +default : +break ; + } +if (itr)return itr->parse_snapshot_options (itr, opts, str);
Signature · 1 line
2.11.0
Alexander Shishkin
reviewerQuoted 92 lines · Alexander Shishkin
It is sometimes useful to generate a snapshot when perf record exits; I've been using a wrapper script around the workload that would do a killall -USR2 perf when the workload exits.
This patch makes it easier and also works when perf record is attached to a pre-existing task. A new snapshot option 'e' can be specified in -S to enable this behavior:
root@elsewhere:~# perf record -e intel_pt// -Se sleep 1 [ perf record: Woken up 2 times to write data ] [ perf record: Captured and wrote 0.085 MB perf.data ]Signed-off-by Alexander Shishkin <[email protected]>--- tools/perf/Documentation/perf-record.txt | 11 ++++++++--- tools/perf/builtin-record.c | 4 ++++ tools/perf/perf.h | 1 + tools/perf/util/auxtrace.c | 10 ++++++++++ 4 files changed, 23 insertions(+), 3 deletions(-)tools/perf/Documentation/perf-record.txt +8
-3@@ -387,9 +387,14 @@ CLOCK_BOOTTIME, CLOCK_REALTIME and CLOCK_TAI. -S:: --snapshot:: Select AUX area tracing Snapshot Mode. This option is valid only with an -AUX area tracing event. Optionally the number of bytes to capture per -snapshot can be specified. In Snapshot Mode, trace data is captured only when -signal SIGUSR2 is received. +AUX area tracing event. Optionally, certain snapshot capturing parameters +can be specified in a string that follows this option: + 'e': take one last snapshot on exit; guarantees that there is at least one + snapshot in the output file; + <size>: if the PMU supports this, specify the desired snapshot size. + +In Snapshot Mode trace data is captured only when signal SIGUSR2 is received +and on exit if the above 'e' option is given. --proc-map-timeout:: When processing pre-existing threads /proc/XXX/mmap, it may take a long time,tools/perf/builtin-record.c +4
-0@@ -1136,6 +1136,10 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) disabled = true; } } + +if (opts->auxtrace_snapshot_on_exit) +record__read_auxtrace_snapshot (rec); +trigger_off (&auxtrace_snapshot_trigger);trigger_off (&switch_output_trigger);tools/perf/perf.h +1
-0@@ -50,6 +50,7 @@ struct record_opts {bool running_time;bool full_auxtrace;bool auxtrace_snapshot_mode; +bool auxtrace_snapshot_on_exit;bool record_namespaces;bool record_switch_events;bool all_kernel;tools/perf/util/auxtrace.c +10
-0@@ -564,6 +564,16 @@ int auxtrace_parse_snapshot_options(struct auxtrace_record *itr,if (!str)return 0 ; +/* PMU-agnostic options */ +switch (*str) { +case 'e' : + opts->auxtrace_snapshot_on_exit = true; + str++; +break ; +default : +break ; + } +if (itr)return itr->parse_snapshot_options (itr, opts, str);Signature · 1 line
2.11.0