linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@infradead.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	David Ahern <dsahern@gmail.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Jiri Olsa <jolsa@redhat.com>, Mike Galbraith <efault@gmx.de>,
	Namhyung Kim <namhyung@gmail.com>,
	Paul Mackerras <paulus@samba.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Stephane Eranian <eranian@google.com>
Subject: [PATCH 08/30] perf kmem: Use perf_evsel__intval and perf_session__set_tracepoints_handlers
Date: Mon, 24 Sep 2012 12:59:22 -0300	[thread overview]
Message-ID: <1348502384-14442-9-git-send-email-acme@infradead.org> (raw)
In-Reply-To: <1348502384-14442-1-git-send-email-acme@infradead.org>

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

Following the model of 'perf sched':

. raw_field_value searches first on the common fields, that are unused
  in this tool

. Using perf_session__set_tracepoints_handlers will save all those
  strcmp to find the right handler at sample processing time, do it just
  once and get the handler from evsel->handler.func.

Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-v9x3q9rv4caxtox7wtjpchq5@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-kmem.c |   90 ++++++++++++++++++++++----------------------
 1 files changed, 45 insertions(+), 45 deletions(-)

diff --git a/tools/perf/builtin-kmem.c b/tools/perf/builtin-kmem.c
index f5f8a6b..bc912c6 100644
--- a/tools/perf/builtin-kmem.c
+++ b/tools/perf/builtin-kmem.c
@@ -1,6 +1,7 @@
 #include "builtin.h"
 #include "perf.h"
 
+#include "util/evlist.h"
 #include "util/evsel.h"
 #include "util/util.h"
 #include "util/cache.h"
@@ -212,36 +213,38 @@ static int insert_caller_stat(unsigned long call_site,
 }
 
 static int perf_evsel__process_alloc_event(struct perf_evsel *evsel,
-					   struct perf_sample *sample, int node)
+					   struct perf_sample *sample)
 {
-	struct event_format *event = evsel->tp_format;
-	void *data = sample->raw_data;
-	unsigned long call_site;
-	unsigned long ptr;
-	int bytes_req, cpu = sample->cpu;
-	int bytes_alloc;
-	int node1, node2;
-
-	ptr = raw_field_value(event, "ptr", data);
-	call_site = raw_field_value(event, "call_site", data);
-	bytes_req = raw_field_value(event, "bytes_req", data);
-	bytes_alloc = raw_field_value(event, "bytes_alloc", data);
-
-	if (insert_alloc_stat(call_site, ptr, bytes_req, bytes_alloc, cpu) ||
+	unsigned long ptr = perf_evsel__intval(evsel, sample, "ptr"),
+		      call_site = perf_evsel__intval(evsel, sample, "call_site");
+	int bytes_req = perf_evsel__intval(evsel, sample, "bytes_req"),
+	    bytes_alloc = perf_evsel__intval(evsel, sample, "bytes_alloc");
+
+	if (insert_alloc_stat(call_site, ptr, bytes_req, bytes_alloc, sample->cpu) ||
 	    insert_caller_stat(call_site, bytes_req, bytes_alloc))
 		return -1;
 
 	total_requested += bytes_req;
 	total_allocated += bytes_alloc;
 
-	if (node) {
-		node1 = cpunode_map[cpu];
-		node2 = raw_field_value(event, "node", data);
+	nr_allocs++;
+	return 0;
+}
+
+static int perf_evsel__process_alloc_node_event(struct perf_evsel *evsel,
+						struct perf_sample *sample)
+{
+	int ret = perf_evsel__process_alloc_event(evsel, sample);
+
+	if (!ret) {
+		int node1 = cpunode_map[sample->cpu],
+		    node2 = perf_evsel__intval(evsel, sample, "node");
+
 		if (node1 != node2)
 			nr_cross_allocs++;
 	}
-	nr_allocs++;
-	return 0;
+
+	return ret;
 }
 
 static int ptr_cmp(struct alloc_stat *, struct alloc_stat *);
@@ -275,8 +278,7 @@ static struct alloc_stat *search_alloc_stat(unsigned long ptr,
 static int perf_evsel__process_free_event(struct perf_evsel *evsel,
 					  struct perf_sample *sample)
 {
-	unsigned long ptr = raw_field_value(evsel->tp_format, "ptr",
-					    sample->raw_data);
+	unsigned long ptr = perf_evsel__intval(evsel, sample, "ptr");
 	struct alloc_stat *s_alloc, *s_caller;
 
 	s_alloc = search_alloc_stat(ptr, 0, &root_alloc_stat, ptr_cmp);
@@ -297,28 +299,8 @@ static int perf_evsel__process_free_event(struct perf_evsel *evsel,
 	return 0;
 }
 
-static int perf_evsel__process_kmem_event(struct perf_evsel *evsel,
-					  struct perf_sample *sample)
-{
-	struct event_format *event = evsel->tp_format;
-
-	if (!strcmp(event->name, "kmalloc") ||
-	    !strcmp(event->name, "kmem_cache_alloc")) {
-		return perf_evsel__process_alloc_event(evsel, sample, 0);
-	}
-
-	if (!strcmp(event->name, "kmalloc_node") ||
-	    !strcmp(event->name, "kmem_cache_alloc_node")) {
-		return perf_evsel__process_alloc_event(evsel, sample, 1);
-	}
-
-	if (!strcmp(event->name, "kfree") ||
-	    !strcmp(event->name, "kmem_cache_free")) {
-		return perf_evsel__process_free_event(evsel, sample);
-	}
-
-	return 0;
-}
+typedef int (*tracepoint_handler)(struct perf_evsel *evsel,
+				  struct perf_sample *sample);
 
 static int process_sample_event(struct perf_tool *tool __maybe_unused,
 				union perf_event *event,
@@ -336,7 +318,12 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
 
 	dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);
 
-	return perf_evsel__process_kmem_event(evsel, sample);
+	if (evsel->handler.func != NULL) {
+		tracepoint_handler f = evsel->handler.func;
+		return f(evsel, sample);
+	}
+
+	return 0;
 }
 
 static struct perf_tool perf_kmem = {
@@ -498,6 +485,14 @@ static int __cmd_kmem(void)
 {
 	int err = -EINVAL;
 	struct perf_session *session;
+	const struct perf_evsel_str_handler kmem_tracepoints[] = {
+		{ "kmem:kmalloc",		perf_evsel__process_alloc_event, },
+    		{ "kmem:kmem_cache_alloc",	perf_evsel__process_alloc_event, },
+		{ "kmem:kmalloc_node",		perf_evsel__process_alloc_node_event, },
+    		{ "kmem:kmem_cache_alloc_node", perf_evsel__process_alloc_node_event, },
+		{ "kmem:kfree",			perf_evsel__process_free_event, },
+    		{ "kmem:kmem_cache_free",	perf_evsel__process_free_event, },
+	};
 
 	session = perf_session__new(input_name, O_RDONLY, 0, false, &perf_kmem);
 	if (session == NULL)
@@ -509,6 +504,11 @@ static int __cmd_kmem(void)
 	if (!perf_session__has_traces(session, "kmem record"))
 		goto out_delete;
 
+	if (perf_session__set_tracepoints_handlers(session, kmem_tracepoints)) {
+		pr_err("Initializing perf session tracepoint handlers failed\n");
+		return -1;
+	}
+
 	setup_pager();
 	err = perf_session__process_events(session, &perf_kmem);
 	if (err != 0)
-- 
1.7.1


  parent reply	other threads:[~2012-09-24 16:00 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-24 15:59 [GIT PULL 00/30] perf/core improvements and fixes Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 01/30] perf tools: Fix a compiling error in trace-event-perl.c for 32 bits machine Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 02/30] perf tools: Fix a compiling error in util/map.c Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 03/30] perf record: Print event causing perf_event_open() to fail Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 04/30] perf tools: Fix parallel build Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 05/30] KVM: x86: Export svm/vmx exit code and vector code to userspace Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 06/30] perf kvm: Events analysis tool Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 07/30] perf kvm: Use perf_evsel__intval Arnaldo Carvalho de Melo
