perf tools: Allow hpp fields to be sort keys
authorNamhyung Kim <namhyung@kernel.org>
Tue, 4 Mar 2014 00:06:42 +0000 (09:06 +0900)
committerJiri Olsa <jolsa@kernel.org>
Wed, 21 May 2014 09:45:34 +0000 (11:45 +0200)
Add overhead{,_sys,_us,_guest_sys,_guest_us}, sample and period sort
keys so that they can be selected with --sort/-s option.

  $ perf report -s period,comm --stdio
  ...
  # Overhead        Period          Command
  # ........  ............  ...............
  #
      47.06%           152          swapper
      13.93%            45  qemu-system-arm
      12.38%            40         synergys
       3.72%            12          firefox
       2.48%             8            xchat

Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Ingo Molnar <mingo@kernel.org>
Link: http://lkml.kernel.org/r/1400480762-22852-9-git-send-email-namhyung@kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
tools/perf/Documentation/perf-diff.txt
tools/perf/Documentation/perf-report.txt
tools/perf/Documentation/perf-top.txt
tools/perf/builtin-diff.c
tools/perf/builtin-report.c
tools/perf/builtin-top.c
tools/perf/ui/hist.c
tools/perf/util/sort.c

index fbfa1192923c74b1a5dbf661ba90fafd9576cebf..b3b8abae62b8d523134490c9f6d01396a78c3cfd 100644 (file)
@@ -50,7 +50,8 @@ OPTIONS
 
 -s::
 --sort=::
-       Sort by key(s): pid, comm, dso, symbol.
+       Sort by key(s): pid, comm, dso, symbol, cpu, parent, srcline.
+       Please see description of --sort in the perf-report man page.
 
 -t::
 --field-separator=::
@@ -202,4 +203,4 @@ If specified the 'Weighted diff' column is displayed with value 'd' computed as:
 
 SEE ALSO
 --------
-linkperf:perf-record[1]
+linkperf:perf-record[1], linkperf:perf-report[1]
index 09af66298564113643ef5db11540ef7e6c8652fd..9babe915b6c496e49f921d5ae683e78ef7a3bed2 100644 (file)
@@ -79,6 +79,15 @@ OPTIONS
        abort cost. This is the global weight.
        - local_weight: Local weight version of the weight above.
        - transaction: Transaction abort flags.
+       - overhead: Overhead percentage of sample
+       - overhead_sys: Overhead percentage of sample running in system mode
+       - overhead_us: Overhead percentage of sample running in user mode
+       - overhead_guest_sys: Overhead percentage of sample running in system mode
+       on guest machine
+       - overhead_guest_us: Overhead percentage of sample running in user mode on
+       guest machine
+       - sample: Number of sample
+       - period: Raw number of event count of sample
 
        By default, comm, dso and symbol keys are used.
        (i.e. --sort comm,dso,symbol)
index 64ed79c43639ee3247f1c6335f94e09410bf5faa..df863288752a60994a047cfd5d77639678405fc5 100644 (file)
@@ -113,7 +113,8 @@ Default is to monitor all CPUS.
 -s::
 --sort::
        Sort by key(s): pid, comm, dso, symbol, parent, srcline, weight,
-       local_weight, abort, in_tx, transaction
+       local_weight, abort, in_tx, transaction, overhead, sample, period.
+       Please see description of --sort in the perf-report man page.
 
 -n::
 --show-nr-samples::
@@ -212,4 +213,4 @@ Pressing any unmapped key displays a menu, and prompts for input.
 
 SEE ALSO
 --------
-linkperf:perf-stat[1], linkperf:perf-list[1]
+linkperf:perf-stat[1], linkperf:perf-list[1], linkperf:perf-report[1]
index f3b10dcf68380710eac279b032d9d2fbb5cbea8a..b60c711d4e724c3c42fa164b43343fa0c0c29dc6 100644 (file)
@@ -741,7 +741,8 @@ static const struct option options[] = {
        OPT_STRING('S', "symbols", &symbol_conf.sym_list_str, "symbol[,symbol...]",
                   "only consider these symbols"),
        OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
-                  "sort by key(s): pid, comm, dso, symbol, parent"),
+                  "sort by key(s): pid, comm, dso, symbol, parent, cpu, srcline, ..."
+                  " Please refer the man page for the complete list."),
        OPT_STRING('t', "field-separator", &symbol_conf.field_sep, "separator",
                   "separator for columns, no spaces will be added between "
                   "columns '.' is reserved."),
index 89c95289fd5102b3b1257d91e4b603d212986347..d0180d5de781162b7068e447df1578666701b0b2 100644 (file)
@@ -699,10 +699,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
        OPT_BOOLEAN(0, "header-only", &report.header_only,
                    "Show only data header."),
        OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
