Skip to contentSkip to conversation

perf trace enhancements

PATCH In review David Ahern 2 participants 7 messages Aug 27, 2013 – Aug 28, 2013 perf events

lore
Share & tools
lore
#0 lore raw

cover perf trace enhancements

Arnaldo:

A couple of enhancements to perf-trace: ability to analyze events from a file and when processing a file limit the analysis to a given set of pid and tids.

David Ahern (3):
perf evlist: Add tracepoint lookup by name
perf trace: Add option to analyze events in a file versus live perf trace: Honor target pid / tid options when analyzing a file

 tools/perf/Documentation/perf-trace.txt |    4 +
 tools/perf/builtin-trace.c              |  135 ++++++++++++++++++++++++++++++-
 tools/perf/util/evlist.c                |   15 ++++
 tools/perf/util/evlist.h                |    4 +
 4 files changed, 157 insertions(+), 1 deletion(-)
Signature · 1 line
1.7.10.1
#1 lore raw

PATCH 1/3 perf evlist: Add tracepoint lookup by name

Will be used by upcoming perf-trace replay option.

Cc Adrian Hunter <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/evlist.c |   15 +++++++++++++++
 tools/perf/util/evlist.h |    4 ++++
 2 files changed, 19 insertions(+)
tools/perf/util/evlist.c +15 -0
index 1f5105a..c0e43ee 100644
@@ -210,6 +210,21 @@ perf_evlist__find_tracepoint_by_id(struct perf_evlist *evlist, int id)
 	return NULL;
 }
 
+struct perf_evsel *
+perf_evlist__find_tracepoint_by_name(struct perf_evlist *evlist,
+				     const char *name)
+{
+	struct perf_evsel *evsel;
+
+	list_for_each_entry(evsel, &evlist->entries, node) {
+		if ((evsel->attr.type == PERF_TYPE_TRACEPOINT) &&
+		    (strcmp(evsel->name, name) == 0))
+			return evsel;
+	}
+
+	return NULL;
+}
+
 int perf_evlist__add_newtp(struct perf_evlist *evlist,
 			   const char *sys, const char *name, void *handler)
 {
tools/perf/util/evlist.h +4 -0
index 327abab..8a509e2 100644
@@ -71,6 +71,10 @@ int perf_evlist__set_filter(struct perf_evlist *evlist, const char *filter);
 struct perf_evsel *
 perf_evlist__find_tracepoint_by_id(struct perf_evlist *evlist, int id);
 
+struct perf_evsel *
+perf_evlist__find_tracepoint_by_name(struct perf_evlist *evlist,
+				     const char *name);
+
 void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel,
 			 int cpu, int thread, u64 id);
 
Signature · 1 line
1.7.10.1
#2 lore raw

PATCH 2/3 perf trace: Add option to analyze events in a file versus live

In reply to David Ahern

Allows capture of raw_syscall:* events and analyzed at a later time.

Cc Adrian Hunter <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/Documentation/perf-trace.txt |    4 ++
 tools/perf/builtin-trace.c              |   92 ++++++++++++++++++++++++++++++-
 2 files changed, 95 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-trace.txt +4 -0
index fe19811..34c459b 100644
@@ -74,6 +74,10 @@ the thread executes on the designated CPUs. Default is to monitor all CPUs.
 --sched:
 	Accrue thread runtime and provide a summary at the end of the session.
 
+-r
+--replay
+	Process events from a given perf data file.
+
 SEE ALSO
 --------
 linkperf:perf-record[1], linkperf:perf-script[1]
tools/perf/builtin-trace.c +91 -1

122 lines not on this page · raw message

Signature · 1 line
1.7.10.1
#3 lore raw

Re: [PATCH 2/3] perf trace: Add option to analyze events in a file versus live

Em Mon, Aug 26, 2013 at 09:52:14PM -0600, David Ahern escreveu:

tools/perf/Documentation/perf-trace.txt the thread executes on the designated CPUs. Default is to monitor all CPUs. · line 79

Quoted 6 lines

Allows capture of raw_syscall:* events and analyzed at a later time.

+-r
+--replay
tools/perf/Documentation/perf-trace.txt +1 -0
+	Process events from a given perf data file.

Shouldn't this be just -i/--input, like for 'report', 'annotate', etc?

- Arnaldo

#4 lore raw

Re: [PATCH 2/3] perf trace: Add option to analyze events in a file versus live

Quoted 4 lines · Arnaldo Carvalho de Melo

Em Mon, Aug 26, 2013 at 09:52:14PM -0600, David Ahern escreveu:

Quoted 3 lines

Allows capture of raw_syscall:* events and analyzed at a later time.

Quoted 8 lines

