]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
perf annotate: Add --percent-type option
authorJiri Olsa <jolsa@kernel.org>
Sat, 4 Aug 2018 13:05:20 +0000 (15:05 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 8 Aug 2018 18:55:53 +0000 (15:55 -0300)
Add --percent-type option to set annotation percent type from following
choices:

  global-period, local-period, global-hits, local-hits

Examples:

  $ perf annotate --percent-type period-local --stdio | head -1
   Percent         |      Source code ... es, percent: local period)
  $ perf annotate --percent-type hits-local --stdio | head -1
   Percent         |      Source code ... es, percent: local hits)
  $ perf annotate --percent-type hits-global --stdio | head -1
   Percent         |      Source code ... es, percent: global hits)
  $ perf annotate --percent-type period-global --stdio | head -1
   Percent         |      Source code ... es, percent: global period)

The local/global keywords set if the percentage is computed in the scope
of the function (local) or the whole data (global).

The period/hits keywords set the base the percentage is computed on -
the samples period or the number of samples (hits).

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/20180804130521.11408-20-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Documentation/perf-annotate.txt
tools/perf/builtin-annotate.c
tools/perf/util/annotate.c
tools/perf/util/annotate.h

index 749cc6055dac32ab1d30879bda29343eed3d887d..e8c972f89357d2dc47bbe57000e503f46d964f37 100644 (file)
@@ -118,6 +118,15 @@ OPTIONS
 --group::
        Show event group information together
 
+--percent-type::
+       Set annotation percent type from following choices:
+         global-period, local-period, global-hits, local-hits
+
+       The local/global keywords set if the percentage is computed
+       in the scope of the function (local) or the whole data (global).
+       The period/hits keywords set the base the percentage is computed
+       on - the samples period or the number of samples (hits).
+
 SEE ALSO
 --------
 linkperf:perf-record[1], linkperf:perf-report[1]
index 8180319285af3377810c30c0298f37c73cb9bb8d..830481b8db26ae379d7e9816c130bdb49be04bd7 100644 (file)
@@ -542,6 +542,10 @@ int cmd_annotate(int argc, const char **argv)
        OPT_CALLBACK_DEFAULT(0, "stdio-color", NULL, "mode",
                             "'always' (default), 'never' or 'auto' only applicable to --stdio mode",
                             stdio__config_color, "always"),
+       OPT_CALLBACK(0, "percent-type", &annotate.opts, "local-period",
+                    "Set percent type local/global-period/hits",
+                    annotate_parse_percent_type),
+
        OPT_END()
        };
        int ret;
index 6316fa96d984b4973add0095d2e5e414679256c3..e4268b948e0e05d4de22555b8236a6a2d4650eca 100644 (file)
@@ -2799,3 +2799,55 @@ void annotation_config__init(void)
        annotation__default_options.show_total_period = symbol_conf.show_total_period;
        annotation__default_options.show_nr_samples   = symbol_conf.show_nr_samples;
 }
+
+static unsigned int parse_percent_type(char *str1, char *str2)
+{
+       unsigned int type = (unsigned int) -1;
+
+       if (!strcmp("period", str1)) {
+               if (!strcmp("local", str2))
+                       type = PERCENT_PERIOD_LOCAL;
+               else if (!strcmp("global", str2))
+                       type = PERCENT_PERIOD_GLOBAL;
+       }
+
+       if (!strcmp("hits", str1)) {
+               if (!strcmp("local", str2))
+                       type = PERCENT_HITS_LOCAL;
+               else if (!strcmp("global", str2))
+                       type = PERCENT_HITS_GLOBAL;
+       }
+
+       return type;
+}
+
+int annotate_parse_percent_type(const struct option *opt, const char *_str,
+                               int unset __maybe_unused)
+{
+       struct annotation_options *opts = opt->value;
+       unsigned int type;
+       char *str1, *str2;
+       int err = -1;
+
+       str1 = strdup(_str);
+       if (!str1)
+               return -ENOMEM;
+
+       str2 = strchr(str1, '-');
+       if (!str2)
+               goto out;
+
+       *str2++ = 0;
+
+       type = parse_percent_type(str1, str2);
+       if (type == (unsigned int) -1)
+               type = parse_percent_type(str2, str1);
+       if (type != (unsigned int) -1) {
+               opts->percent_type = type;
+               err = 0;
+       }
+
+out:
+       free(str1);
+       return err;
+}
index 760a6678edffb18df02e74a94b56e3aae66ecc6b..005a5fe8a8c6bccc49ed7d6b1861952313ecb2df 100644 (file)
@@ -397,4 +397,6 @@ static inline int symbol__tui_annotate(struct symbol *sym __maybe_unused,
 
 void annotation_config__init(void);
 
+int annotate_parse_percent_type(const struct option *opt, const char *_str,
+                               int unset);
 #endif /* __PERF_ANNOTATE_H */