Re: [PATCH 07/10] perf tools: Add 'trace' sort key

2015-12-22 Thread Namhyung Kim
Hi Jiri,

On Tue, Dec 22, 2015 at 08:22:03AM +0100, Jiri Olsa wrote:
> On Mon, Dec 21, 2015 at 11:26:50PM +0900, Namhyung Kim wrote:
> 
> SNIP
> 
> > diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
> > index e28d26d0e73c..50a6b35a2fee 100644
> > --- a/tools/perf/util/sort.c
> > +++ b/tools/perf/util/sort.c
> > @@ -445,6 +445,65 @@ struct sort_entry sort_socket = {
> > .se_width_idx   = HISTC_SOCKET,
> >  };
> >  
> > +/* --sort trace */
> > +
> > +static char *get_trace_output(struct hist_entry *he)
> > +{
> > +   struct trace_seq seq;
> > +   struct perf_evsel *evsel;
> > +   struct pevent_record rec = {
> > +   .data = he->raw_data,
> > +   .size = he->raw_size,
> > +   };
> > +
> > +   evsel = hists_to_evsel(he->hists);
> > +
> > +   trace_seq_init();
> > +   pevent_event_info(, evsel->tp_format, );
> > +   return seq.buffer;
> > +}
> 
> this function could be global and used in previous patch
> in update_dynamic_len for trace_output?

OK.

> 
> hum, one's using evsel->tp_format and the other field->event,
> I can't recall if both point to the same stuff..

AFAIK they should point to the same.

Thanks,
Namhyung
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 07/10] perf tools: Add 'trace' sort key

2015-12-22 Thread Namhyung Kim
Hi Jiri,

On Tue, Dec 22, 2015 at 08:22:03AM +0100, Jiri Olsa wrote:
> On Mon, Dec 21, 2015 at 11:26:50PM +0900, Namhyung Kim wrote:
> 
> SNIP
> 
> > diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
> > index e28d26d0e73c..50a6b35a2fee 100644
> > --- a/tools/perf/util/sort.c
> > +++ b/tools/perf/util/sort.c
> > @@ -445,6 +445,65 @@ struct sort_entry sort_socket = {
> > .se_width_idx   = HISTC_SOCKET,
> >  };
> >  
> > +/* --sort trace */
> > +
> > +static char *get_trace_output(struct hist_entry *he)
> > +{
> > +   struct trace_seq seq;
> > +   struct perf_evsel *evsel;
> > +   struct pevent_record rec = {
> > +   .data = he->raw_data,
> > +   .size = he->raw_size,
> > +   };
> > +
> > +   evsel = hists_to_evsel(he->hists);
> > +
> > +   trace_seq_init();
> > +   pevent_event_info(, evsel->tp_format, );
> > +   return seq.buffer;
> > +}
> 
> this function could be global and used in previous patch
> in update_dynamic_len for trace_output?

OK.

> 
> hum, one's using evsel->tp_format and the other field->event,
> I can't recall if both point to the same stuff..

AFAIK they should point to the same.

Thanks,
Namhyung
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 07/10] perf tools: Add 'trace' sort key

2015-12-21 Thread Jiri Olsa
On Mon, Dec 21, 2015 at 11:26:50PM +0900, Namhyung Kim wrote:

SNIP

> diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
> index e28d26d0e73c..50a6b35a2fee 100644
> --- a/tools/perf/util/sort.c
> +++ b/tools/perf/util/sort.c
> @@ -445,6 +445,65 @@ struct sort_entry sort_socket = {
>   .se_width_idx   = HISTC_SOCKET,
>  };
>  
> +/* --sort trace */
> +
> +static char *get_trace_output(struct hist_entry *he)
> +{
> + struct trace_seq seq;
> + struct perf_evsel *evsel;
> + struct pevent_record rec = {
> + .data = he->raw_data,
> + .size = he->raw_size,
> + };
> +
> + evsel = hists_to_evsel(he->hists);
> +
> + trace_seq_init();
> + pevent_event_info(, evsel->tp_format, );
> + return seq.buffer;
> +}

this function could be global and used in previous patch
in update_dynamic_len for trace_output?

hum, one's using evsel->tp_format and the other field->event,
I can't recall if both point to the same stuff..

jirka
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 07/10] perf tools: Add 'trace' sort key