tools/perf/Documentation/perf-trace.txt the thread executes on the designated CPUs. Default is to monitor all CPUs. · line 79

Quoted 3 lines
+-r
+--replay
tools/perf/Documentation/perf-trace.txt +1 -0
+	Process events from a given perf data file.

Shouldn't this be just -i/--input, like for 'report', 'annotate', etc?

- Arnaldo

uh, arguably. But -i == inherit per a prior patch. record (-i = inherit) / report (-i = input file) collision.

I have used this a bit over the last 2 days and -r is not logical. How about -f / --file?

David

#5 lore raw

Re: [PATCH 2/3] perf trace: Add option to analyze events in a file versus live

Em Wed, Aug 28, 2013 at 07:09:37AM -0600, David Ahern escreveu:

Quoted 5 lines · Arnaldo Carvalho de Melo
Quoted 3 lines

Em Mon, Aug 26, 2013 at 09:52:14PM -0600, David Ahern escreveu:

Quoted 2 lines

Allows capture of raw_syscall:* events and analyzed at a later time.

Quoted 8 lines
Quoted 5 lines

tools/perf/Documentation/perf-trace.txt the thread executes on the designated CPUs. Default is to monitor all CPUs. · line 79

Quoted 3 lines
+-r
+--replay
tools/perf/Documentation/perf-trace.txt +1 -0
+	Process events from a given perf data file.

Shouldn't this be just -i/--input, like for 'report', 'annotate', etc?

uh, arguably. But -i == inherit per a prior patch. record (-i = inherit) / report (-i = input file) collision.

Perhaps --inherit is seldom used and can stay just as --inherit so that we can use -i/--input to keep it consistent with report/annotate/etc?

- Arnaldo

#6 lore raw

PATCH 3/3 perf trace: Honor target pid / tid options when analyzing a file

In reply to David Ahern

Allows capture of raw_syscall events for all processes or threads in a task and then analyzing specific ones.

Cc Adrian Hunter <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/builtin-trace.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
tools/perf/builtin-trace.c +43 -0
index a0a1540..ef957a1 100644
@@ -8,6 +8,7 @@
 #include "util/thread.h"
 #include "util/parse-options.h"
 #include "util/strlist.h"
+#include "util/intlist.h"
 #include "util/thread_map.h"
 
 #include <libaudit.h>
@@ -259,6 +260,8 @@ struct trace {
 	unsigned long		nr_events;
 	struct strlist		*ev_qualifier;
 	bool			not_ev_qualifier;
+	struct intlist		*tid_list;
+	struct intlist		*pid_list;
 	bool			sched;
 	bool			multiple_threads;
 	double			duration_filter;
@@ -649,6 +652,18 @@ out_dump:
 	return 0;
 }
 
+static bool skip_sample(struct trace *trace, struct perf_sample *sample)
+{
+	if ((trace->pid_list && intlist__find(trace->pid_list, sample->pid)) ||
+	    (trace->tid_list && intlist__find(trace->tid_list, sample->tid)))
+		return false;
+
+	if (trace->pid_list || trace->tid_list)
+		return true;
+
+	return false;
+}
+
 static int trace__process_sample(struct perf_tool *tool,
 				 union perf_event *event __maybe_unused,
 				 struct perf_sample *sample,
@@ -660,6 +675,9 @@ static int trace__process_sample(struct perf_tool *tool,
 
 	tracepoint_handler handler = evsel->handler.func;
 
+	if (skip_sample(trace, sample))
+		return 0;
+
 	if (trace->base_time == 0)
 		trace->base_time = sample->time;
 
@@ -679,6 +697,27 @@ perf_session__has_tp(struct perf_session *session, const char *name)
 	return evsel != NULL;
 }
 
+static int parse_target_str(struct trace *trace)
+{
+	if (trace->opts.target.pid) {
+		trace->pid_list = intlist__new(trace->opts.target.pid);
+		if (trace->pid_list == NULL) {
+			pr_err("Error parsing process id string\n");
+			return -EINVAL;
+		}
+	}
+
+	if (trace->opts.target.tid) {
+		trace->tid_list = intlist__new(trace->opts.target.tid);
+		if (trace->tid_list == NULL) {
+			pr_err("Error parsing thread id string\n");
+			return -EINVAL;
+		}
+	}
+
+	return 0;
+}
+
 static int trace__run(struct trace *trace, int argc, const char **argv)
 {
 	struct perf_evlist *evlist = perf_evlist__new();
@@ -861,6 +900,10 @@ static int trace__replay(struct trace *trace)
 		goto out;
 	}
 
+	err = parse_target_str(trace);
+	if (err != 0)
+		goto out;
+
 	setup_pager();
 
 	err = perf_session__process_events(session, &trace->tool);
Signature · 1 line
1.7.10.1