perf tools: Add support for cycles, weight branch_info field
authorAndi Kleen <ak@linux.intel.com>
Sat, 18 Jul 2015 15:24:46 +0000 (08:24 -0700)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 6 Aug 2015 19:29:45 +0000 (16:29 -0300)
cycles is a new branch_info field available on some CPUs that indicates
the time deltas between branches in the LBR.

Add a sort key and output code for the cycles to allow to display the
basic block cycles individually in perf report.

We also pass in the cycles for weight when LBRs are processed, which
allows to get global and local weight, to get an estimate of the total
cost.

And also print the cycles information for perf report -D.  I also added
printing for the previously missing LBR flags (mispredict etc.)

Signed-off-by: Andi Kleen <ak@linux.intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/1437233094-12844-2-git-send-email-andi@firstfloor.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Documentation/perf-report.txt
tools/perf/util/event.h
tools/perf/util/hist.c
tools/perf/util/hist.h
tools/perf/util/session.c
tools/perf/util/sort.c
tools/perf/util/sort.h

index c33b69f3374fda01b6a9ee7dcca6b7bbb2f74e8c..960da203ec11143ea529bfbf80b0fab0503322d5 100644 (file)
@@ -109,6 +109,7 @@ OPTIONS
        - mispredict: "N" for predicted branch, "Y" for mispredicted branch
        - in_tx: branch in TSX transaction
        - abort: TSX transaction abort.
+       - cycles: Cycles in basic block
 
        And default sort keys are changed to comm, dso_from, symbol_from, dso_to
        and symbol_to, see '--branch-stack'.
index 4bb2ae894c78c04cf99946f7add1e98b53fb1d11..f729df5e25e634607f6b4c2f2cb4cc4e1ec933a3 100644 (file)
@@ -134,7 +134,8 @@ struct branch_flags {
        u64 predicted:1;
        u64 in_tx:1;
        u64 abort:1;
-       u64 reserved:60;
+       u64 cycles:16;
+       u64 reserved:44;
 };
 
 struct branch_entry {
index 6f28d53d4e46093293e71363d9aa5e7c1e0b23f5..54fc0033dd6af5fdfffac2b43e52cbd62e1892f8 100644 (file)
@@ -618,7 +618,8 @@ iter_add_next_branch_entry(struct hist_entry_iter *iter, struct addr_location *a
         * and not events sampled. Thus we use a pseudo period of 1.
         */
        he = __hists__add_entry(hists, al, iter->parent, &bi[i], NULL,
-                               1, 1, 0, true);
+                               1, bi->flags.cycles ? bi->flags.cycles : 1,
+                               0, true);
        if (he == NULL)
                return -ENOMEM;
 
index 5ed8d9c229814d9c6942ce3528898bbd9de1cb79..3881d98153093dd3b712f28a112414cffa6256c2 100644 (file)
@@ -47,6 +47,7 @@ enum hist_column {
        HISTC_MEM_SNOOP,
        HISTC_MEM_DCACHELINE,
        HISTC_TRANSACTION,
+       HISTC_CYCLES,
        HISTC_NR_COLS, /* Last entry */
 };
 
index f51eb54aeeb3a7fa8cd172a1d670ba82ac3e2394..18722e774a69c5c8fdbbc1c55454b0b85a0e1b16 100644 (file)
@@ -784,10 +784,18 @@ static void branch_stack__printf(struct perf_sample *sample)
 
        printf("... branch stack: nr:%" PRIu64 "\n", sample->branch_stack->nr);
 
-       for (i = 0; i < sample->branch_stack->nr; i++)
-               printf("..... %2"PRIu64": %016" PRIx64 " -> %016" PRIx64 "\n",
-                       i, sample->branch_stack->entries[i].from,
-                       sample->branch_stack->entries[i].to);
+       for (i = 0; i < sample->branch_stack->nr; i++) {
+               struct branch_entry *e = &sample->branch_stack->entries[i];
+
+               printf("..... %2"PRIu64": %016" PRIx64 " -> %016" PRIx64 " %hu cycles %s%s%s%s %x\n",
+                       i, e->from, e->to,
+                       e->flags.cycles,
+                       e->flags.mispred ? "M" : " ",
+                       e->flags.predicted ? "P" : " ",
+                       e->flags.abort ? "A" : " ",
+                       e->flags.in_tx ? "T" : " ",
+                       (unsigned)e->flags.reserved);
+       }
 }
 
 static void regs_dump__printf(u64 mask, u64 *regs)
index 4c65a143a34c96747ab7c6d39284f264f0f8d41e..5b7a50c04e4526e019eb73f3f2d907198d2f8de6 100644 (file)
@@ -526,6 +526,29 @@ static int hist_entry__mispredict_snprintf(struct hist_entry *he, char *bf,
        return repsep_snprintf(bf, size, "%-*.*s", width, width, out);
 }
 
+static int64_t
+sort__cycles_cmp(struct hist_entry *left, struct hist_entry *right)
+{
+       return left->branch_info->flags.cycles -
+               right->branch_info->flags.cycles;
+}
+
+static int hist_entry__cycles_snprintf(struct hist_entry *he, char *bf,
+                                   size_t size, unsigned int width)
+{
+       if (he->branch_info->flags.cycles == 0)
+               return repsep_snprintf(bf, size, "%-*s", width, "-");
+       return repsep_snprintf(bf, size, "%-*hd", width,
+                              he->branch_info->flags.cycles);
+}
+
+struct sort_entry sort_cycles = {
+       .se_header      = "Basic Block Cycles",
+       .se_cmp         = sort__cycles_cmp,
+       .se_snprintf    = hist_entry__cycles_snprintf,
+       .se_width_idx   = HISTC_CYCLES,
+};
+
 /* --sort daddr_sym */
 static int64_t
 sort__daddr_cmp(struct hist_entry *left, struct hist_entry *right)
@@ -1190,6 +1213,7 @@ static struct sort_dimension bstack_sort_dimensions[] = {
        DIM(SORT_MISPREDICT, "mispredict", sort_mispredict),
        DIM(SORT_IN_TX, "in_tx", sort_in_tx),
        DIM(SORT_ABORT, "abort", sort_abort),
+       DIM(SORT_CYCLES, "cycles", sort_cycles),
 };
 
 #undef DIM
index e97cd476d336f2a9cad2a1eeb9daba34d08ed3a4..bc6c87a76d16544e856b621649e79a4f9e3e3b19 100644 (file)
@@ -185,6 +185,7 @@ enum sort_type {
        SORT_MISPREDICT,
        SORT_ABORT,
        SORT_IN_TX,
+       SORT_CYCLES,
 
        /* memory mode specific sort keys */
        __SORT_MEMORY_MODE,