2015-12-21 Thread Namhyung Kim
The 'trace' sort key is to show tracepoint event output using either
print fmt or plugin.  For example sched_switch event (using plugin) will
show output like below:

  $ perf report -s trace --stdio
  ...
  # Overhead  Trace output
  #   ...
  #
   9.48%  swapper/0:0 [120] R ==> transmission-gt:17773 [120]
   9.48%  transmission-gt:17773 [120] S ==> swapper/0:0 [120]
   9.04%  swapper/2:0 [120] R ==> transmission-gt:17773 [120]
   8.92%  transmission-gt:17773 [120] S ==> swapper/2:0 [120]
   5.25%  swapper/0:0 [120] R ==> kworker/0:1H:109 [100]
   5.21%  kworker/0:1H:109 [100] S ==> swapper/0:0 [120]
   1.78%  swapper/3:0 [120] R ==> transmission-gt:17773 [120]
   1.78%  transmission-gt:17773 [120] S ==> swapper/3:0 [120]
   1.53%  Xephyr:6524 [120] S ==> swapper/0:0 [120]
   1.53%  swapper/0:0 [120] R ==> Xephyr:6524 [120]
   1.17%  swapper/2:0 [120] R ==> irq/33-iwlwifi:233 [49]
   1.13%  irq/33-iwlwifi:233 [49] S ==> swapper/2:0 [120]

Note that the 'trace' sort key works only for tracepoint events.  If
it's used to other type of events, just "N/A" will be printed.

Suggested-by: Jiri Olsa 
Cc: Steven Rostedt 
Signed-off-by: Namhyung Kim 
---
 tools/perf/util/hist.h |  1 +
 tools/perf/util/sort.c | 60 ++
 tools/perf/util/sort.h |  1 +
 3 files changed, 62 insertions(+)

diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 36439bfad059..15b22c563d30 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -52,6 +52,7 @@ enum hist_column {
HISTC_MEM_IADDR_SYMBOL,
HISTC_TRANSACTION,
HISTC_CYCLES,
+   HISTC_TRACE,
HISTC_NR_COLS, /* Last entry */
 };
 
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index e28d26d0e73c..50a6b35a2fee 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -445,6 +445,65 @@ struct sort_entry sort_socket = {
.se_width_idx   = HISTC_SOCKET,
 };
 
+/* --sort trace */
+
+static char *get_trace_output(struct hist_entry *he)
+{
+   struct trace_seq seq;
+   struct perf_evsel *evsel;
+   struct pevent_record rec = {
+   .data = he->raw_data,
+   .size = he->raw_size,
+   };
+
+   evsel = hists_to_evsel(he->hists);
+
+   trace_seq_init();
+   pevent_event_info(, evsel->tp_format, );
+   return seq.buffer;
+}
+
+static int64_t
+sort__trace_cmp(struct hist_entry *left, struct hist_entry *right)
+{
+   struct perf_evsel *evsel;
+
+   evsel = hists_to_evsel(left->hists);
+   if (evsel->attr.type != PERF_TYPE_TRACEPOINT)
+   return 0;
+
+   if (left->trace_output == NULL)
+   left->trace_output = get_trace_output(left);
+   if (right->trace_output == NULL)
+   right->trace_output = get_trace_output(right);
+
+   hists__new_col_len(left->hists, HISTC_TRACE, 
strlen(left->trace_output));
+   hists__new_col_len(right->hists, HISTC_TRACE, 
strlen(right->trace_output));
+
+   return strcmp(right->trace_output, left->trace_output);
+}
+
+static int hist_entry__trace_snprintf(struct hist_entry *he, char *bf,
+   size_t size, unsigned int width)
+{
+   struct perf_evsel *evsel;
+
+   evsel = hists_to_evsel(he->hists);
+   if (evsel->attr.type != PERF_TYPE_TRACEPOINT)
+   return scnprintf(bf, size, "%-*.*s", width, width, "N/A");
+
+   if (he->trace_output == NULL)
+   he->trace_output = get_trace_output(he);
+   return repsep_snprintf(bf, size, "%-*.*s", width, width, 
he->trace_output);
+}
+
+struct sort_entry sort_trace = {
+   .se_header  = "Trace output",
+   .se_cmp = sort__trace_cmp,
+   .se_snprintf= hist_entry__trace_snprintf,
+   .se_width_idx   = HISTC_TRACE,
+};
+
 /* sort keys for branch stacks */
 
 static int64_t
