Skip to contentSkip to conversation

perf script: add support for dumping events other than trace

PATCH In review David Ahern 4 participants 20 messages Mar 10, 2011 – Mar 16, 2011 perf events

lore
Share & tools
lore
#0 lore raw

v4 cover perf script: add support for dumping events other than trace

v3 -> v4:
- moved code removal to separate patch
- added check that callchain exists before trying to use it
- cleaned up whitespace errors so acme does not have to

v2 -> v3:
- removed show-unresolved option
- setup different output defaults based on event type
- moved printing of comm, pid/tid, time and event name from print_event to builtin-script and renamed print_event to print_trace_event
- removed unneeded cursor depth check
- updated to latest perf-core to get Arnaldo's recent makeovers
- created smaller, focused patches

v1 -> v2:
- fixed process_event handler in trace-event-perl
- removed unneeded call to callchain_register_param
- corrected walking of callchains in perf_session__print_symbols
- complete rewrite for handling non-tracepoint events

David Ahern (6):
perf script: change process_event prototype
perf: remove print_graph_cpu and print_graph_proc from
trace-event-parse
perf script: move printing of 'common' data from print_event and
rename
perf script: support custom field selection for output perf script: add support for dumping symbols
perf script: add support for H/W and S/W events

 tools/perf/Documentation/perf-script.txt           |   22 ++
 tools/perf/builtin-script.c                        |  300 ++++++++++++++++++--
 tools/perf/util/parse-events.c                     |   22 ++
 tools/perf/util/parse-events.h                     |    1 +
 .../perf/util/scripting-engines/trace-event-perl.c |   11 +-
 .../util/scripting-engines/trace-event-python.c    |   11 +-
 tools/perf/util/session.c                          |   61 ++++
 tools/perf/util/session.h                          |    4 +
 tools/perf/util/trace-event-parse.c                |  110 +-------
 tools/perf/util/trace-event-scripting.c            |    9 +-
 tools/perf/util/trace-event.h                      |   10 +-
 11 files changed, 423 insertions(+), 138 deletions(-)
Signature · 1 line
1.7.4
#1 lore raw

PATCH v4 1/6 perf script: change process_event prototype

Prepare for handling of samples for any event type.

---
 tools/perf/builtin-script.c                        |   25 ++++++++++++-------
 .../perf/util/scripting-engines/trace-event-perl.c |   11 ++++++--
 .../util/scripting-engines/trace-event-python.c    |   11 ++++++--
 tools/perf/util/trace-event-scripting.c            |    9 +++----
 tools/perf/util/trace-event.h                      |    7 ++++-
 5 files changed, 41 insertions(+), 22 deletions(-)
tools/perf/builtin-script.c +16 -9
index 5f40df6..b2bdd55 100644
@@ -20,6 +20,20 @@ static u64			last_timestamp;
 static u64			nr_unordered;
 extern const struct option	record_options[];
 
+static void process_event(union perf_event *event __unused,
+			  struct perf_sample *sample,
+			  struct perf_session *session __unused,
+			  struct thread *thread)
+{
+	/*
+	 * FIXME: better resolve from pid from the struct trace_entry
+	 * field, although it should be the same than this perf
+	 * event pid
+	 */
+	print_event(sample->cpu, sample->raw_data, sample->raw_size,
+		    sample->time, thread->comm);
+}
+
 static int default_start_script(const char *script __unused,
 				int argc __unused,
 				const char **argv __unused)
@@ -40,7 +54,7 @@ static int default_generate_script(const char *outfile __unused)
 static struct scripting_ops default_scripting_ops = {
 	.start_script		= default_start_script,
 	.stop_script		= default_stop_script,
-	.process_event		= print_event,
+	.process_event		= process_event,
 	.generate_script	= default_generate_script,
 };
 
@@ -86,14 +100,7 @@ static int process_sample_event(union perf_event *event,
 			last_timestamp = sample->time;
 			return 0;
 		}
-		/*
-		 * FIXME: better resolve from pid from the struct trace_entry
-		 * field, although it should be the same than this perf
-		 * event pid
-		 */
-		scripting_ops->process_event(sample->cpu, sample->raw_data,
-					     sample->raw_size,
-					     sample->time, thread->comm);
+		scripting_ops->process_event(event, sample, session, thread);
 	}
 
 	session->hists.stats.total_period += sample->period;
tools/perf/util/scripting-engines/trace-event-perl.c +8 -3
index 9368081..6214272 100644
@@ -245,9 +245,10 @@ static inline struct event *find_cache_event(int type)
 	return event;
 }
 
-static void perl_process_event(int cpu, void *data,
-			       int size __unused,
-			       unsigned long long nsecs, char *comm)
+static void perl_process_event(union perf_event *pevent __unused,
+			       struct perf_sample *sample,
+			       struct perf_session *session __unused,
+			       struct thread *thread)
 {
 	struct format_field *field;
 	static char handler[256];
@@ -256,6 +257,10 @@ static void perl_process_event(int cpu, void *data,
 	struct event *event;
 	int type;
 	int pid;
+	int cpu = sample->cpu;
+	void *data = sample->raw_data;
+	unsigned long long nsecs = sample->time;
+	char *comm = thread->comm;
 
 	dSP;
 
tools/perf/util/scripting-engines/trace-event-python.c +8 -3
index 2040b85..1b85d60 100644
@@ -204,9 +204,10 @@ static inline struct event *find_cache_event(int type)
 	return event;
 }
 
-static void python_process_event(int cpu, void *data,
-				 int size __unused,
-				 unsigned long long nsecs, char *comm)
+static void python_process_event(union perf_event *pevent __unused,
+				 struct perf_sample *sample,
+				 struct perf_session *session __unused,
+				 struct thread *thread)
 {
 	PyObject *handler, *retval, *context, *t, *obj, *dict = NULL;
 	static char handler_name[256];
@@ -217,6 +218,10 @@ static void python_process_event(int cpu, void *data,
 	unsigned n = 0;
 	int type;
 	int pid;
+	int cpu = sample->cpu;
+	void *data = sample->raw_data;
+	unsigned long long nsecs = sample->time;
+	char *comm = thread->comm;
 
 	t = PyTuple_New(MAX_FIELDS);
 	if (!t)
tools/perf/util/trace-event-scripting.c +4 -5
index f7af2fc..66f4b78 100644
@@ -36,11 +36,10 @@ static int stop_script_unsupported(void)
 	return 0;
 }
 
-static void process_event_unsupported(int cpu __unused,
-				      void *data __unused,
-				      int size __unused,
-				      unsigned long long nsecs __unused,
-				      char *comm __unused)
+static void process_event_unsupported(union perf_event *event __unused,
+				      struct perf_sample *sample __unused,
+				      struct perf_session *session __unused,
+				      struct thread *thread __unused)
 {
 }
 
tools/perf/util/trace-event.h +5 -2
index b5f12ca..5f7b513 100644
@@ -3,6 +3,7 @@
 
 #include <stdbool.h>
 #include "parse-events.h"
+#include "session.h"
 
 #define __unused __attribute__((unused))
 
@@ -278,8 +279,10 @@ struct scripting_ops {
 	const char *name;
 	int (*start_script) (const char *script, int argc, const char **argv);
 	int (*stop_script) (void);
-	void (*process_event) (int cpu, void *data, int size,
-			       unsigned long long nsecs, char *comm);
+	void (*process_event) (union perf_event *event,
+			       struct perf_sample *sample,
+			       struct perf_session *session,
+			       struct thread *thread);
 	int (*generate_script) (const char *outfile);
 };
 
Signature · 1 line
1.7.4
#2 lore raw

[tip:perf/urgent] perf script: Change process_event prototype

Commit-ID:  be6d842a65babc54e2b204b382df2529e304be48
Gitweb:     http://git.kernel.org/tip/be6d842a65babc54e2b204b382df2529e304be48
Author:     David Ahern <[email protected]>
AuthorDate: Wed, 9 Mar 2011 22:23:23 -0700
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 14 Mar 2011 17:05:50 -0300

perf script: Change process_event prototype

Prepare for handling of samples for any event type.

Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>

LKML-Reference: <[email protected]>

---
 tools/perf/builtin-script.c                        |   25 ++++++++++++-------
 .../perf/util/scripting-engines/trace-event-perl.c |   11 ++++++--
 .../util/scripting-engines/trace-event-python.c    |   11 ++++++--
 tools/perf/util/trace-event-scripting.c            |    9 +++----
 tools/perf/util/trace-event.h                      |    7 ++++-
 5 files changed, 41 insertions(+), 22 deletions(-)
tools/perf/builtin-script.c +16 -9
index 5f40df6..b2bdd55 100644
@@ -20,6 +20,20 @@ static u64			last_timestamp;
 static u64			nr_unordered;
 extern const struct option	record_options[];
 
+static void process_event(union perf_event *event __unused,
+			  struct perf_sample *sample,
+			  struct perf_session *session __unused,
+			  struct thread *thread)
+{
+	/*
+	 * FIXME: better resolve from pid from the struct trace_entry
+	 * field, although it should be the same than this perf
+	 * event pid
+	 */
+	print_event(sample->cpu, sample->raw_data, sample->raw_size,
+		    sample->time, thread->comm);
+}
+
 static int default_start_script(const char *script __unused,
 				int argc __unused,
 				const char **argv __unused)
@@ -40,7 +54,7 @@ static int default_generate_script(const char *outfile __unused)
 static struct scripting_ops default_scripting_ops = {
 	.start_script		= default_start_script,
 	.stop_script		= default_stop_script,
-	.process_event		= print_event,
+	.process_event		= process_event,
 	.generate_script	= default_generate_script,
 };
 
@@ -86,14 +100,7 @@ static int process_sample_event(union perf_event *event,
 			last_timestamp = sample->time;
 			return 0;
 		}
-		/*
-		 * FIXME: better resolve from pid from the struct trace_entry
-		 * field, although it should be the same than this perf
-		 * event pid
-		 */
-		scripting_ops->process_event(sample->cpu, sample->raw_data,
-					     sample->raw_size,
-					     sample->time, thread->comm);
+		scripting_ops->process_event(event, sample, session, thread);
 	}
 
 	session->hists.stats.total_period += sample->period;
tools/perf/util/scripting-engines/trace-event-perl.c +8 -3
index 9368081..6214272 100644
@@ -245,9 +245,10 @@ static inline struct event *find_cache_event(int type)
 	return event;
 }
 