2012-09-24 15:59 ` Arnaldo Carvalho de Melo [this message]
2012-09-24 15:59 ` [PATCH 09/30] perf lock: Use perf_evsel__intval and perf_session__set_tracepoints_handlers Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 10/30] perf timechart: Use zalloc and fix a couple leaks Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 11/30] perf header: Add struct perf_session_env Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 12/30] perf header: Add ->process callbacks to most of features Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 13/30] perf header: Use pre-processed session env when printing Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 14/30] perf header: Remove unused @feat arg from ->process callback Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 15/30] perf kvm: Use perf_session_env for reading cpuid Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 16/30] perf header: Remove perf_header__read_feature Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 17/30] perf tools: remove sscanf extension %as Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 18/30] tools lib traceevent: Fix error path on process_array() Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 19/30] tools lib traceevent: Make sure that arg->op.right is set properly Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 20/30] tools lib traceevent: Free field if an error occurs on process_fields Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 21/30] tools lib traceevent: Free field if an error occurs on process_flags/symbols Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 22/30] perf tools: bfd.h/libbfd detection fails with recent binutils Arnaldo Carvalho de Melo
2012-09-24 23:58   ` Mike Frysinger
2012-09-25  6:47     ` Markus Trippelsdorf
2012-09-25 16:40       ` Mike Frysinger
2012-09-24 15:59 ` [PATCH 23/30] tools lib traceevent: Use asprintf were applicable Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 24/30] tools lib traceevent: Use calloc " Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 25/30] tools lib traceevent: Fix afterlife gotos Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 26/30] tools lib traceevent: Remove some die() calls Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 27/30] tools lib traceevent: Carve out events format parsing routine Arnaldo Carvalho de Melo
2012-09-25  4:15   ` Namhyung Kim
2012-09-25 11:12     ` Arnaldo Carvalho de Melo
2012-09-25 12:25       ` [PATCH] tools lib traceevent: Fix error path on pevent_parse_event Namhyung Kim
2012-09-27  5:51         ` [tip:perf/core] " tip-bot for Namhyung Kim
2012-09-24 15:59 ` [PATCH 28/30] perf evsel: Provide a new constructor for tracepoints Arnaldo Carvalho de Melo
2012-09-25  4:26   ` Namhyung Kim
2012-09-25 11:28     ` Arnaldo Carvalho de Melo
2012-09-24 15:59 ` [PATCH 29/30] perf test: Add test for the sched tracepoint format fields Arnaldo Carvalho de Melo
2012-09-25  4:31   ` Namhyung Kim
2012-09-24 15:59 ` [PATCH 30/30] tools lib traceevent: Handle alloc_arg failure Arnaldo Carvalho de Melo

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=1348502384-14442-9-git-send-email-acme@infradead.org \
    --to=acme@infradead.org \
    --cc=acme@redhat.com \
    --cc=dsahern@gmail.com \
    --cc=efault@gmx.de \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@gmail.com \
    --cc=paulus@samba.org \
    --cc=peterz@infradead.org \
    /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).