@@ -1314,6 +1373,7 @@ static struct sort_dimension common_sort_dimensions[] = {
DIM(SORT_LOCAL_WEIGHT, "local_weight", sort_local_weight),
DIM(SORT_GLOBAL_WEIGHT, "weight", sort_global_weight),
DIM(SORT_TRANSACTION, "transaction", sort_transaction),
+   DIM(SORT_TRACE, "trace", sort_trace),
 };
 
 #undef DIM
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index f6d2a7e3e7f2..6b7590ade229 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -183,6 +183,7 @@ enum sort_type {
SORT_LOCAL_WEIGHT,
SORT_GLOBAL_WEIGHT,
SORT_TRANSACTION,
+   SORT_TRACE,
 
/* branch stack specific sort keys */
__SORT_BRANCH_STACK,
-- 
2.6.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 07/10] perf tools: Add 'trace' sort key

2015-12-21 Thread Namhyung Kim
The 'trace' sort key is to show tracepoint event output using either
print fmt or plugin.  For example sched_switch event (using plugin) will
show output like below:

  $ perf report -s trace --stdio
  ...
  # Overhead  Trace output
  #   ...
  #
   9.48%  swapper/0:0 [120] R ==> transmission-gt:17773 [120]
   9.48%  transmission-gt:17773 [120] S ==> swapper/0:0 [120]
   9.04%  swapper/2:0 [120] R ==> transmission-gt:17773 [120]
   8.92%  transmission-gt:17773 [120] S ==> swapper/2:0 [120]
   5.25%  swapper/0:0 [120] R ==> kworker/0:1H:109 [100]
   5.21%  kworker/0:1H:109 [100] S ==> swapper/0:0 [120]
   1.78%  swapper/3:0 [120] R ==> transmission-gt:17773 [120]
   1.78%  transmission-gt:17773 [120] S ==> swapper/3:0 [120]
   1.53%  Xephyr:6524 [120] S ==> swapper/0:0 [120]
   1.53%  swapper/0:0 [120] R ==> Xephyr:6524 [120]
   1.17%  swapper/2:0 [120] R ==> irq/33-iwlwifi:233 [49]
   1.13%  irq/33-iwlwifi:233 [49] S ==> swapper/2:0 [120]

Note that the 'trace' sort key works only for tracepoint events.  If
it's used to other type of events, just "N/A" will be printed.

Suggested-by: Jiri Olsa 
Cc: Steven Rostedt 
Signed-off-by: Namhyung Kim 
---
 tools/perf/util/hist.h |  1 +
 tools/perf/util/sort.c | 60 ++
 tools/perf/util/sort.h |  1 +
 3 files changed, 62 insertions(+)

diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 36439bfad059..15b22c563d30 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -52,6 +52,7 @@ enum hist_column {
HISTC_MEM_IADDR_SYMBOL,
HISTC_TRANSACTION,
HISTC_CYCLES,
+   HISTC_TRACE,
HISTC_NR_COLS, /* Last entry */
 };
 
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index e28d26d0e73c..50a6b35a2fee 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -445,6 +445,65 @@ struct sort_entry sort_socket = {
.se_width_idx   = HISTC_SOCKET,
 };
 
+/* --sort trace */
+
+static char *get_trace_output(struct hist_entry *he)
+{
+   struct trace_seq seq;
+   struct perf_evsel *evsel;
+   struct pevent_record rec = {
+   .data = he->raw_data,
+   .size = he->raw_size,
+   };
+
+   evsel = hists_to_evsel(he->hists);
+
+   trace_seq_init();
+   pevent_event_info(, evsel->tp_format, );
+   return seq.buffer;
+}
+
+static int64_t
+sort__trace_cmp(struct hist_entry *left, struct hist_entry *right)
+{
+   struct perf_evsel *evsel;
+
+   evsel = hists_to_evsel(left->hists);
+   if (evsel->attr.type != PERF_TYPE_TRACEPOINT)
+   return 0;
+
+   if (left->trace_output == NULL)
+   left->trace_output = get_trace_output(left);
+   if (right->trace_output == NULL)
+   right->trace_output = get_trace_output(right);
+
+   hists__new_col_len(left->hists, HISTC_TRACE, 
strlen(left->trace_output));
+   hists__new_col_len(right->hists, HISTC_TRACE, 
strlen(right->trace_output));
+
+   return strcmp(right->trace_output, left->trace_output);
+}
+
+static int hist_entry__trace_snprintf(struct hist_entry *he, char *bf,
+   size_t size, unsigned int width)
+{
+   struct perf_evsel *evsel;
+
+   evsel = hists_to_evsel(he->hists);
+   if (evsel->attr.type != PERF_TYPE_TRACEPOINT)
+   return scnprintf(bf, size, "%-*.*s", width, width, "N/A");
+
+   if (he->trace_output == NULL)
+   he->trace_output = get_trace_output(he);
+   return repsep_snprintf(bf, size, "%-*.*s", width, width, 
he->trace_output);
+}
+
+struct sort_entry sort_trace = {
+   .se_header  = "Trace output",
+   .se_cmp = sort__trace_cmp,
+   .se_snprintf= hist_entry__trace_snprintf,
+   .se_width_idx   = HISTC_TRACE,
+};
+
 /* sort keys for branch stacks */
 
 static int64_t
