perf tools: Per-event time support
authorKan Liang <kan.liang@intel.com>
Tue, 4 Aug 2015 08:30:19 +0000 (04:30 -0400)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 5 Aug 2015 15:50:52 +0000 (12:50 -0300)
This patchkit adds the ability to turn off time stamps per event.

One usaful case for partial time is to work with per-event callgraph to
enable "PEBS threshold > 1" (https://lkml.org/lkml/2015/5/10/196), which
can significantly reduce the sampling overhead.

The event samples with time stamps off will not be ordered.

Signed-off-by: Kan Liang <kan.liang@intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/1438677022-34296-2-git-send-email-kan.liang@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Documentation/perf-record.txt
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
tools/perf/util/pmu.c

index ac41350ca48511e07444393c69683069bc66d641..0d852d1bc90f0a514b00c6d6abcfb725f748f1c0 100644 (file)
@@ -49,7 +49,9 @@ OPTIONS
          These params can be used to overload default config values per event.
          Here is a list of the params.
          - 'period': Set event sampling period
-
+         - 'time': Disable/enable time stamping. Acceptable values are 1 for
+                   enabling time stamping. 0 for disabling time stamping.
+                   The default is 1.
          Note: If user explicitly sets options which conflict with the params,
          the value set by the params will be overridden.
 
index 7d3acba5a5122e30981da506704a1c10091de6dc..7febfe2557033f52005366f81d5a1b63693be1cf 100644 (file)
@@ -587,15 +587,23 @@ perf_evsel__config_callgraph(struct perf_evsel *evsel,
        }
 }
 
-static void apply_config_terms(struct perf_event_attr *attr __maybe_unused,
-                              struct list_head *config_terms)
+static void apply_config_terms(struct perf_evsel *evsel)
 {
        struct perf_evsel_config_term *term;
+       struct list_head *config_terms = &evsel->config_terms;
+       struct perf_event_attr *attr = &evsel->attr;
 
        list_for_each_entry(term, config_terms, list) {
                switch (term->type) {
                case PERF_EVSEL__CONFIG_TERM_PERIOD:
                        attr->sample_period = term->val.period;
+                       break;
+               case PERF_EVSEL__CONFIG_TERM_TIME:
+                       if (term->val.time)
+                               perf_evsel__set_sample_bit(evsel, TIME);
+                       else
+                               perf_evsel__reset_sample_bit(evsel, TIME);
+                       break;
                default:
                        break;
                }
@@ -798,7 +806,7 @@ void perf_evsel__config(struct perf_evsel *evsel, struct record_opts *opts)
         * Apply event specific term settings,
         * it overloads any global configuration.
         */
-       apply_config_terms(attr, &evsel->config_terms);
+       apply_config_terms(evsel);
 }
 
 static int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads)
index a7d2175358b8bf416c7048b506f08d89b4e99808..6a129081f3ad918cd6832b3700de90d7ede0255b 100644 (file)
@@ -39,6 +39,7 @@ struct cgroup_sel;
 */
 enum {
        PERF_EVSEL__CONFIG_TERM_PERIOD,
+       PERF_EVSEL__CONFIG_TERM_TIME,
        PERF_EVSEL__CONFIG_TERM_MAX,
 };
 
@@ -47,6 +48,7 @@ struct perf_evsel_config_term {
        int     type;
        union {
                u64     period;
+               bool    time;
        } val;
 };
 
index 09bee93fd0ec681fd0502607214ae493684fa016..a6cb9afc20e28539f5d323bd34fc641fbe1bf681 100644 (file)
@@ -603,6 +603,14 @@ do {                                                                          \
                 * attr->branch_sample_type = term->val.num;
                 */
                break;
+       case PARSE_EVENTS__TERM_TYPE_TIME:
+               CHECK_TYPE_VAL(NUM);
+               if (term->val.num > 1) {
+                       err->str = strdup("expected 0 or 1");
+                       err->idx = term->err_val;
+                       return -EINVAL;
+               }
+               break;
        case PARSE_EVENTS__TERM_TYPE_NAME:
                CHECK_TYPE_VAL(STR);
                break;
@@ -650,6 +658,10 @@ do {                                                               \
                switch (term->type_term) {
                case PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD:
                        ADD_CONFIG_TERM(PERIOD, period, term->val.num);
+                       break;
+               case PARSE_EVENTS__TERM_TYPE_TIME:
+                       ADD_CONFIG_TERM(TIME, time, term->val.num);
+                       break;
                default:
                        break;
                }
index 2063048a435416ef80dd8dccd79d4048a8034763..e6f9aacc1ccecd38079634dda34c364e4206bf9b 100644 (file)
@@ -63,6 +63,7 @@ enum {
        PARSE_EVENTS__TERM_TYPE_NAME,
        PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD,
        PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE,
+       PARSE_EVENTS__TERM_TYPE_TIME,
 };
 
 struct parse_events_term {
index 13cef3c655652764c95cdd33f53d048e00bdc10c..f5427505ae77b319d0910f220fcdd7bfc9b13599 100644 (file)
@@ -183,6 +183,7 @@ config2                     { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_CONFIG2); }
 name                   { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_NAME); }
 period                 { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_SAMPLE_PERIOD); }
 branch_type            { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_BRANCH_SAMPLE_TYPE); }
+time                   { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_TIME); }
 ,                      { return ','; }
 "/"                    { BEGIN(INITIAL); return '/'; }
 {name_minus}           { return str(yyscanner, PE_NAME); }
index 7bcb8c315615b1ffdf7123584b2b832f5cfd9d35..b615cdf211d6e241109ad66b988f93ab3e65c5af 100644 (file)
@@ -607,7 +607,7 @@ static char *formats_error_string(struct list_head *formats)
 {
        struct perf_pmu_format *format;
        char *err, *str;
-       static const char *static_terms = "config,config1,config2,name,period,branch_type\n";
+       static const char *static_terms = "config,config1,config2,name,period,branch_type,time\n";
        unsigned i = 0;
 
        if (!asprintf(&str, "valid terms:"))