-static void perl_process_event(int cpu, void *data,
-			       int size __unused,
-			       unsigned long long nsecs, char *comm)
+static void perl_process_event(union perf_event *pevent __unused,
+			       struct perf_sample *sample,
+			       struct perf_session *session __unused,
+			       struct thread *thread)
 {
 	struct format_field *field;
 	static char handler[256];
@@ -256,6 +257,10 @@ static void perl_process_event(int cpu, void *data,
 	struct event *event;
 	int type;
 	int pid;
+	int cpu = sample->cpu;
+	void *data = sample->raw_data;
+	unsigned long long nsecs = sample->time;
+	char *comm = thread->comm;
 
 	dSP;
 
tools/perf/util/scripting-engines/trace-event-python.c +8 -3
index 2040b85..1b85d60 100644
@@ -204,9 +204,10 @@ static inline struct event *find_cache_event(int type)
 	return event;
 }
 
-static void python_process_event(int cpu, void *data,
-				 int size __unused,
-				 unsigned long long nsecs, char *comm)
+static void python_process_event(union perf_event *pevent __unused,
+				 struct perf_sample *sample,
+				 struct perf_session *session __unused,
+				 struct thread *thread)
 {
 	PyObject *handler, *retval, *context, *t, *obj, *dict = NULL;
 	static char handler_name[256];
@@ -217,6 +218,10 @@ static void python_process_event(int cpu, void *data,
 	unsigned n = 0;
 	int type;
 	int pid;
+	int cpu = sample->cpu;
+	void *data = sample->raw_data;
+	unsigned long long nsecs = sample->time;
+	char *comm = thread->comm;
 
 	t = PyTuple_New(MAX_FIELDS);
 	if (!t)
tools/perf/util/trace-event-scripting.c +4 -5
index f7af2fc..66f4b78 100644
@@ -36,11 +36,10 @@ static int stop_script_unsupported(void)
 	return 0;
 }
 
-static void process_event_unsupported(int cpu __unused,
-				      void *data __unused,
-				      int size __unused,
-				      unsigned long long nsecs __unused,
-				      char *comm __unused)
+static void process_event_unsupported(union perf_event *event __unused,
+				      struct perf_sample *sample __unused,
+				      struct perf_session *session __unused,
+				      struct thread *thread __unused)
 {
 }
 
tools/perf/util/trace-event.h +5 -2
index b5f12ca..5f7b513 100644
@@ -3,6 +3,7 @@
 
 #include <stdbool.h>
 #include "parse-events.h"
+#include "session.h"
 
 #define __unused __attribute__((unused))
 
@@ -278,8 +279,10 @@ struct scripting_ops {
 	const char *name;
 	int (*start_script) (const char *script, int argc, const char **argv);
 	int (*stop_script) (void);
-	void (*process_event) (int cpu, void *data, int size,
-			       unsigned long long nsecs, char *comm);
+	void (*process_event) (union perf_event *event,
+			       struct perf_sample *sample,
+			       struct perf_session *session,
+			       struct thread *thread);
 	int (*generate_script) (const char *outfile);
 };
 
#3 lore raw

PATCH v4 2/6 perf: remove print_graph_cpu and print_graph_proc from trace-event-parse

In reply to David Ahern

Next patch moves printing of 'common' data into perf-script which removes the need for these functions.

---
 tools/perf/util/trace-event-parse.c |   65 +---------------------------------
 1 files changed, 2 insertions(+), 63 deletions(-)
tools/perf/util/trace-event-parse.c +2 -63
index d8e622d..dd5f058 100644
@@ -2648,63 +2648,8 @@ static void print_lat_fmt(void *data, int size __unused)
 		printf("%d", lock_depth);
 }
 
-/* taken from Linux, written by Frederic Weisbecker */
-static void print_graph_cpu(int cpu)
-{
-	int i;
-	int log10_this = log10_cpu(cpu);
-	int log10_all = log10_cpu(cpus);
-
-
-	/*
-	 * Start with a space character - to make it stand out
-	 * to the right a bit when trace output is pasted into
-	 * email:
-	 */
-	printf(" ");
-
-	/*
-	 * Tricky - we space the CPU field according to the max
-	 * number of online CPUs. On a 2-cpu system it would take
-	 * a maximum of 1 digit - on a 128 cpu system it would
-	 * take up to 3 digits:
-	 */
-	for (i = 0; i < log10_all - log10_this; i++)
-		printf(" ");
-
-	printf("%d) ", cpu);
-}
-
-#define TRACE_GRAPH_PROCINFO_LENGTH	14
 #define TRACE_GRAPH_INDENT	2
 
-static void print_graph_proc(int pid, const char *comm)
-{
-	/* sign + log10(MAX_INT) + '\0' */
-	char pid_str[11];
-	int spaces = 0;
-	int len;
-	int i;
-
-	sprintf(pid_str, "%d", pid);
-
-	/* 1 stands for the "-" character */
-	len = strlen(comm) + strlen(pid_str) + 1;
-
-	if (len < TRACE_GRAPH_PROCINFO_LENGTH)
-		spaces = TRACE_GRAPH_PROCINFO_LENGTH - len;
-
-	/* First spaces to align center */
-	for (i = 0; i < spaces / 2; i++)
-		printf(" ");
-
-	printf("%s-%s", comm, pid_str);
-
-	/* Last spaces to align center */
-	for (i = 0; i < spaces - (spaces / 2); i++)
-		printf(" ");
-}
-
 static struct record *
 get_return_for_leaf(int cpu, int cur_pid, unsigned long long cur_func,
 		    struct record *next)
@@ -2876,7 +2821,7 @@ static void print_graph_nested(struct event *event, void *data)
 
 static void
 pretty_print_func_ent(void *data, int size, struct event *event,
-		      int cpu, int pid, const char *comm,
+		      int cpu, int pid, const char *comm __unused,
 		      unsigned long secs, unsigned long usecs)
 {
 	struct format_field *field;
@@ -2886,9 +2831,6 @@ pretty_print_func_ent(void *data, int size, struct event *event,
 
 	printf("%5lu.%06lu |  ", secs, usecs);
 
-	print_graph_cpu(cpu);
-	print_graph_proc(pid, comm);
-
 	printf(" | ");
 
 	if (latency_format) {
@@ -2924,7 +2866,7 @@ out_free:
 
 static void
 pretty_print_func_ret(void *data, int size __unused, struct event *event,
-		      int cpu, int pid, const char *comm,
+		      int cpu __unused, int pid __unused, const char *comm __unused,
 		      unsigned long secs, unsigned long usecs)
 {
 	unsigned long long rettime, calltime;
@@ -2934,9 +2876,6 @@ pretty_print_func_ret(void *data, int size __unused, struct event *event,
 
 	printf("%5lu.%06lu |  ", secs, usecs);
 
-	print_graph_cpu(cpu);
-	print_graph_proc(pid, comm);
-
 	printf(" | ");
 
 	if (latency_format) {
Signature · 1 line
1.7.4
#4 lore raw

[tip:perf/urgent] perf tracing: Remove print_graph_cpu and print_graph_proc from trace-event-parse

Commit-ID:  2ee7a49f935b19f7daf0a110800488acd2479cba
Gitweb:     http://git.kernel.org/tip/2ee7a49f935b19f7daf0a110800488acd2479cba
Author:     David Ahern <[email protected]>
AuthorDate: Wed, 9 Mar 2011 22:23:24 -0700
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 14 Mar 2011 17:05:51 -0300

perf tracing: Remove print_graph_cpu and print_graph_proc from trace-event-parse

Next patch moves printing of 'common' data into perf-script which removes the need for these functions.

Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>

LKML-Reference: <[email protected]>

---
 tools/perf/util/trace-event-parse.c |   65 +---------------------------------
 1 files changed, 2 insertions(+), 63 deletions(-)
tools/perf/util/trace-event-parse.c +2 -63
index d8e622d..dd5f058 100644
@@ -2648,63 +2648,8 @@ static void print_lat_fmt(void *data, int size __unused)
 		printf("%d", lock_depth);
 }
 
-/* taken from Linux, written by Frederic Weisbecker */
-static void print_graph_cpu(int cpu)
-{
-	int i;
-	int log10_this = log10_cpu(cpu);
-	int log10_all = log10_cpu(cpus);
-
-
-	/*
-	 * Start with a space character - to make it stand out
-	 * to the right a bit when trace output is pasted into
-	 * email:
-	 */
-	printf(" ");
-
-	/*
-	 * Tricky - we space the CPU field according to the max
-	 * number of online CPUs. On a 2-cpu system it would take
-	 * a maximum of 1 digit - on a 128 cpu system it would
-	 * take up to 3 digits:
-	 */
-	for (i = 0; i < log10_all - log10_this; i++)
-		printf(" ");
-
-	printf("%d) ", cpu);
-}
-
-#define TRACE_GRAPH_PROCINFO_LENGTH	14
 #define TRACE_GRAPH_INDENT	2
 
-static void print_graph_proc(int pid, const char *comm)
-{
-	/* sign + log10(MAX_INT) + '\0' */
-	char pid_str[11];
-	int spaces = 0;
-	int len;
-	int i;
-
-	sprintf(pid_str, "%d", pid);
-
-	/* 1 stands for the "-" character */
-	len = strlen(comm) + strlen(pid_str) + 1;
-
-	if (len < TRACE_GRAPH_PROCINFO_LENGTH)
-		spaces = TRACE_GRAPH_PROCINFO_LENGTH - len;
-
-	/* First spaces to align center */
-	for (i = 0; i < spaces / 2; i++)
-		printf(" ");
-
-	printf("%s-%s", comm, pid_str);
-
-	/* Last spaces to align center */
-	for (i = 0; i < spaces - (spaces / 2); i++)
-		printf(" ");
-}
-
 static struct record *
 get_return_for_leaf(int cpu, int cur_pid, unsigned long long cur_func,
 		    struct record *next)
@@ -2876,7 +2821,7 @@ static void print_graph_nested(struct event *event, void *data)
 
 static void
 pretty_print_func_ent(void *data, int size, struct event *event,
-		      int cpu, int pid, const char *comm,
+		      int cpu, int pid, const char *comm __unused,
 		      unsigned long secs, unsigned long usecs)
 {
 	struct format_field *field;
@@ -2886,9 +2831,6 @@ pretty_print_func_ent(void *data, int size, struct event *event,
 
 	printf("%5lu.%06lu |  ", secs, usecs);
 
-	print_graph_cpu(cpu);
-	print_graph_proc(pid, comm);
-
 	printf(" | ");
 
 	if (latency_format) {
@@ -2924,7 +2866,7 @@ out_free:
 
 static void
 pretty_print_func_ret(void *data, int size __unused, struct event *event,
-		      int cpu, int pid, const char *comm,
+		      int cpu __unused, int pid __unused, const char *comm __unused,
 		      unsigned long secs, unsigned long usecs)
 {
 	unsigned long long rettime, calltime;
@@ -2934,9 +2876,6 @@ pretty_print_func_ret(void *data, int size __unused, struct event *event,
 
 	printf("%5lu.%06lu |  ", secs, usecs);
 
-	print_graph_cpu(cpu);
-	print_graph_proc(pid, comm);
-
 	printf(" | ");
 
 	if (latency_format) {
#5 lore raw

PATCH v4 3/6 perf script: move printing of 'common' data from print_event and rename

In reply to David Ahern

This change does impact output: latency data is trace specific and is now printed after the common data - comm, tid, cpu, time and event name.

---
 tools/perf/builtin-script.c         |   38 ++++++++++++++++++++++-----
 tools/perf/util/trace-event-parse.c |   49 +++++++---------------------------
 tools/perf/util/trace-event.h       |    3 +-
 3 files changed, 42 insertions(+), 48 deletions(-)
tools/perf/builtin-script.c +31 -7
index b2bdd55..0a79da2 100644
@@ -20,18 +20,42 @@ static u64			last_timestamp;
 static u64			nr_unordered;
 extern const struct option	record_options[];
 
+static void print_sample_start(struct perf_sample *sample,
+			       struct thread *thread)
+{
+	int type;
+	struct event *event;
+	const char *evname = NULL;
+	unsigned long secs;
+	unsigned long usecs;
+	unsigned long long nsecs = sample->time;
+
+	if (latency_format)
+		printf("%8.8s-%-5d %3d", thread->comm, sample->tid, sample->cpu);
+	else
+		printf("%16s-%-5d [%03d]", thread->comm, sample->tid, sample->cpu);
+
+	secs = nsecs / NSECS_PER_SEC;
+	nsecs -= secs * NSECS_PER_SEC;
+	usecs = nsecs / NSECS_PER_USEC;
+	printf(" %5lu.%06lu: ", secs, usecs);
+
+	type = trace_parse_common_type(sample->raw_data);
+	event = trace_find_event(type);
+	if (event)
+		evname = event->name;
+
+	printf("%s: ", evname ? evname : "(unknown)");
+}
+
 static void process_event(union perf_event *event __unused,
 			  struct perf_sample *sample,
 			  struct perf_session *session __unused,
 			  struct thread *thread)
 {
-	/*
-	 * FIXME: better resolve from pid from the struct trace_entry
-	 * field, although it should be the same than this perf
-	 * event pid
-	 */
-	print_event(sample->cpu, sample->raw_data, sample->raw_size,
-		    sample->time, thread->comm);
+	print_sample_start(sample, thread);
+	print_trace_event(sample->cpu, sample->raw_data, sample->raw_size);
+	printf("\n");
 }
 
 static int default_start_script(const char *script __unused,
tools/perf/util/trace-event-parse.c +10 -39

111 lines not on this page · raw message

tools/perf/util/trace-event.h +1 -2
index 5f7b513..b04da57 100644
@@ -177,8 +177,7 @@ void print_printk(void);
 
 int parse_ftrace_file(char *buf, unsigned long size);
 int parse_event_file(char *buf, unsigned long size, char *sys);
-void print_event(int cpu, void *data, int size, unsigned long long nsecs,
-		  char *comm);
+void print_trace_event(int cpu, void *data, int size);
 
 extern int file_bigendian;
 extern int host_bigendian;
Signature · 1 line
1.7.4
#6 lore raw

Re: [PATCH 3/6] perf script: move printing of 'common' data from print_event and rename

Quoted 7 lines · David Ahern

This change does impact output: latency data is trace specific and is now printed after the common data - comm, tid, cpu, time and event name.

---
 tools/perf/builtin-script.c         |   38 ++++++++++++++++++++++-----
 tools/perf/util/trace-event-parse.c |   49 +++++++---------------------------

I was hoping after the next merge window to start making a common library for parsing events. This way things like powertop and timechart or anything that uses the perf interface does not need to write its own parsing of events, or expect the event formats to be hardcoded.

The trace-event-parse.c was taking from trace-cmd's parse-events.c code and hopefully the two can merge again. The parse-events.c code in trace-cmd has gone through several iterations that has made it much more robust and flexible. I purposely kept it as a separate libarary not dependent on trace-cmd so that it could be used by other utilities like perf.

Quoted 62 lines
 tools/perf/util/trace-event.h       |    3 +-
 3 files changed, 42 insertions(+), 48 deletions(-)
tools/perf/builtin-script.c +31 -7
index b2bdd55..0a79da2 100644
@@ -20,18 +20,42 @@ static u64			last_timestamp;
 static u64			nr_unordered;
 extern const struct option	record_options[];
 
+static void print_sample_start(struct perf_sample *sample,
+			       struct thread *thread)
+{
+	int type;
+	struct event *event;
+	const char *evname = NULL;
+	unsigned long secs;
+	unsigned long usecs;
+	unsigned long long nsecs = sample->time;
+
+	if (latency_format)
+		printf("%8.8s-%-5d %3d", thread->comm, sample->tid, sample->cpu);
+	else
+		printf("%16s-%-5d [%03d]", thread->comm, sample->tid, sample->cpu);
+
+	secs = nsecs / NSECS_PER_SEC;
+	nsecs -= secs * NSECS_PER_SEC;
+	usecs = nsecs / NSECS_PER_USEC;
+	printf(" %5lu.%06lu: ", secs, usecs);
+
+	type = trace_parse_common_type(sample->raw_data);
+	event = trace_find_event(type);
+	if (event)
+		evname = event->name;
+
+	printf("%s: ", evname ? evname : "(unknown)");
+}
+
 static void process_event(union perf_event *event __unused,
 			  struct perf_sample *sample,
 			  struct perf_session *session __unused,
 			  struct thread *thread)
 {
-	/*
-	 * FIXME: better resolve from pid from the struct trace_entry
-	 * field, although it should be the same than this perf
-	 * event pid
-	 */
-	print_event(sample->cpu, sample->raw_data, sample->raw_size,
-		    sample->time, thread->comm);
+	print_sample_start(sample, thread);
+	print_trace_event(sample->cpu, sample->raw_data, sample->raw_size);
+	printf("\n");
 }
 
 static int default_start_script(const char *script __unused,
tools/perf/util/trace-event-parse.c +0 -0
index dd5f058..0a7ed5b 100644

tools/perf/util/trace-event-parse.c static void print_lat_fmt(void *data, int size __unused) · line 2648

Quoted 8 lines
tools/perf/util/trace-event-parse.c +2 -2
@@ -2643,9 +2643,9 @@ static void print_lat_fmt(void *data, int size __unused)
 		printf(".");
 
 	if (lock_depth < 0)
-		printf(".");
+		printf(". ");
 	else
-		printf("%d", lock_depth);
+		printf("%d ", lock_depth);

For example, I'm removing the field lock_depth, as that was added by Frederic as a temporary field to help with the removal of the BKL. Currently this code is unused by perf, but if it is in the future, it must be able to handle not having this field. In fact, I'm thinking of modifying other "common" fields to help improve tracing performance.

If we could have a common library for all tools that need to parse events, then this code can be updated in a single place. Which also brings another point. Do we want to move the events out of debugfs. And if we do, I would love to change the way the event format is. I consider the format in debugfs as it stands a true ABI, but the content that the format shows is not.

-- Steve

#7 lore raw

Re: [PATCH 3/6] perf script: move printing of 'common' data from print_event and rename

Em Thu, Mar 10, 2011 at 10:20:53AM -0500, Steven Rostedt escreveu:

Quoted 14 lines · David Ahern
Quoted 7 lines

This change does impact output: latency data is trace specific and is now printed after the common data - comm, tid, cpu, time and event name.

 tools/perf/builtin-script.c         |   38 ++++++++++++++++++++++-----
 tools/perf/util/trace-event-parse.c |   49 +++++++---------------------------

I was hoping after the next merge window to start making a common library for parsing events. This way things like powertop and timechart or anything that uses the perf interface does not need to write its own parsing of events, or expect the event formats to be hardcoded.

Quoted 6 lines

The trace-event-parse.c was taking from trace-cmd's parse-events.c code and hopefully the two can merge again. The parse-events.c code in trace-cmd has gone through several iterations that has made it much more robust and flexible. I purposely kept it as a separate libarary not dependent on trace-cmd so that it could be used by other utilities like perf.

David is kinda new to this perf/ftrace/trace-cmd/etc soap opera, and he has been patient to go thru the motions with Peter, Thomas, Frédéric and me, going from doing what he wants in 'perf report' to 'perf script', etc.

We're almost to the point where his feature is implemented in a way Frédéric, the one most actively reviewing his work, is satisfied, right Frédéric?

I think the merge with the libraries you mention is something that is not a precondition to merging David's work.

And his work is at least moving things in the trace parts of tools/, that was so far dormant.

- Arnaldo

#8 lore raw

Re: [PATCH 3/6] perf script: move printing of 'common' data from print_event and rename

Quoted 15 lines · Arnaldo Carvalho de Melo

Em Thu, Mar 10, 2011 at 10:20:53AM -0500, Steven Rostedt escreveu:

Quoted 14 lines · David Ahern
Quoted 7 lines

This change does impact output: latency data is trace specific and is now printed after the common data - comm, tid, cpu, time and event name.

 tools/perf/builtin-script.c         |   38 ++++++++++++++++++++++-----
 tools/perf/util/trace-event-parse.c |   49 +++++++---------------------------

I was hoping after the next merge window to start making a common library for parsing events. This way things like powertop and timechart or anything that uses the perf interface does not need to write its own parsing of events, or expect the event formats to be hardcoded.

Quoted 8 lines
Quoted 6 lines

The trace-event-parse.c was taking from trace-cmd's parse-events.c code and hopefully the two can merge again. The parse-events.c code in trace-cmd has gone through several iterations that has made it much more robust and flexible. I purposely kept it as a separate libarary not dependent on trace-cmd so that it could be used by other utilities like perf.

David is kinda new to this perf/ftrace/trace-cmd/etc soap opera, and he

Lucky him ;)

Quoted 7 lines

has been patient to go thru the motions with Peter, Thomas, Frédéric and me, going from doing what he wants in 'perf report' to 'perf script', etc.

We're almost to the point where his feature is implemented in a way Frédéric, the one most actively reviewing his work, is satisfied, right Frédéric?

You must have one of those keyboards where it is easy to make that é

Quoted 6 lines

I think the merge with the libraries you mention is something that is not a precondition to merging David's work.

And his work is at least moving things in the trace parts of tools/, that was so far dormant.

Note, I'm not saying that his work should be put on hold. I actually want to start it up again. Maybe I worded this response wrong. It was more about bringing David up to speed on what I want to do next than saying not to do this work.

Thanks,

-- Steve

#9 lore raw

Re: [PATCH 3/6] perf script: move printing of 'common' data from print_event and rename

Em Thu, Mar 10, 2011 at 11:05:35AM -0500, Steven Rostedt escreveu:

Quoted 4 lines · Arnaldo Carvalho de Melo
Quoted 1 line

David is kinda new to this perf/ftrace/trace-cmd/etc soap opera, and he

Lucky him ;)

:-)

Quoted 9 lines
Quoted 7 lines

has been patient to go thru the motions with Peter, Thomas, Frédéric and me, going from doing what he wants in 'perf report' to 'perf script', etc.

We're almost to the point where his feature is implemented in a way Frédéric, the one most actively reviewing his work, is satisfied, right Frédéric?

You must have one of those keyboards where it is easy to make that é

gnome makes this all mostly easy, and my native language, as Frédéric's, have those pesky characters :)

Quoted 10 lines
Quoted 5 lines

I think the merge with the libraries you mention is something that is not a precondition to merging David's work.

And his work is at least moving things in the trace parts of tools/, that was so far dormant.

Note, I'm not saying that his work should be put on hold. I actually want to start it up again. Maybe I worded this response wrong. It was more about bringing David up to speed on what I want to do next than saying not to do this work.

Right, I just wanted to make sure he doesn't spill his coffee with what could seem like yet another requirement to work on infrastructure to get his legitimate feature implementation merged :-)

- Arnaldo

#10 lore raw

Re: [PATCH 3/6] perf script: move printing of 'common' data from print_event and rename

Quoted 6 lines · Arnaldo Carvalho de Melo
Quoted 6 lines
Quoted 5 lines

I think the merge with the libraries you mention is something that is not a precondition to merging David's work.

And his work is at least moving things in the trace parts of tools/, that was so far dormant.

Quoted 8 lines
Quoted 4 lines

Note, I'm not saying that his work should be put on hold. I actually want to start it up again. Maybe I worded this response wrong. It was more about bringing David up to speed on what I want to do next than saying not to do this work.

Right, I just wanted to make sure he doesn't spill his coffee with what could seem like yet another requirement to work on infrastructure to get his legitimate feature implementation merged :-)

I appreciate the clarification. Luckily, no coffee in hand.

I need to get the time-of-day strings done next, and someone else is pushing the reverse callchain display (another local change I wanted to get upstream). I could take a look at other requests - like common code
- as time allows.

David

Quoted 2 lines

- Arnaldo

#11 lore raw

Re: [PATCH 3/6] perf script: move printing of 'common' data from print_event and rename

Quoted 17 lines · David Ahern
Quoted 6 lines · Arnaldo Carvalho de Melo
Quoted 6 lines
Quoted 5 lines

I think the merge with the libraries you mention is something that is not a precondition to merging David's work.

And his work is at least moving things in the trace parts of tools/, that was so far dormant.

Quoted 8 lines
Quoted 4 lines

Note, I'm not saying that his work should be put on hold. I actually want to start it up again. Maybe I worded this response wrong. It was more about bringing David up to speed on what I want to do next than saying not to do this work.

Right, I just wanted to make sure he doesn't spill his coffee with what could seem like yet another requirement to work on infrastructure to get his legitimate feature implementation merged :-)

Quoted 6 lines

I appreciate the clarification. Luckily, no coffee in hand.

I need to get the time-of-day strings done next, and someone else is pushing the reverse callchain display (another local change I wanted to get upstream). I could take a look at other requests - like common code
- as time allows.

Right, we could start looking at making the common code on top of your changes. I don't want to hinder progress for asking for too much.

Thanks,

-- Steve

#12 lore raw

Re: [PATCH 3/6] perf script: move printing of 'common' data from print_event and rename

In reply to Arnaldo Carvalho de Melo
Quoted 22 lines · Arnaldo Carvalho de Melo

Em Thu, Mar 10, 2011 at 10:20:53AM -0500, Steven Rostedt escreveu:

Quoted 14 lines · David Ahern
Quoted 7 lines

This change does impact output: latency data is trace specific and is now printed after the common data - comm, tid, cpu, time and event name.

 tools/perf/builtin-script.c         |   38 ++++++++++++++++++++++-----
 tools/perf/util/trace-event-parse.c |   49 +++++++---------------------------

I was hoping after the next merge window to start making a common library for parsing events. This way things like powertop and timechart or anything that uses the perf interface does not need to write its own parsing of events, or expect the event formats to be hardcoded.

Quoted 6 lines

The trace-event-parse.c was taking from trace-cmd's parse-events.c code and hopefully the two can merge again. The parse-events.c code in trace-cmd has gone through several iterations that has made it much more robust and flexible. I purposely kept it as a separate libarary not dependent on trace-cmd so that it could be used by other utilities like perf.

Quoted 8 lines

David is kinda new to this perf/ftrace/trace-cmd/etc soap opera, and he has been patient to go thru the motions with Peter, Thomas, Frédéric and me, going from doing what he wants in 'perf report' to 'perf script', etc.

We're almost to the point where his feature is implemented in a way Frédéric, the one most actively reviewing his work, is satisfied, right Frédéric?

Yeah, nice work! Thanks David!

#13 lore raw

[tip:perf/urgent] perf script: Move printing of 'common' data from print_event and rename

In reply to David Ahern
Commit-ID:  c70c94b47405d2c94df19c16273daf1f5fb9193d
Gitweb:     http://git.kernel.org/tip/c70c94b47405d2c94df19c16273daf1f5fb9193d
Author:     David Ahern <[email protected]>
AuthorDate: Wed, 9 Mar 2011 22:23:25 -0700
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 14 Mar 2011 17:05:55 -0300

perf script: Move printing of 'common' data from print_event and rename

This change does impact output: latency data is trace specific and is now printed after the common data - comm, tid, cpu, time and event name.

Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>

LKML-Reference: <[email protected]>

---
 tools/perf/builtin-script.c         |   38 ++++++++++++++++++++++-----
 tools/perf/util/trace-event-parse.c |   49 +++++++---------------------------
 tools/perf/util/trace-event.h       |    3 +-
 3 files changed, 42 insertions(+), 48 deletions(-)
tools/perf/builtin-script.c +31 -7
index b2bdd55..0a79da2 100644
@@ -20,18 +20,42 @@ static u64			last_timestamp;
 static u64			nr_unordered;
 extern const struct option	record_options[];
 
+static void print_sample_start(struct perf_sample *sample,
+			       struct thread *thread)
+{
+	int type;
+	struct event *event;
+	const char *evname = NULL;
+	unsigned long secs;
+	unsigned long usecs;
+	unsigned long long nsecs = sample->time;
+
+	if (latency_format)
+		printf("%8.8s-%-5d %3d", thread->comm, sample->tid, sample->cpu);
+	else
+		printf("%16s-%-5d [%03d]", thread->comm, sample->tid, sample->cpu);
+
+	secs = nsecs / NSECS_PER_SEC;
+	nsecs -= secs * NSECS_PER_SEC;
+	usecs = nsecs / NSECS_PER_USEC;
+	printf(" %5lu.%06lu: ", secs, usecs);
+
+	type = trace_parse_common_type(sample->raw_data);
+	event = trace_find_event(type);
+	if (event)
+		evname = event->name;
+
+	printf("%s: ", evname ? evname : "(unknown)");
+}
+
 static void process_event(union perf_event *event __unused,
 			  struct perf_sample *sample,
 			  struct perf_session *session __unused,
 			  struct thread *thread)
 {
-	/*
-	 * FIXME: better resolve from pid from the struct trace_entry
-	 * field, although it should be the same than this perf
-	 * event pid
-	 */
-	print_event(sample->cpu, sample->raw_data, sample->raw_size,
-		    sample->time, thread->comm);
+	print_sample_start(sample, thread);
+	print_trace_event(sample->cpu, sample->raw_data, sample->raw_size);
+	printf("\n");
 }
 
 static int default_start_script(const char *script __unused,
tools/perf/util/trace-event-parse.c +10 -39

111 lines not on this page · raw message

tools/perf/util/trace-event.h +1 -2
index 5f7b513..b04da57 100644
@@ -177,8 +177,7 @@ void print_printk(void);
 
 int parse_ftrace_file(char *buf, unsigned long size);
 int parse_event_file(char *buf, unsigned long size, char *sys);
-void print_event(int cpu, void *data, int size, unsigned long long nsecs,
-		  char *comm);
+void print_trace_event(int cpu, void *data, int size);
 
 extern int file_bigendian;
 extern int host_bigendian;
#14 lore raw

PATCH v4 4/6 perf script: support custom field selection for output

In reply to David Ahern

Allow a user to select which fields to print to stdout for event data. Options include comm (command name), tid (thread id), pid (process id), time (perf timestamp), cpu, event (for event name), and trace (for trace data).

Default is set to maintain compatibility with current output; this feature does alter output format slightly -- no '-' between command and pid/tid.

Thanks to Frederic Weisbecker for detailed suggestions on this approach.

Examples (output compressed)

1. trace, default format

perf record -ga -e sched:sched_switch
perf script

swapper 0 [000] 537.037184: sched_switch: prev_comm=swapper prev_pid=0...
sshd 1675 [000] 537.037309: sched_switch: prev_comm=sshd prev_pid=1675...
netstat 1692 [001] 537.038664: sched_switch: prev_comm=netstat prev_pid=1692...

2. trace, custom format

perf record -ga -e sched:sched_switch
perf script -f comm,pid,time,trace <--- omitting cpu and event name

swapper 0 537.037184: prev_comm=swapper prev_pid=0 prev_prio=120 ...
sshd 1675 537.037309: prev_comm=sshd prev_pid=1675 prev_prio=120 ...
netstat 1692 537.038664: prev_comm=netstat prev_pid=1692 prev_prio=120 ...

---
 tools/perf/Documentation/perf-script.txt |    5 +
 tools/perf/builtin-script.c              |  141 ++++++++++++++++++++++++++----
 2 files changed, 130 insertions(+), 16 deletions(-)
tools/perf/Documentation/perf-script.txt +5 -0
index 29ad942..b73cf58 100644
@@ -112,6 +112,11 @@ OPTIONS
 --debug-mode::
         Do various checks like samples ordering and lost events.
 
+-f::
+--fields
+        Comma separated list of fields to print. Options are:
+        comm, tid, pid, time, cpu, event, trace
+
 SEE ALSO
 --------
 linkperf:perf-record[1], linkperf:perf-script-perl[1],
tools/perf/builtin-script.c +125 -16

182 lines not on this page · raw message

Signature · 1 line
1.7.4
#15 lore raw

[tip:perf/urgent] perf script: Support custom field selection for output

Commit-ID:  745f43e3433a7939bd9c351c8106e0c1db2044c6
Gitweb:     http://git.kernel.org/tip/745f43e3433a7939bd9c351c8106e0c1db2044c6
Author:     David Ahern <[email protected]>
AuthorDate: Wed, 9 Mar 2011 22:23:26 -0700
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 14 Mar 2011 17:06:16 -0300

perf script: Support custom field selection for output

Allow a user to select which fields to print to stdout for event data. Options include comm (command name), tid (thread id), pid (process id), time (perf timestamp), cpu, event (for event name), and trace (for trace data).

Default is set to maintain compatibility with current output; this feature does alter output format slightly -- no '-' between command and pid/tid.

Thanks to Frederic Weisbecker for detailed suggestions on this approach.

Examples (output compressed)

1. trace, default format

perf record -ga -e sched:sched_switch
perf script

swapper 0 [000] 537.037184: sched_switch: prev_comm=swapper prev_pid=0...
sshd 1675 [000] 537.037309: sched_switch: prev_comm=sshd prev_pid=1675...
netstat 1692 [001] 537.038664: sched_switch: prev_comm=netstat prev_pid=1692...

2. trace, custom format

perf record -ga -e sched:sched_switch
perf script -f comm,pid,time,trace <--- omitting cpu and event name

swapper 0 537.037184: prev_comm=swapper prev_pid=0 prev_prio=120 ...
sshd 1675 537.037309: prev_comm=sshd prev_pid=1675 prev_prio=120 ...
netstat 1692 537.038664: prev_comm=netstat prev_pid=1692 prev_prio=120 ...

Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>

LKML-Reference: <[email protected]>

---
 tools/perf/Documentation/perf-script.txt |    5 +
 tools/perf/builtin-script.c              |  141 ++++++++++++++++++++++++++----
 2 files changed, 130 insertions(+), 16 deletions(-)
tools/perf/Documentation/perf-script.txt +5 -0
index 29ad942..b73cf58 100644
@@ -112,6 +112,11 @@ OPTIONS
 --debug-mode::
         Do various checks like samples ordering and lost events.
 
+-f::
+--fields
+        Comma separated list of fields to print. Options are:
+        comm, tid, pid, time, cpu, event, trace
+
 SEE ALSO
 --------
 linkperf:perf-record[1], linkperf:perf-script-perl[1],
tools/perf/builtin-script.c +125 -16

182 lines not on this page · raw message

#16 lore raw

PATCH v4 5/6 perf script: add support for dumping symbols

In reply to David Ahern

Add option to dump symbols found in events.

e.g., perf script -f comm,pid,tid,time,trace,sym

swapper 0/0 537.037184: prev_comm=swapper prev_pid=0 prev_prio=120...

        ffffffff81030350 perf_trace_sched_switch ([kernel.kallsyms])
        ffffffff81382ac5 schedule ([kernel.kallsyms])
        ffffffff8100134a cpu_idle ([kernel.kallsyms])
        ffffffff81370b39 rest_init ([kernel.kallsyms])
        ffffffff81696c23 start_kernel ([kernel.kallsyms].init.text)
        ffffffff816962af x86_64_start_reservations ([kernel.kallsyms].init.text)
        ffffffff816963b9 x86_64_start_kernel ([kernel.kallsyms].init.text)

sshd 1675/1675 537.037309: prev_comm=sshd prev_pid=1675 prev_prio=120...
ffffffff81030350 perf_trace_sched_switch ([kernel.kallsyms]) ffffffff81382ac5 schedule ([kernel.kallsyms]) ffffffff813837aa schedule_hrtimeout_range_clock ([kernel.kallsyms]) ffffffff81383886 schedule_hrtimeout_range ([kernel.kallsyms]) ffffffff8110c4f9 poll_schedule_timeout ([kernel.kallsyms]) ffffffff8110cd20 do_select ([kernel.kallsyms]) ffffffff8110ced8 core_sys_select ([kernel.kallsyms]) ffffffff8110d00d sys_select ([kernel.kallsyms]) ffffffff81002bc2 system_call ([kernel.kallsyms])
7f1647e56e93 __GI_select (/lib64/libc-2.12.90.so)

netstat 1692/1692 537.038664: prev_comm=netstat prev_pid=1692 prev_prio=...
ffffffff81030350 perf_trace_sched_switch ([kernel.kallsyms]) ffffffff81382ac5 schedule ([kernel.kallsyms]) ffffffff81002c3a sysret_careful ([kernel.kallsyms])
7f7a6cd1b210 __GI___libc_read (/lib64/libc-2.12.90.so)

---
 tools/perf/Documentation/perf-script.txt |   16 +++++++-
 tools/perf/builtin-script.c              |   31 +++++++++++++++-
 tools/perf/util/session.c                |   61 ++++++++++++++++++++++++++++++
 tools/perf/util/session.h                |    4 ++
 4 files changed, 110 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-script.txt +15 -1
index b73cf58..c64118a 100644
@@ -115,7 +115,21 @@ OPTIONS
 -f::
 --fields
         Comma separated list of fields to print. Options are:
-        comm, tid, pid, time, cpu, event, trace
+        comm, tid, pid, time, cpu, event, trace, sym
+
+-k::
+--vmlinux=<file>::
+        vmlinux pathname
+
+--kallsyms=<file>::
+        kallsyms pathname
+
+--symfs=<directory>::
+        Look for files with symbols relative to this directory.
+
+-G::
+--hide-call-graph::
+        When printing symbols do not display call chain.
 
 SEE ALSO
 --------
tools/perf/builtin-script.c +30 -1
index c046e6e..b45b09c 100644
@@ -19,6 +19,7 @@ static bool			debug_mode;
 static u64			last_timestamp;
 static u64			nr_unordered;
 extern const struct option	record_options[];
+static bool			no_callchain;
 
 enum perf_output_field {
 	PERF_OUTPUT_COMM            = 1U << 0,
@@ -28,6 +29,7 @@ enum perf_output_field {
 	PERF_OUTPUT_CPU             = 1U << 4,
 	PERF_OUTPUT_EVNAME          = 1U << 5,
 	PERF_OUTPUT_TRACE           = 1U << 6,
+	PERF_OUTPUT_SYM             = 1U << 7,
 };
 
 struct output_option {
@@ -41,6 +43,7 @@ struct output_option {
 	{.str = "cpu",   .field = PERF_OUTPUT_CPU},
 	{.str = "event", .field = PERF_OUTPUT_EVNAME},
 	{.str = "trace", .field = PERF_OUTPUT_TRACE},
+	{.str = "sym",   .field = PERF_OUTPUT_SYM},
 };
 
 /* default set to maintain compatibility with current format */
@@ -65,6 +68,8 @@ static void print_sample_start(struct perf_sample *sample,
 	if (PRINT_FIELD(COMM)) {
 		if (latency_format)
 			printf("%8.8s ", thread->comm);
+		else if (PRINT_FIELD(SYM) && symbol_conf.use_callchain)
+			printf("%s ", thread->comm);
 		else
 			printf("%16s ", thread->comm);
 	}
@@ -112,6 +117,14 @@ static void process_event(union perf_event *event __unused,
 		print_trace_event(sample->cpu, sample->raw_data,
 				  sample->raw_size);
 
+	if (PRINT_FIELD(SYM)) {
+		if (!symbol_conf.use_callchain)
+			printf(" ");
+		else
+			printf("\n");
+		perf_session__print_symbols(event, sample, session);
+	}
+
 	printf("\n");
 }
 
@@ -190,7 +203,10 @@ static int process_sample_event(union perf_event *event,
 
 static struct perf_event_ops event_ops = {
 	.sample		 = process_sample_event,
+	.mmap		 = perf_event__process_mmap,
 	.comm		 = perf_event__process_comm,
+	.exit		 = perf_event__process_task,
+	.fork		 = perf_event__process_task,
 	.attr		 = perf_event__process_attr,
 	.event_type	 = perf_event__process_event_type,
 	.tracing_data	 = perf_event__process_tracing_data,
@@ -722,8 +738,16 @@ static const struct option options[] = {
 		    "input file name"),
 	OPT_BOOLEAN('d', "debug-mode", &debug_mode,
 		   "do various checks like samples ordering and lost events"),
+	OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
+		   "file", "vmlinux pathname"),
+	OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
+		   "file", "kallsyms pathname"),
+	OPT_BOOLEAN('G', "hide-call-graph", &no_callchain,
+		    "When printing symbols do not display call chain"),
+	OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
+		    "Look for files with symbols relative to this directory"),
 	OPT_CALLBACK('f', "fields", NULL, "str",
-		     "comma separated output fields. Options: comm,tid,pid,time,cpu,event,trace",
+		     "comma separated output fields. Options: comm,tid,pid,time,cpu,event,trace,sym",
 		     parse_output_fields),
 
 	OPT_END()
@@ -905,6 +929,11 @@ int cmd_script(int argc, const char **argv, const char *prefix __used)
 	if (session == NULL)
 		return -ENOMEM;
 
+	if (!no_callchain && (session->sample_type & PERF_SAMPLE_CALLCHAIN))
+		symbol_conf.use_callchain = true;
+	else
+		symbol_conf.use_callchain = false;
+
 	if (strcmp(input_name, "-") &&
 	    !perf_session__has_traces(session, "record -R"))
 		return -EINVAL;
tools/perf/util/session.c +61 -0

64 lines not on this page · raw message

tools/perf/util/session.h +4 -0
index 05dd7bc..64369d3 100644
@@ -161,4 +161,8 @@ static inline int perf_session__parse_sample(struct perf_session *session,
 					session->sample_id_all, sample);
 }
 
+void perf_session__print_symbols(union perf_event *event,
+				 struct perf_sample *sample,
+				 struct perf_session *session);
+
 #endif /* __PERF_SESSION_H */
Signature · 1 line
1.7.4
#17 lore raw

[tip:perf/urgent] perf script: Add support for dumping symbols

Commit-ID:  c0230b2bfbd16e42d937c34aed99e5d6493eb5e4
Gitweb:     http://git.kernel.org/tip/c0230b2bfbd16e42d937c34aed99e5d6493eb5e4
Author:     David Ahern <[email protected]>
AuthorDate: Wed, 9 Mar 2011 22:23:27 -0700
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 14 Mar 2011 17:06:50 -0300

perf script: Add support for dumping symbols

Add option to dump symbols found in events.

e.g., perf script -f comm,pid,tid,time,trace,sym

swapper 0/0 537.037184: prev_comm=swapper prev_pid=0 prev_prio=120...

        ffffffff81030350 perf_trace_sched_switch ([kernel.kallsyms])
        ffffffff81382ac5 schedule ([kernel.kallsyms])
        ffffffff8100134a cpu_idle ([kernel.kallsyms])
        ffffffff81370b39 rest_init ([kernel.kallsyms])
        ffffffff81696c23 start_kernel ([kernel.kallsyms].init.text)
        ffffffff816962af x86_64_start_reservations ([kernel.kallsyms].init.text)
        ffffffff816963b9 x86_64_start_kernel ([kernel.kallsyms].init.text)

sshd 1675/1675 537.037309: prev_comm=sshd prev_pid=1675 prev_prio=120...
ffffffff81030350 perf_trace_sched_switch ([kernel.kallsyms]) ffffffff81382ac5 schedule ([kernel.kallsyms]) ffffffff813837aa schedule_hrtimeout_range_clock ([kernel.kallsyms]) ffffffff81383886 schedule_hrtimeout_range ([kernel.kallsyms]) ffffffff8110c4f9 poll_schedule_timeout ([kernel.kallsyms]) ffffffff8110cd20 do_select ([kernel.kallsyms]) ffffffff8110ced8 core_sys_select ([kernel.kallsyms]) ffffffff8110d00d sys_select ([kernel.kallsyms]) ffffffff81002bc2 system_call ([kernel.kallsyms])
7f1647e56e93 __GI_select (/lib64/libc-2.12.90.so)

netstat 1692/1692 537.038664: prev_comm=netstat prev_pid=1692 prev_prio=...
ffffffff81030350 perf_trace_sched_switch ([kernel.kallsyms]) ffffffff81382ac5 schedule ([kernel.kallsyms]) ffffffff81002c3a sysret_careful ([kernel.kallsyms])
7f7a6cd1b210 __GI___libc_read (/lib64/libc-2.12.90.so)

Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>

LKML-Reference: <[email protected]>

---
 tools/perf/Documentation/perf-script.txt |   16 +++++++-
 tools/perf/builtin-script.c              |   31 +++++++++++++++-
 tools/perf/util/session.c                |   61 ++++++++++++++++++++++++++++++
 tools/perf/util/session.h                |    4 ++
 4 files changed, 110 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-script.txt +15 -1
index b73cf58..c64118a 100644
@@ -115,7 +115,21 @@ OPTIONS
 -f::
 --fields
         Comma separated list of fields to print. Options are:
-        comm, tid, pid, time, cpu, event, trace
+        comm, tid, pid, time, cpu, event, trace, sym
+
+-k::
+--vmlinux=<file>::
+        vmlinux pathname
+
+--kallsyms=<file>::
+        kallsyms pathname
+
+--symfs=<directory>::
+        Look for files with symbols relative to this directory.
+
+-G::
+--hide-call-graph::
+        When printing symbols do not display call chain.
 
 SEE ALSO
 --------
tools/perf/builtin-script.c +30 -1
index c046e6e..b45b09c 100644
@@ -19,6 +19,7 @@ static bool			debug_mode;
 static u64			last_timestamp;
 static u64			nr_unordered;
 extern const struct option	record_options[];
+static bool			no_callchain;
 
 enum perf_output_field {
 	PERF_OUTPUT_COMM            = 1U << 0,
@@ -28,6 +29,7 @@ enum perf_output_field {
 	PERF_OUTPUT_CPU             = 1U << 4,
 	PERF_OUTPUT_EVNAME          = 1U << 5,
 	PERF_OUTPUT_TRACE           = 1U << 6,
+	PERF_OUTPUT_SYM             = 1U << 7,
 };
 
 struct output_option {
@@ -41,6 +43,7 @@ struct output_option {
 	{.str = "cpu",   .field = PERF_OUTPUT_CPU},
 	{.str = "event", .field = PERF_OUTPUT_EVNAME},
 	{.str = "trace", .field = PERF_OUTPUT_TRACE},
+	{.str = "sym",   .field = PERF_OUTPUT_SYM},
 };
 
 /* default set to maintain compatibility with current format */
@@ -65,6 +68,8 @@ static void print_sample_start(struct perf_sample *sample,
 	if (PRINT_FIELD(COMM)) {
 		if (latency_format)
 			printf("%8.8s ", thread->comm);
+		else if (PRINT_FIELD(SYM) && symbol_conf.use_callchain)
+			printf("%s ", thread->comm);
 		else
 			printf("%16s ", thread->comm);
 	}
@@ -112,6 +117,14 @@ static void process_event(union perf_event *event __unused,
 		print_trace_event(sample->cpu, sample->raw_data,
 				  sample->raw_size);
 
+	if (PRINT_FIELD(SYM)) {
+		if (!symbol_conf.use_callchain)
+			printf(" ");
+		else
+			printf("\n");
+		perf_session__print_symbols(event, sample, session);
+	}
+
 	printf("\n");
 }
 
@@ -190,7 +203,10 @@ static int process_sample_event(union perf_event *event,
 
 static struct perf_event_ops event_ops = {
 	.sample		 = process_sample_event,
+	.mmap		 = perf_event__process_mmap,
 	.comm		 = perf_event__process_comm,
+	.exit		 = perf_event__process_task,
+	.fork		 = perf_event__process_task,
 	.attr		 = perf_event__process_attr,
 	.event_type	 = perf_event__process_event_type,
 	.tracing_data	 = perf_event__process_tracing_data,
@@ -722,8 +738,16 @@ static const struct option options[] = {
 		    "input file name"),
 	OPT_BOOLEAN('d', "debug-mode", &debug_mode,
 		   "do various checks like samples ordering and lost events"),
+	OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
+		   "file", "vmlinux pathname"),
+	OPT_STRING(0, "kallsyms", &symbol_conf.kallsyms_name,
+		   "file", "kallsyms pathname"),
+	OPT_BOOLEAN('G', "hide-call-graph", &no_callchain,
+		    "When printing symbols do not display call chain"),
+	OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
+		    "Look for files with symbols relative to this directory"),
 	OPT_CALLBACK('f', "fields", NULL, "str",
-		     "comma separated output fields. Options: comm,tid,pid,time,cpu,event,trace",
+		     "comma separated output fields. Options: comm,tid,pid,time,cpu,event,trace,sym",
 		     parse_output_fields),
 
 	OPT_END()
@@ -905,6 +929,11 @@ int cmd_script(int argc, const char **argv, const char *prefix __used)
 	if (session == NULL)
 		return -ENOMEM;
 
+	if (!no_callchain && (session->sample_type & PERF_SAMPLE_CALLCHAIN))
+		symbol_conf.use_callchain = true;
+	else
+		symbol_conf.use_callchain = false;
+
 	if (strcmp(input_name, "-") &&
 	    !perf_session__has_traces(session, "record -R"))
 		return -EINVAL;
tools/perf/util/session.c +61 -0

64 lines not on this page · raw message

tools/perf/util/session.h +4 -0
index b5b148b..0b3c9af 100644
@@ -159,4 +159,8 @@ static inline int perf_session__parse_sample(struct perf_session *session,
 					session->sample_id_all, sample);
 }
 
+void perf_session__print_symbols(union perf_event *event,
+				 struct perf_sample *sample,
+				 struct perf_session *session);
+
 #endif /* __PERF_SESSION_H */
#18 lore raw

PATCH v4 6/6 perf script: add support for H/W and S/W events

In reply to David Ahern

Custom fields set for each type by prepending field argument with type. For file with multiple event types (e.g., trace and S/W) display of an event type suppressed by setting output fields to "".

e.g.,
perf record -ga -e sched:sched_switch -e cpu-clock -c 10000000 -R -- sleep 1 perf script

openssl 11496 [000] 9711.807107: cpu-clock-msecs:

        ffffffff810c22dc arch_local_irq_restore ([kernel.kallsyms])
        ffffffff810c518c __alloc_pages_nodemask ([kernel.kallsyms])
        ffffffff810297b2 pte_alloc_one ([kernel.kallsyms])
        ffffffff810d8b98 __pte_alloc ([kernel.kallsyms])
        ffffffff810daf07 handle_mm_fault ([kernel.kallsyms])
        ffffffff8138763a do_page_fault ([kernel.kallsyms])
        ffffffff81384a65 page_fault ([kernel.kallsyms])
            7f6130507d70 asn1_check_tlen (/lib64/libcrypto.so.1.0.0c)
                       0  ()

         openssl 11496 [000]  9711.808042: sched_switch: prev_comm=openssl ...
     kworker/0:0     4 [000]  9711.808067: sched_switch: prev_comm=kworker/...
         swapper     0 [001]  9711.808090: sched_switch: prev_comm=kworker/...
            sshd 11451 [001]  9711.808185: sched_switch: prev_comm=sshd pre...
swapper     0 [001]  9711.816155: cpu-clock-msecs:
        ffffffff81023609 native_safe_halt ([kernel.kallsyms])
        ffffffff8100132a cpu_idle ([kernel.kallsyms])
        ffffffff8137cf9b start_secondary ([kernel.kallsyms])

openssl 11496 [000] 9711.817104: cpu-clock-msecs:

            7f61304ad723 AES_cbc_encrypt (/lib64/libcrypto.so.1.0.0c)
            7fff3402f950  ()
        12f0debc9a785634  ()

swapper 0 [001] 9711.826155: cpu-clock-msecs:

        ffffffff81023609 native_safe_halt ([kernel.kallsyms])
        ffffffff8100132a cpu_idle ([kernel.kallsyms])
        ffffffff8137cf9b start_secondary ([kernel.kallsyms])

To suppress trace events within the file and use default output for S/W events:
perf script -f trace:

or to suppress S/W events and do default display for trace events:
perf script -f sw:

Custom field selections:
perf script -f sw:comm,tid,time -f trace:time,trace

         openssl 11496  9711.797162:
         swapper     0  9711.807071:
         openssl 11496  9711.807107:
 9711.808042: prev_comm=openssl prev_pid=11496 prev_prio=120 prev_state=R ...
 9711.808067: prev_comm=kworker/0:0 prev_pid=4 prev_prio=120 prev_state=S ...
 9711.808090: prev_comm=kworker/0:0 prev_pid=0 prev_prio=120 prev_state=R ...
 9711.808185: prev_comm=sshd prev_pid=11451 prev_prio=120 prev_state=S ==>...
         swapper     0  9711.816155:
         openssl 11496  9711.817104:
         swapper     0  9711.826155:
---
 tools/perf/Documentation/perf-script.txt |    5 +-
 tools/perf/builtin-script.c              |  157 +++++++++++++++++++++++-------
 tools/perf/util/parse-events.c           |   22 ++++
 tools/perf/util/parse-events.h           |    1 +
 4 files changed, 148 insertions(+), 37 deletions(-)
tools/perf/Documentation/perf-script.txt +4 -1
index c64118a..66f040b 100644
@@ -115,7 +115,10 @@ OPTIONS
 -f::
 --fields
         Comma separated list of fields to print. Options are:
-        comm, tid, pid, time, cpu, event, trace, sym
+        comm, tid, pid, time, cpu, event, trace, sym. Field
+        list must be prepended with the type, trace, sw or hw,
+        to indicate to which event type the field list applies.
+        e.g., -f sw:comm,tid,time,sym  and -f trace:time,cpu,trace
 
 -k::
 --vmlinux=<file>::
tools/perf/builtin-script.c +121 -36

236 lines not on this page · raw message

tools/perf/util/parse-events.c +22 -0
index 54a7e26..952b4ae 100644
@@ -263,6 +263,28 @@ static char *event_cache_name(u8 cache_type, u8 cache_op, u8 cache_result)
 	return name;
 }
 
+const char *event_type(int type)
+{
+	switch (type) {
+	case PERF_TYPE_HARDWARE:
+		return "hardware";
+
+	case PERF_TYPE_SOFTWARE:
+		return "software";
+
+	case PERF_TYPE_TRACEPOINT:
+		return "tracepoint";
+
+	case PERF_TYPE_HW_CACHE:
+		return "hardware-cache";
+
+	default:
+		break;
+	}
+
+	return "unknown";
+}
+
 const char *event_name(struct perf_evsel *evsel)
 {
 	u64 config = evsel->attr.config;
tools/perf/util/parse-events.h +1 -0
index 212f88e..746d3fc 100644
@@ -20,6 +20,7 @@ struct tracepoint_path {
 extern struct tracepoint_path *tracepoint_id_to_path(u64 config);
 extern bool have_tracepoints(struct list_head *evlist);
 
+const char *event_type(int type);
 const char *event_name(struct perf_evsel *event);
 extern const char *__event_name(int type, u64 config);
 
Signature · 1 line
1.7.4
#19 lore raw

[tip:perf/urgent] perf script: Add support for H/W and S/W events

Commit-ID:  1424dc96807909438282663079adc7f27c10b4a5
Gitweb:     http://git.kernel.org/tip/1424dc96807909438282663079adc7f27c10b4a5
Author:     David Ahern <[email protected]>
AuthorDate: Wed, 9 Mar 2011 22:23:28 -0700
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 14 Mar 2011 17:07:20 -0300

perf script: Add support for H/W and S/W events

Custom fields set for each type by prepending field argument with type. For file with multiple event types (e.g., trace and S/W) display of an event type suppressed by setting output fields to "".

e.g.,
perf record -ga -e sched:sched_switch -e cpu-clock -c 10000000 -R -- sleep 1 perf script

openssl 11496 [000] 9711.807107: cpu-clock-msecs:

        ffffffff810c22dc arch_local_irq_restore ([kernel.kallsyms])
        ffffffff810c518c __alloc_pages_nodemask ([kernel.kallsyms])
        ffffffff810297b2 pte_alloc_one ([kernel.kallsyms])
        ffffffff810d8b98 __pte_alloc ([kernel.kallsyms])
        ffffffff810daf07 handle_mm_fault ([kernel.kallsyms])
        ffffffff8138763a do_page_fault ([kernel.kallsyms])
        ffffffff81384a65 page_fault ([kernel.kallsyms])
            7f6130507d70 asn1_check_tlen (/lib64/libcrypto.so.1.0.0c)
                       0  ()

         openssl 11496 [000]  9711.808042: sched_switch: prev_comm=openssl ...
     kworker/0:0     4 [000]  9711.808067: sched_switch: prev_comm=kworker/...
         swapper     0 [001]  9711.808090: sched_switch: prev_comm=kworker/...
            sshd 11451 [001]  9711.808185: sched_switch: prev_comm=sshd pre...
swapper     0 [001]  9711.816155: cpu-clock-msecs:
        ffffffff81023609 native_safe_halt ([kernel.kallsyms])
        ffffffff8100132a cpu_idle ([kernel.kallsyms])
        ffffffff8137cf9b start_secondary ([kernel.kallsyms])

openssl 11496 [000] 9711.817104: cpu-clock-msecs:

            7f61304ad723 AES_cbc_encrypt (/lib64/libcrypto.so.1.0.0c)
            7fff3402f950  ()
        12f0debc9a785634  ()

swapper 0 [001] 9711.826155: cpu-clock-msecs:

        ffffffff81023609 native_safe_halt ([kernel.kallsyms])
        ffffffff8100132a cpu_idle ([kernel.kallsyms])
        ffffffff8137cf9b start_secondary ([kernel.kallsyms])

To suppress trace events within the file and use default output for S/W events:
perf script -f trace:

or to suppress S/W events and do default display for trace events:
perf script -f sw:

Custom field selections:
perf script -f sw:comm,tid,time -f trace:time,trace

         openssl 11496  9711.797162:
         swapper     0  9711.807071:
         openssl 11496  9711.807107:
 9711.808042: prev_comm=openssl prev_pid=11496 prev_prio=120 prev_state=R ...
 9711.808067: prev_comm=kworker/0:0 prev_pid=4 prev_prio=120 prev_state=S ...
 9711.808090: prev_comm=kworker/0:0 prev_pid=0 prev_prio=120 prev_state=R ...
 9711.808185: prev_comm=sshd prev_pid=11451 prev_prio=120 prev_state=S ==>...
         swapper     0  9711.816155:
         openssl 11496  9711.817104:
         swapper     0  9711.826155:
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>

LKML-Reference: <[email protected]>

---
 tools/perf/Documentation/perf-script.txt |    5 +-
 tools/perf/builtin-script.c              |  155 +++++++++++++++++++++++-------
 tools/perf/util/parse-events.c           |   22 ++++
 tools/perf/util/parse-events.h           |    1 +
 4 files changed, 147 insertions(+), 36 deletions(-)
tools/perf/Documentation/perf-script.txt +4 -1
index c64118a..66f040b 100644
@@ -115,7 +115,10 @@ OPTIONS
 -f::
 --fields
         Comma separated list of fields to print. Options are:
-        comm, tid, pid, time, cpu, event, trace, sym
+        comm, tid, pid, time, cpu, event, trace, sym. Field
+        list must be prepended with the type, trace, sw or hw,
+        to indicate to which event type the field list applies.
+        e.g., -f sw:comm,tid,time,sym  and -f trace:time,cpu,trace
 
 -k::
 --vmlinux=<file>::
tools/perf/builtin-script.c +120 -35

234 lines not on this page · raw message

tools/perf/util/parse-events.c +22 -0
index 54a7e26..952b4ae 100644
@@ -263,6 +263,28 @@ static char *event_cache_name(u8 cache_type, u8 cache_op, u8 cache_result)
 	return name;
 }
 
+const char *event_type(int type)
+{
+	switch (type) {
+	case PERF_TYPE_HARDWARE:
+		return "hardware";
+
+	case PERF_TYPE_SOFTWARE:
+		return "software";
+
+	case PERF_TYPE_TRACEPOINT:
+		return "tracepoint";
+
+	case PERF_TYPE_HW_CACHE:
+		return "hardware-cache";
+
+	default:
+		break;
+	}
+
+	return "unknown";
+}
+
 const char *event_name(struct perf_evsel *evsel)
 {
 	u64 config = evsel->attr.config;
tools/perf/util/parse-events.h +1 -0
index 212f88e..746d3fc 100644
@@ -20,6 +20,7 @@ struct tracepoint_path {
 extern struct tracepoint_path *tracepoint_id_to_path(u64 config);
 extern bool have_tracepoints(struct list_head *evlist);
 
+const char *event_type(int type);
 const char *event_name(struct perf_evsel *event);
 extern const char *__event_name(int type, u64 config);