perf trace: Sort summary output by number of events

  # trace -a -s sleep 1 |& grep events | tail
   gmain (1733), 34 events, 1.0%, 0.000 msec
   hexchat (9765), 46 events, 1.4%, 0.000 msec
   ssh (11109), 80 events, 2.4%, 0.000 msec
   sleep (32631), 81 events, 2.4%, 0.000 msec
   qemu-system-x86 (10021), 272 events, 8.2%, 0.000 msec
   Xorg (1965), 322 events, 9.7%, 0.000 msec
   SoftwareVsyncTh (10922), 366 events, 11.1%, 0.000 msec
   gnome-shell (2231), 446 events, 13.5%, 0.000 msec
   qemu-system-x86 (9931), 468 events, 14.1%, 0.000 msec
   firefox (10871), 1098 events, 33.2%, 0.000 msec
  [root@jouet ~]#
Suggested-by: default avatarMilian Wolff <milian.wolff@kdab.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-ye4cnprhfeiq32ar4lt60dqs@git.kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent f58c2535
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "util/bpf-loader.h" #include "util/bpf-loader.h"
#include "callchain.h" #include "callchain.h"
#include "syscalltbl.h" #include "syscalltbl.h"
#include "rb_resort.h"
#include <libaudit.h> /* FIXME: Still needed for audit_errno_to_name */ #include <libaudit.h> /* FIXME: Still needed for audit_errno_to_name */
#include <stdlib.h> #include <stdlib.h>
...@@ -2829,19 +2830,9 @@ static size_t thread__dump_stats(struct thread_trace *ttrace, ...@@ -2829,19 +2830,9 @@ static size_t thread__dump_stats(struct thread_trace *ttrace,
return printed; return printed;
} }
/* struct used to pass data to per-thread function */ static size_t trace__fprintf_thread(FILE *fp, struct thread *thread, struct trace *trace)
struct summary_data {
FILE *fp;
struct trace *trace;
size_t printed;
};
static int trace__fprintf_one_thread(struct thread *thread, void *priv)
{ {
struct summary_data *data = priv; size_t printed = 0;
FILE *fp = data->fp;
size_t printed = data->printed;
struct trace *trace = data->trace;
struct thread_trace *ttrace = thread__priv(thread); struct thread_trace *ttrace = thread__priv(thread);
double ratio; double ratio;
...@@ -2860,22 +2851,38 @@ static int trace__fprintf_one_thread(struct thread *thread, void *priv) ...@@ -2860,22 +2851,38 @@ static int trace__fprintf_one_thread(struct thread *thread, void *priv)
printed += fprintf(fp, ", %.3f msec\n", ttrace->runtime_ms); printed += fprintf(fp, ", %.3f msec\n", ttrace->runtime_ms);
printed += thread__dump_stats(ttrace, trace, fp); printed += thread__dump_stats(ttrace, trace, fp);
data->printed += printed; return printed;
}
return 0; static unsigned long thread__nr_events(struct thread_trace *ttrace)
{
return ttrace ? ttrace->nr_events : 0;
}
DEFINE_RESORT_RB(threads, (thread__nr_events(a->thread->priv) < thread__nr_events(b->thread->priv)),
struct thread *thread;
)
{
entry->thread = rb_entry(nd, struct thread, rb_node);
} }
static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp) static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp)
{ {
struct summary_data data = { DECLARE_RESORT_RB_MACHINE_THREADS(threads, trace->host);
.fp = fp, size_t printed = trace__fprintf_threads_header(fp);
.trace = trace struct rb_node *nd;
};
data.printed = trace__fprintf_threads_header(fp);
machine__for_each_thread(trace->host, trace__fprintf_one_thread, &data); if (threads == NULL) {
fprintf(fp, "%s", "Error sorting output by nr_events!\n");
return 0;
}
resort_rb__for_each(nd, threads)
printed += trace__fprintf_thread(fp, threads_entry->thread, trace);
return data.printed; resort_rb__delete(threads);
return printed;
} }
static int trace__set_duration(const struct option *opt, const char *str, static int trace__set_duration(const struct option *opt, const char *str,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment