perf record: Add support for AUX area sampling
authorAdrian Hunter <adrian.hunter@intel.com>
Fri, 15 Nov 2019 12:42:16 +0000 (14:42 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 22 Nov 2019 13:48:13 +0000 (10:48 -0300)
Add a 'perf record' option '--aux-sample' to request AUX area sampling.
AUX area sampling uses an overwriting buffer much like snapshot mode, so
adjust the AUX buffer mmapping accordingly. To make it easy to queue
samples for decoding, synthesize an ID index.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: http://lore.kernel.org/lkml/20191115124225.5247-7-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Documentation/perf-record.txt
tools/perf/builtin-record.c

index ebcba1f..e216d7b 100644 (file)
@@ -433,6 +433,12 @@ can be specified in a string that follows this option:
 In Snapshot Mode trace data is captured only when signal SIGUSR2 is received
 and on exit if the above 'e' option is given.
 
+--aux-sample[=OPTIONS]::
+Select AUX area sampling. At least one of the events selected by the -e option
+must be an AUX area event. Samples on other events will be created containing
+data from the AUX area. Optionally sample size may be specified, otherwise it
+defaults to 4KiB.
+
 --proc-map-timeout::
 When processing pre-existing threads /proc/XXX/mmap, it may take a long time,
 because the file may be huge. A time out is needed in such cases.
index 7ab3110..b5063d3 100644 (file)
@@ -680,6 +680,11 @@ static int record__auxtrace_init(struct record *rec)
        if (err)
                return err;
 
+       err = auxtrace_parse_sample_options(rec->itr, rec->evlist, &rec->opts,
+                                           rec->opts.auxtrace_sample_opts);
+       if (err)
+               return err;
+
        return auxtrace_parse_filters(rec->evlist);
 }
 
@@ -752,6 +757,8 @@ static int record__mmap_evlist(struct record *rec,
                               struct evlist *evlist)
 {
        struct record_opts *opts = &rec->opts;
+       bool auxtrace_overwrite = opts->auxtrace_snapshot_mode ||
+                                 opts->auxtrace_sample_mode;
        char msg[512];
 
        if (opts->affinity != PERF_AFFINITY_SYS)
@@ -759,7 +766,7 @@ static int record__mmap_evlist(struct record *rec,
 
        if (evlist__mmap_ex(evlist, opts->mmap_pages,
                                 opts->auxtrace_mmap_pages,
-                                opts->auxtrace_snapshot_mode,
+                                auxtrace_overwrite,
                                 opts->nr_cblocks, opts->affinity,
                                 opts->mmap_flush, opts->comp_level) < 0) {
                if (errno == EPERM) {
@@ -1046,6 +1053,7 @@ static int record__mmap_read_evlist(struct record *rec, struct evlist *evlist,
                }
 
                if (map->auxtrace_mmap.base && !rec->opts.auxtrace_snapshot_mode &&
+                   !rec->opts.auxtrace_sample_mode &&
                    record__auxtrace_mmap_read(rec, map) != 0) {
                        rc = -1;
                        goto out;
@@ -1321,6 +1329,15 @@ static int record__synthesize(struct record *rec, bool tail)
        if (err)
                goto out;
 
+       /* Synthesize id_index before auxtrace_info */
+       if (rec->opts.auxtrace_sample_mode) {
+               err = perf_event__synthesize_id_index(tool,
+                                                     process_synthesized_event,
+                                                     session->evlist, machine);
+               if (err)
+                       goto out;
+       }
+
        if (rec->opts.full_auxtrace) {
                err = perf_event__synthesize_auxtrace_info(rec->itr, tool,
                                        session, process_synthesized_event);
@@ -2329,6 +2346,8 @@ static struct option __record_options[] = {
        parse_clockid),
        OPT_STRING_OPTARG('S', "snapshot", &record.opts.auxtrace_snapshot_opts,
                          "opts", "AUX area tracing Snapshot Mode", ""),
+       OPT_STRING_OPTARG(0, "aux-sample", &record.opts.auxtrace_sample_opts,
+                         "opts", "sample AUX area", ""),
        OPT_UINTEGER(0, "proc-map-timeout", &proc_map_timeout,
                        "per thread proc mmap processing timeout in ms"),
        OPT_BOOLEAN(0, "namespaces", &record.opts.record_namespaces,