]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/commitdiff
perf tools: Enable overwrite settings
authorWang Nan <wangnan0@huawei.com>
Thu, 14 Jul 2016 08:34:45 +0000 (08:34 +0000)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 15 Jul 2016 20:27:51 +0000 (17:27 -0300)
This patch allows following config terms and option:

Globally setting events to overwrite;

  # perf record --overwrite ...

Set specific events to be overwrite or no-overwrite.

  # perf record --event cycles/overwrite/ ...
  # perf record --event cycles/no-overwrite/ ...

Add missing config terms and update the config term array size because
the longest string length has changed.

For overwritable events, it automatically selects attr.write_backward
since perf requires it to be backward for reading.

Test result:

  # perf record --overwrite -e syscalls:*enter_nanosleep* usleep 1
  [ perf record: Woken up 2 times to write data ]
  [ perf record: Captured and wrote 0.011 MB perf.data (1 samples) ]
  # perf evlist -v
  syscalls:sys_enter_nanosleep: type: 2, size: 112, config: 0x134, { sample_period, sample_freq }: 1, sample_type: IP|TID|TIME|CPU|PERIOD|RAW, disabled: 1, inherit: 1, mmap: 1, comm: 1, enable_on_exec: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1, write_backward: 1
  # Tip: use 'perf evlist --trace-fields' to show fields for tracepoint events

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Nilay Vaish <nilayvaish@gmail.com>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1468485287-33422-14-git-send-email-wangnan0@huawei.com
Signed-off-by: He Kuang <hekuang@huawei.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Documentation/perf-record.txt
tools/perf/builtin-record.c
tools/perf/perf.h
tools/perf/tests/backward-ring-buffer.c
tools/perf/util/evsel.c
tools/perf/util/evsel.h
tools/perf/util/parse-events.c
tools/perf/util/parse-events.h
tools/perf/util/parse-events.l

index 5b46b1d1a37c93ff0c046f5e6f249dfdb110ac19..384c630436f8fea08f753a7c9f746dfae9f436a0 100644 (file)
@@ -367,6 +367,20 @@ options.
 'perf record --dry-run -e' can act as a BPF script compiler if llvm.dump-obj
 in config file is set to true.
 
+--overwrite::
+Makes all events use an overwritable ring buffer. An overwritable ring
+buffer works like a flight recorder: when it gets full, the kernel will
+overwrite the oldest records, that thus will never make it to the
+perf.data file.
+
+When '--overwrite' and '--switch-output' are used perf records and drops
+events until it receives a signal, meaning that something unusual was
+detected that warrants taking a snapshot of the most current events,
+those fitting in the ring buffer at that moment.
+
+'overwrite' attribute can also be set or canceled for an event using
+config terms. For example: 'cycles/overwrite/' and 'instructions/no-overwrite/'.
+
 SEE ALSO
 --------
 linkperf:perf-stat[1], linkperf:perf-list[1]