-                  "sort by key(s): pid, comm, dso, symbol, parent, cpu, srcline,"
-                  " dso_to, dso_from, symbol_to, symbol_from, mispredict,"
-                  " weight, local_weight, mem, symbol_daddr, dso_daddr, tlb, "
-                  "snoop, locked, abort, in_tx, transaction"),
+                  "sort by key(s): pid, comm, dso, symbol, parent, cpu, srcline, ..."
+                  " Please refer the man page for the complete list."),
        OPT_BOOLEAN(0, "showcpuutilization", &symbol_conf.show_cpu_utilization,
                    "Show sample percentage for different cpu modes"),
        OPT_STRING('p', "parent", &parent_pattern, "regex",
index 37d30460bada06336472975a9cbb362693015157..4fef1e415129262ecf0969b3a479f7db114ed48b 100644 (file)
@@ -1083,8 +1083,8 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
        OPT_INCR('v', "verbose", &verbose,
                    "be more verbose (show counter open errors, etc)"),
        OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
-                  "sort by key(s): pid, comm, dso, symbol, parent, weight, local_weight,"
-                  " abort, in_tx, transaction"),
+                  "sort by key(s): pid, comm, dso, symbol, parent, cpu, srcline, ..."
+                  " Please refer the man page for the complete list."),
        OPT_BOOLEAN('n', "show-nr-samples", &symbol_conf.show_nr_samples,
                    "Show a column with the number of samples"),
        OPT_CALLBACK_NOOPT('g', NULL, &top.record_opts,
index e7ac794382c1cadec56f56e5ee68a4c061ab2cf1..24116a48298f814cdf115cffdc72b1155cff8dcb 100644 (file)
@@ -346,8 +346,13 @@ void perf_hpp__init(void)
        int i;
 
        for (i = 0; i < PERF_HPP__MAX_INDEX; i++) {
-               INIT_LIST_HEAD(&perf_hpp__format[i].list);
-               INIT_LIST_HEAD(&perf_hpp__format[i].sort_list);
+               struct perf_hpp_fmt *fmt = &perf_hpp__format[i];
+
+               INIT_LIST_HEAD(&fmt->list);
+
+               /* sort_list may be linked by setup_sorting() */
+               if (fmt->sort_list.next == NULL)
+                       INIT_LIST_HEAD(&fmt->sort_list);
        }
 
        perf_hpp__column_enable(PERF_HPP__OVERHEAD);
index b2829f9470536a11dd4be10a2e89a0aad7ed05cb..916652af8304d8a42d1b947f46c713663dbf9026 100644 (file)
@@ -1028,6 +1028,26 @@ static struct sort_dimension memory_sort_dimensions[] = {
 
 #undef DIM
 
+struct hpp_dimension {
+       const char              *name;
+       struct perf_hpp_fmt     *fmt;
+       int                     taken;
+};
+
+#define DIM(d, n) { .name = n, .fmt = &perf_hpp__format[d], }
+
+static struct hpp_dimension hpp_sort_dimensions[] = {
+       DIM(PERF_HPP__OVERHEAD, "overhead"),
+       DIM(PERF_HPP__OVERHEAD_SYS, "overhead_sys"),
+       DIM(PERF_HPP__OVERHEAD_US, "overhead_us"),
+       DIM(PERF_HPP__OVERHEAD_GUEST_SYS, "overhead_guest_sys"),
+       DIM(PERF_HPP__OVERHEAD_GUEST_US, "overhead_guest_us"),
+       DIM(PERF_HPP__SAMPLES, "sample"),
+       DIM(PERF_HPP__PERIOD, "period"),
+};
+
+#undef DIM
+
 struct hpp_sort_entry {
        struct perf_hpp_fmt hpp;
        struct sort_entry *se;
@@ -1115,6 +1135,16 @@ static int __sort_dimension__add(struct sort_dimension *sd, enum sort_type idx)
        return 0;
 }
 
+static int __hpp_dimension__add(struct hpp_dimension *hd)
+{
+       if (!hd->taken) {
+               hd->taken = 1;
+
+               perf_hpp__register_sort_field(hd->fmt);
+       }
+       return 0;
+}
+
 int sort_dimension__add(const char *tok)
 {
        unsigned int i;
@@ -1144,6 +1174,15 @@ int sort_dimension__add(const char *tok)
                return __sort_dimension__add(sd, i);
        }
 
+       for (i = 0; i < ARRAY_SIZE(hpp_sort_dimensions); i++) {
+               struct hpp_dimension *hd = &hpp_sort_dimensions[i];
+
+               if (strncasecmp(tok, hd->name, strlen(tok)))
+                       continue;
+
+               return __hpp_dimension__add(hd);
+       }
+
        for (i = 0; i < ARRAY_SIZE(bstack_sort_dimensions); i++) {
                struct sort_dimension *sd = &bstack_sort_dimensions[i];