perf diff: Add -b option for perf diff to display paired entries only
authorJiri Olsa <jolsa@redhat.com>
Fri, 5 Oct 2012 14:44:40 +0000 (16:44 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 5 Oct 2012 17:05:14 +0000 (14:05 -0300)
Adding -b option to perf diff command to display only entries with match
in the baseline.

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1349448287-18919-2-git-send-email-jolsa@redhat.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Documentation/perf-diff.txt
tools/perf/builtin-diff.c

index ab7f667de1b158d290443397696166a573bbb7f4..6ce95858cd4ea2f87527103f8d84d2b08f2b3688 100644 (file)
@@ -72,6 +72,10 @@ OPTIONS
 --symfs=<directory>::
         Look for files with symbols relative to this directory.
 
+-b::
+--baseline-only::
+        Show only items with match in baseline.
+
 SEE ALSO
 --------
 linkperf:perf-record[1]
index a0b531c14b974f24cbbd2727a879c59c69415e06..1063c31e507c52243ee6681d3442a85eb012e940 100644 (file)
@@ -24,6 +24,7 @@ static char const *input_old = "perf.data.old",
 static char      diff__default_sort_order[] = "dso,symbol";
 static bool  force;
 static bool show_displacement;
+static bool show_baseline_only;
 
 static int hists__add_entry(struct hists *self,
                            struct addr_location *al, u64 period)
@@ -172,6 +173,31 @@ static void perf_evlist__resort_hists(struct perf_evlist *evlist, bool name)
        }
 }
 
+static void hists__baseline_only(struct hists *hists)
+{
+       struct rb_node *next = rb_first(&hists->entries);
+
+       while (next != NULL) {
+               struct hist_entry *he = rb_entry(next, struct hist_entry, rb_node);
+
+               next = rb_next(&he->rb_node);
+               if (!he->pair) {
+                       rb_erase(&he->rb_node, &hists->entries);
+                       hist_entry__free(he);
+               }
+       }
+}
+
+static void hists__process(struct hists *old, struct hists *new)
+{
+       hists__match(old, new);
+
+       if (show_baseline_only)
+               hists__baseline_only(new);
+
+       hists__fprintf(new, true, 0, 0, stdout);
+}
+
 static int __cmd_diff(void)
 {
        int ret, i;
@@ -213,8 +239,7 @@ static int __cmd_diff(void)
 
                first = false;
 
-               hists__match(&evsel_old->hists, &evsel->hists);
-               hists__fprintf(&evsel->hists, true, 0, 0, stdout);
+               hists__process(&evsel_old->hists, &evsel->hists);
        }
 
 out_delete:
@@ -235,6 +260,8 @@ static const struct option options[] = {
                    "be more verbose (show symbol address, etc)"),
        OPT_BOOLEAN('M', "displacement", &show_displacement,
                    "Show position displacement relative to baseline"),
+       OPT_BOOLEAN('b', "baseline-only", &show_baseline_only,
+                   "Show only items with match in baseline"),
        OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
                    "dump raw trace in ASCII"),
        OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),