linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Adrian Hunter <adrian.hunter@intel.com>,
	David Ahern <dsahern@gmail.com>, Jiri Olsa <jolsa@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>,
	Wang Nan <wangnan0@huawei.com>
Subject: [PATCH 03/17] perf trace: Sort summary output by number of events
Date: Thu,  5 May 2016 21:29:26 -0300	[thread overview]
Message-ID: <1462494580-27164-4-git-send-email-acme@kernel.org> (raw)
In-Reply-To: <1462494580-27164-1-git-send-email-acme@kernel.org>

From: Arnaldo Carvalho de Melo <acme@redhat.com>

  # 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: Milian 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.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-trace.c | 49 ++++++++++++++++++++++++++--------------------
 1 file changed, 28 insertions(+), 21 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 9e38fe973f0c..aac0074cc926 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -36,6 +36,7 @@
 #include "util/bpf-loader.h"
 #include "callchain.h"
 #include "syscalltbl.h"
+#include "rb_resort.h"
 
 #include <libaudit.h> /* FIXME: Still needed for audit_errno_to_name */
 #include <stdlib.h>
@@ -2829,19 +2830,9 @@ static size_t thread__dump_stats(struct thread_trace *ttrace,
 	return printed;
 }
 
-/* struct used to pass data to per-thread function */
-struct summary_data {
-	FILE *fp;
-	struct trace *trace;
-	size_t printed;
-};
-
-static int trace__fprintf_one_thread(struct thread *thread, void *priv)
+static size_t trace__fprintf_thread(FILE *fp, struct thread *thread, struct trace *trace)
 {
-	struct summary_data *data = priv;
-	FILE *fp = data->fp;
-	size_t printed = data->printed;
-	struct trace *trace = data->trace;
+	size_t printed = 0;
 	struct thread_trace *ttrace = thread__priv(thread);
 	double ratio;
 
@@ -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 += 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)
 {
-	struct summary_data data = {
-		.fp = fp,
-		.trace = trace
-	};
-	data.printed = trace__fprintf_threads_header(fp);
+	DECLARE_RESORT_RB_MACHINE_THREADS(threads, trace->host);
+	size_t printed = trace__fprintf_threads_header(fp);
+	struct rb_node *nd;
 
-	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,
-- 
2.5.5

  parent reply	other threads:[~2016-05-06  0:29 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-06  0:29 [GIT PULL 00/17] perf/core improvements and fixes Arnaldo Carvalho de Melo
2016-05-06  0:29 ` [PATCH 01/17] perf machine: Introduce number of threads member Arnaldo Carvalho de Melo
2016-05-06  0:29 ` [PATCH 02/17] perf tools: Add template for generating rbtree resort class Arnaldo Carvalho de Melo
2016-05-06  0:29 ` Arnaldo Carvalho de Melo [this message]
2016-05-06  0:29 ` [PATCH 04/17] perf trace: Sort syscalls stats by msecs in --summary Arnaldo Carvalho de Melo
2016-05-06  0:29 ` [PATCH 05/17] perf trace: Do not show the runtime_ms for a thread when not collecting it Arnaldo Carvalho de Melo
2016-05-06  0:29 ` [PATCH 06/17] perf tools powerpc: Add support for generating bpf prologue Arnaldo Carvalho de Melo
2016-05-06  0:29 ` [PATCH 07/17] perf hists: Move sort__need_collapse into struct perf_hpp_list Arnaldo Carvalho de Melo
2016-05-06  0:29 ` [PATCH 08/17] perf hists: Move sort__has_parent " Arnaldo Carvalho de Melo
2016-05-06  0:29 ` [PATCH 09/17] perf hists: Move sort__has_sym " Arnaldo Carvalho de Melo
2016-05-06  0:29 ` [PATCH 10/17] perf hists: Move sort__has_dso " Arnaldo Carvalho de Melo
2016-05-06  0:29 ` [PATCH 11/17] perf hists: Move sort__has_socket " Arnaldo Carvalho de Melo
2016-05-06  0:29 ` [PATCH 12/17] perf hists: Move sort__has_thread " Arnaldo Carvalho de Melo
2016-05-06  0:29 ` [PATCH 13/17] perf hists: Move sort__has_comm " Arnaldo Carvalho de Melo
2016-05-06  0:29 ` [PATCH 14/17] perf powerpc: Fix kprobe and kretprobe handling with kallsyms on ppc64le Arnaldo Carvalho de Melo
2016-05-06  0:29 ` [PATCH 15/17] perf symbols: Fix kallsyms perf test " Arnaldo Carvalho de Melo
2016-05-06  0:29 ` [PATCH 16/17] perf evlist: Extract perf_mmap__read() Arnaldo Carvalho de Melo
2016-05-06  0:29 ` [PATCH 17/17] perf evlist: Rename variable in perf_mmap__read() Arnaldo Carvalho de Melo
2016-05-06  6:36 ` [GIT PULL 00/17] perf/core improvements and fixes Ingo Molnar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1462494580-27164-4-git-send-email-acme@kernel.org \
    --to=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=adrian.hunter@intel.com \
    --cc=dsahern@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=wangnan0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).