@@ -1314,6 +1373,7 @@ static struct sort_dimension common_sort_dimensions[] = {
DIM(SORT_LOCAL_WEIGHT, "local_weight", sort_local_weight),
DIM(SORT_GLOBAL_WEIGHT, "weight", sort_global_weight),
DIM(SORT_TRANSACTION, "transaction", sort_transaction),
+   DIM(SORT_TRACE, "trace", sort_trace),
 };
 
 #undef DIM
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index f6d2a7e3e7f2..6b7590ade229 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -183,6 +183,7 @@ enum sort_type {
SORT_LOCAL_WEIGHT,
SORT_GLOBAL_WEIGHT,
SORT_TRANSACTION,
+   SORT_TRACE,
 
/* branch stack specific sort keys */
__SORT_BRANCH_STACK,
-- 
2.6.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  

Re: [PATCH 07/10] perf tools: Add 'trace' sort key

2015-12-21 Thread Jiri Olsa
On Mon, Dec 21, 2015 at 11:26:50PM +0900, Namhyung Kim wrote:

SNIP

> diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
> index e28d26d0e73c..50a6b35a2fee 100644
> --- a/tools/perf/util/sort.c
> +++ b/tools/perf/util/sort.c
> @@ -445,6 +445,65 @@ struct sort_entry sort_socket = {
>   .se_width_idx   = HISTC_SOCKET,
>  };
>  
> +/* --sort trace */
> +
> +static char *get_trace_output(struct hist_entry *he)
> +{
> + struct trace_seq seq;
> + struct perf_evsel *evsel;
> + struct pevent_record rec = {
> + .data = he->raw_data,
> + .size = he->raw_size,
> + };
> +
> + evsel = hists_to_evsel(he->hists);
> +
> + trace_seq_init();
> + pevent_event_info(, evsel->tp_format, );
> + return seq.buffer;
> +}

this function could be global and used in previous patch
in update_dynamic_len for trace_output?

hum, one's using evsel->tp_format and the other field->event,
I can't recall if both point to the same stuff..

jirka
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 07/10] perf tools: Add 'trace' sort key

2015-12-15 Thread Namhyung Kim
The 'trace' sort key is to show tracepoint event output using either
print fmt or plugin.  For example sched_switch event (using plugin) will
show output like below:

  $ perf report -s trace --stdio
  ...
  # Overhead  Trace output
  #   ...
  #
   9.48%  swapper/0:0 [120] R ==> transmission-gt:17773 [120]
   9.48%  transmission-gt:17773 [120] S ==> swapper/0:0 [120]
   9.04%  swapper/2:0 [120] R ==> transmission-gt:17773 [120]
   8.92%  transmission-gt:17773 [120] S ==> swapper/2:0 [120]
   5.25%  swapper/0:0 [120] R ==> kworker/0:1H:109 [100]
   5.21%  kworker/0:1H:109 [100] S ==> swapper/0:0 [120]
   1.78%  swapper/3:0 [120] R ==> transmission-gt:17773 [120]
   1.78%  transmission-gt:17773 [120] S ==> swapper/3:0 [120]
   1.53%  Xephyr:6524 [120] S ==> swapper/0:0 [120]
   1.53%  swapper/0:0 [120] R ==> Xephyr:6524 [120]
   1.17%  swapper/2:0 [120] R ==> irq/33-iwlwifi:233 [49]
   1.13%  irq/33-iwlwifi:233 [49] S ==> swapper/2:0 [120]

Note that the 'trace' sort key works only for tracepoint events.  If
it's used to other type of events, just "N/A" will be printed.

Suggested-by: Jiri Olsa 
Cc: Steven Rostedt 
Signed-off-by: Namhyung Kim 
---
 tools/perf/util/hist.c |  1 +
 tools/perf/util/hist.h |  1 +
 tools/perf/util/sort.c | 61 ++
 tools/perf/util/sort.h |  2 ++
 4 files changed, 65 insertions(+)

diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 99a6f1c17806..e471e0fa6a18 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -976,6 +976,7 @@ void hist_entry__delete(struct hist_entry *he)
if (he->srcfile && he->srcfile[0])
free(he->srcfile);
free_callchain(he->callchain);
+   free(he->trace_output);
free(he);
 }
 
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 36439bfad059..15b22c563d30 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -52,6 +52,7 @@ enum hist_column {
HISTC_MEM_IADDR_SYMBOL,
HISTC_TRANSACTION,
HISTC_CYCLES,
+   HISTC_TRACE,
HISTC_NR_COLS, /* Last entry */
 };
 
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 746b1c405db2..caa8d3c1f6f9 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -445,6 +445,66 @@ struct sort_entry sort_socket = {
.se_width_idx   = HISTC_SOCKET,
 };
 
+/* --sort trace */
+
+static char *get_trace_output(struct hist_entry *he)
+{
+   struct trace_seq seq;
+   struct perf_evsel *evsel;
+   struct pevent_record rec = {
+   .cpu  = he->cpu,
+   .data = he->raw_data,
+   .size = he->raw_size,
+   };
+
+   evsel = hists_to_evsel(he->hists);
+
+   trace_seq_init();
+   pevent_event_info(, evsel->tp_format, );
+   return seq.buffer;
+}
+
+static int64_t
+sort__trace_cmp(struct hist_entry *left, struct hist_entry *right)
+{
+   struct perf_evsel *evsel;
+
+   evsel = hists_to_evsel(left->hists);
+   if (evsel->attr.type != PERF_TYPE_TRACEPOINT)
+   return 0;
+
+   if (left->trace_output == NULL)
+   left->trace_output = get_trace_output(left);
+   if (right->trace_output == NULL)
+   right->trace_output = get_trace_output(right);
+
+   hists__new_col_len(left->hists, HISTC_TRACE, 
strlen(left->trace_output));
+   hists__new_col_len(right->hists, HISTC_TRACE, 
strlen(right->trace_output));
+
+   return strcmp(right->trace_output, left->trace_output);
+}
+
+static int hist_entry__trace_snprintf(struct hist_entry *he, char *bf,
+   size_t size, unsigned int width)
+{
+   struct perf_evsel *evsel;
+
+   evsel = hists_to_evsel(he->hists);
+   if (evsel->attr.type != PERF_TYPE_TRACEPOINT)
+   return scnprintf(bf, size, "%-*.*s", width, width, "N/A");
+
+   if (he->trace_output == NULL)
+   he->trace_output = get_trace_output(he);
+   return repsep_snprintf(bf, size, "%-*.*s", width, width, 
he->trace_output);
+}
+
+struct sort_entry sort_trace = {
+   .se_header  = "Trace output",
+   .se_cmp = sort__trace_cmp,
+   .se_snprintf= hist_entry__trace_snprintf,
+   .se_width_idx   = HISTC_TRACE,
+};
+
 /* sort keys for branch stacks */
 
 static int64_t
@@ -1314,6 +1374,7 @@ static struct sort_dimension common_sort_dimensions[] = {
DIM(SORT_LOCAL_WEIGHT, "local_weight", sort_local_weight),
DIM(SORT_GLOBAL_WEIGHT, "weight", sort_global_weight),
DIM(SORT_TRANSACTION, "transaction", sort_transaction),
+   DIM(SORT_TRACE, "trace", sort_trace),
 };
 
 #undef DIM
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index aefcc2f8f173..a2c4bd059b81 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -125,6 +125,7 @@ struct hist_entry {
struct 

[PATCH 07/10] perf tools: Add 'trace' sort key

2015-12-15 Thread Namhyung Kim
The 'trace' sort key is to show tracepoint event output using either
print fmt or plugin.  For example sched_switch event (using plugin) will
show output like below:

  $ perf report -s trace --stdio
  ...
  # Overhead  Trace output
  #   ...
  #
   9.48%  swapper/0:0 [120] R ==> transmission-gt:17773 [120]
   9.48%  transmission-gt:17773 [120] S ==> swapper/0:0 [120]
   9.04%  swapper/2:0 [120] R ==> transmission-gt:17773 [120]
   8.92%  transmission-gt:17773 [120] S ==> swapper/2:0 [120]
   5.25%  swapper/0:0 [120] R ==> kworker/0:1H:109 [100]
   5.21%  kworker/0:1H:109 [100] S ==> swapper/0:0 [120]
   1.78%  swapper/3:0 [120] R ==> transmission-gt:17773 [120]
   1.78%  transmission-gt:17773 [120] S ==> swapper/3:0 [120]
   1.53%  Xephyr:6524 [120] S ==> swapper/0:0 [120]
   1.53%  swapper/0:0 [120] R ==> Xephyr:6524 [120]
   1.17%  swapper/2:0 [120] R ==> irq/33-iwlwifi:233 [49]
   1.13%  irq/33-iwlwifi:233 [49] S ==> swapper/2:0 [120]

Note that the 'trace' sort key works only for tracepoint events.  If
it's used to other type of events, just "N/A" will be printed.

Suggested-by: Jiri Olsa 
Cc: Steven Rostedt 
Signed-off-by: Namhyung Kim 
---
 tools/perf/util/hist.c |  1 +
 tools/perf/util/hist.h |  1 +
 tools/perf/util/sort.c | 61 ++
 tools/perf/util/sort.h |  2 ++
 4 files changed, 65 insertions(+)

diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index 99a6f1c17806..e471e0fa6a18 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -976,6 +976,7 @@ void hist_entry__delete(struct hist_entry *he)
if (he->srcfile && he->srcfile[0])
free(he->srcfile);
free_callchain(he->callchain);
+   free(he->trace_output);
free(he);
 }
 
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index 36439bfad059..15b22c563d30 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -52,6 +52,7 @@ enum hist_column {
HISTC_MEM_IADDR_SYMBOL,
HISTC_TRANSACTION,
HISTC_CYCLES,
+   HISTC_TRACE,
HISTC_NR_COLS, /* Last entry */
 };
 
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 746b1c405db2..caa8d3c1f6f9 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -445,6 +445,66 @@ struct sort_entry sort_socket = {
.se_width_idx   = HISTC_SOCKET,
 };
 
+/* --sort trace */
+
+static char *get_trace_output(struct hist_entry *he)
+{
+   struct trace_seq seq;
+   struct perf_evsel *evsel;
+   struct pevent_record rec = {
+   .cpu  = he->cpu,
+   .data = he->raw_data,
+   .size = he->raw_size,
+   };
+
+   evsel = hists_to_evsel(he->hists);
+
+   trace_seq_init();
+   pevent_event_info(, evsel->tp_format, );
+   return seq.buffer;
+}
+
+static int64_t
+sort__trace_cmp(struct hist_entry *left, struct hist_entry *right)
+{
+   struct perf_evsel *evsel;
+
+   evsel = hists_to_evsel(left->hists);
+   if (evsel->attr.type != PERF_TYPE_TRACEPOINT)
+   return 0;
+
+   if (left->trace_output == NULL)
+   left->trace_output = get_trace_output(left);
+   if (right->trace_output == NULL)
+   right->trace_output = get_trace_output(right);
+
+   hists__new_col_len(left->hists, HISTC_TRACE, 
strlen(left->trace_output));
+   hists__new_col_len(right->hists, HISTC_TRACE, 
strlen(right->trace_output));
+
+   return strcmp(right->trace_output, left->trace_output);
+}
+
+static int hist_entry__trace_snprintf(struct hist_entry *he, char *bf,
+   size_t size, unsigned int width)
+{
+   struct perf_evsel *evsel;
+
+   evsel = hists_to_evsel(he->hists);
+   if (evsel->attr.type != PERF_TYPE_TRACEPOINT)
+   return scnprintf(bf, size, "%-*.*s", width, width, "N/A");
+
+   if (he->trace_output == NULL)
+   he->trace_output = get_trace_output(he);
+   return repsep_snprintf(bf, size, "%-*.*s", width, width, 
he->trace_output);
+}
+
+struct sort_entry sort_trace = {
+   .se_header  = "Trace output",
+   .se_cmp = sort__trace_cmp,
+   .se_snprintf= hist_entry__trace_snprintf,
+   .se_width_idx   = HISTC_TRACE,
+};
+
 /* sort keys for branch stacks */
 
 static int64_t
@@ -1314,6 +1374,7 @@ static struct sort_dimension common_sort_dimensions[] = {
DIM(SORT_LOCAL_WEIGHT, "local_weight", sort_local_weight),
DIM(SORT_GLOBAL_WEIGHT, "weight", sort_global_weight),
DIM(SORT_TRANSACTION, "transaction", sort_transaction),
+   DIM(SORT_TRACE, "trace", sort_trace),
 };
 
 #undef DIM
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index aefcc2f8f173..a2c4bd059b81 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h