index b87070b1f492b82e7cd15dc83bd53f947ff3bb90..39c7486f0607b21ceb0e4ee1d4ab262a03d90ff8 100644 (file)
@@ -1399,6 +1399,7 @@ struct option __record_options[] = {
        OPT_BOOLEAN_SET('i', "no-inherit", &record.opts.no_inherit,
                        &record.opts.no_inherit_set,
                        "child tasks do not inherit counters"),
+       OPT_BOOLEAN(0, "overwrite", &record.opts.overwrite, "use overwrite mode"),
        OPT_UINTEGER('F', "freq", &record.opts.user_freq, "profile at this frequency"),
        OPT_CALLBACK('m', "mmap-pages", &record.opts, "pages[,pages]",
                     "number of mmap data pages and AUX area tracing mmap pages",
index cd8f1b150f9ec67ec2e3aef5dd45f6eee7918e89..608b42bdb1b605563fedefcbdffec7d9b6ba3a86 100644 (file)
@@ -59,6 +59,7 @@ struct record_opts {
        bool         record_switch_events;
        bool         all_kernel;
        bool         all_user;
+       bool         overwrite;
        unsigned int freq;
        unsigned int mmap_pages;
        unsigned int auxtrace_mmap_pages;
index db9cd3048655b824ae80f8ccf0db9a002b4fb9b4..615780cbfe1d86dce93bc4dfb60e6850a42797b0 100644 (file)
@@ -108,7 +108,11 @@ int test__backward_ring_buffer(int subtest __maybe_unused)
        }
 
        bzero(&parse_error, sizeof(parse_error));
-       err = parse_events(evlist, "syscalls:sys_enter_prctl", &parse_error);
+       /*
+        * Set backward bit, ring buffer should be writing from end. Record
+        * it in aux evlist
+        */
+       err = parse_events(evlist, "syscalls:sys_enter_prctl/overwrite/", &parse_error);
        if (err) {
                pr_debug("Failed to parse tracepoint event, try use root\n");
                ret = TEST_SKIP;
@@ -117,10 +121,6 @@ int test__backward_ring_buffer(int subtest __maybe_unused)
 
        perf_evlist__config(evlist, &opts, NULL);
 
-       /* Set backward bit, ring buffer should be writing from end */
-       evlist__for_each_entry(evlist, evsel)
-               evsel->attr.write_backward = 1;
-
        err = perf_evlist__open(evlist);
        if (err < 0) {
                pr_debug("perf_evlist__open: %s\n",
index 9ac2f92ce88de180a8b1ccac858eeb38c96e2567..8c54df61fe642d0245c72f88a3d6a300af8f5d26 100644 (file)
@@ -695,6 +695,9 @@ static void apply_config_terms(struct perf_evsel *evsel,
                         */
                        attr->inherit = term->val.inherit ? 1 : 0;
                        break;
+               case PERF_EVSEL__CONFIG_TERM_OVERWRITE:
+                       attr->write_backward = term->val.overwrite ? 1 : 0;
+                       break;
                default:
                        break;
                }
@@ -776,6 +779,7 @@ 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;
 
        perf_evsel__set_sample_bit(evsel, IP);
        perf_evsel__set_sample_bit(evsel, TID);
index e60cbfc2cd3532edd489e76b69e4ba44a3f7ef1c..8a4a6c9f14808032904314cf398ddcda2d2dc127 100644 (file)
@@ -45,6 +45,7 @@ enum {
        PERF_EVSEL__CONFIG_TERM_STACK_USER,
        PERF_EVSEL__CONFIG_TERM_INHERIT,
        PERF_EVSEL__CONFIG_TERM_MAX_STACK,
+       PERF_EVSEL__CONFIG_TERM_OVERWRITE,
        PERF_EVSEL__CONFIG_TERM_MAX,
 };
 
@@ -59,6 +60,7 @@ struct perf_evsel_config_term {
                u64     stack_user;
                int     max_stack;
                bool    inherit;
+               bool    overwrite;
        } val;
 };
 
index 375af0e02831e603bd4b2f1d36aea0d7822be795..6c913c3914fb92163a6f8cabda62c0282b64c38e 100644 (file)
@@ -902,6 +902,8 @@ static const char *config_term_names[__PARSE_EVENTS__TERM_TYPE_NR] = {
        [PARSE_EVENTS__TERM_TYPE_NOINHERIT]             = "no-inherit",
        [PARSE_EVENTS__TERM_TYPE_INHERIT]               = "inherit",
        [PARSE_EVENTS__TERM_TYPE_MAX_STACK]             = "max-stack",
+       [PARSE_EVENTS__TERM_TYPE_OVERWRITE]             = "overwrite",
+       [PARSE_EVENTS__TERM_TYPE_NOOVERWRITE]           = "no-overwrite",
 };
 
 static bool config_term_shrinked;
@@ -994,6 +996,12 @@ do {                                                                          \
        case PARSE_EVENTS__TERM_TYPE_NOINHERIT:
                CHECK_TYPE_VAL(NUM);
                break;
+       case PARSE_EVENTS__TERM_TYPE_OVERWRITE:
+               CHECK_TYPE_VAL(NUM);
+               break;
+       case PARSE_EVENTS__TERM_TYPE_NOOVERWRITE:
+               CHECK_TYPE_VAL(NUM);
+               break;
        case PARSE_EVENTS__TERM_TYPE_NAME:
                CHECK_TYPE_VAL(STR);
                break;
@@ -1046,6 +1054,8 @@ static int config_term_tracepoint(struct perf_event_attr *attr,
        case PARSE_EVENTS__TERM_TYPE_INHERIT:
        case PARSE_EVENTS__TERM_TYPE_NOINHERIT:
        case PARSE_EVENTS__TERM_TYPE_MAX_STACK:
+       case PARSE_EVENTS__TERM_TYPE_OVERWRITE:
+       case PARSE_EVENTS__TERM_TYPE_NOOVERWRITE:
                return config_term_common(attr, term, err);
        default:
                if (err) {
@@ -1118,6 +1128,12 @@ do {                                                             \
                case PARSE_EVENTS__TERM_TYPE_MAX_STACK:
                        ADD_CONFIG_TERM(MAX_STACK, max_stack, term->val.num);
                        break;
+               case PARSE_EVENTS__TERM_TYPE_OVERWRITE:
+                       ADD_CONFIG_TERM(OVERWRITE, overwrite, term->val.num ? 1 : 0);
+                       break;
+               case PARSE_EVENTS__TERM_TYPE_NOOVERWRITE:
+                       ADD_CONFIG_TERM(OVERWRITE, overwrite, term->val.num ? 0 : 1);
+                       break;
                default:
                        break;
                }
@@ -2412,9 +2428,9 @@ static void config_terms_list(char *buf, size_t buf_sz)
 char *parse_events_formats_error_string(char *additional_terms)
 {
        char *str;
-       /* "branch_type" is the longest name */
+       /* "no-overwrite" is the longest name */
        char static_terms[__PARSE_EVENTS__TERM_TYPE_NR *
-                         (sizeof("branch_type") - 1)];
+                         (sizeof("no-overwrite") - 1)];
 
        config_terms_list(static_terms, sizeof(static_terms));
        /* valid terms */
index b4aa7eb2df7312781f59dcf8e31f00a66f46dc54..d1edbf8cc66a7704cf774c3f3fc80fee8f1a31bd 100644 (file)
@@ -69,6 +69,8 @@ enum {
        PARSE_EVENTS__TERM_TYPE_NOINHERIT,
        PARSE_EVENTS__TERM_TYPE_INHERIT,
        PARSE_EVENTS__TERM_TYPE_MAX_STACK,
+       PARSE_EVENTS__TERM_TYPE_NOOVERWRITE,
+       PARSE_EVENTS__TERM_TYPE_OVERWRITE,
        __PARSE_EVENTS__TERM_TYPE_NR,
 };
 
index 3c15b33b2e84aceb85eb651364f2c15bbd76d6fc..7a2519435da05273febd9af1974637cbc1c5d8c7 100644 (file)
@@ -202,6 +202,8 @@ stack-size          { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_STACKSIZE); }
 max-stack              { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_MAX_STACK); }
 inherit                        { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_INHERIT); }
 no-inherit             { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NOINHERIT); }
+overwrite              { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_OVERWRITE); }
+no-overwrite           { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NOOVERWRITE); }
 ,                      { return ','; }
 "/"                    { BEGIN(INITIAL); return '/'; }
 {name_minus}           { return str(yyscanner, PE_NAME); }