aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authorAdrian Hunter <adrian.hunter@intel.com>2013-11-01 09:51:30 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-11-04 10:19:26 -0500
commit7ea95727af571d592c9d6aa7627690d44b114a2d (patch)
tree43af87a288748e3e6c2baad21170405f34a0df63 /tools/perf
parentf852fd621ca19f557f2e3d05900366be7c7afb83 (diff)
perf script: Set up output options for in-stream attributes
Attributes (struct perf_event_attr) are recorded separately in the perf.data file. perf script uses them to set up output options. However attributes can also be in the event stream, for example when the input is a pipe (i.e. live mode). This patch makes perf script process in-stream attributes in the same way as on-file attributes. Here is an example: Before this patch: $ perf record uname | perf script Linux [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.015 MB (null) (~655 samples) ] :4220 4220 [-01] 2933367.838906: cycles: :4220 4220 [-01] 2933367.838910: cycles: :4220 4220 [-01] 2933367.838912: cycles: :4220 4220 [-01] 2933367.838914: cycles: :4220 4220 [-01] 2933367.838916: cycles: :4220 4220 [-01] 2933367.838918: cycles: uname 4220 [-01] 2933367.838938: cycles: uname 4220 [-01] 2933367.839207: cycles: After this patch: $ perf record uname | perf script Linux [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.015 MB (null) (~655 samples) ] :4582 4582 2933425.707724: cycles: ffffffff81043ffa native_write_msr_safe ([kernel.kallsyms]) :4582 4582 2933425.707728: cycles: ffffffff81043ffa native_write_msr_safe ([kernel.kallsyms]) :4582 4582 2933425.707730: cycles: ffffffff81043ffa native_write_msr_safe ([kernel.kallsyms]) :4582 4582 2933425.707732: cycles: ffffffff81043ffa native_write_msr_safe ([kernel.kallsyms]) :4582 4582 2933425.707734: cycles: ffffffff81043ffa native_write_msr_safe ([kernel.kallsyms]) :4582 4582 2933425.707736: cycles: ffffffff81309a24 memcpy ([kernel.kallsyms]) uname 4582 2933425.707760: cycles: ffffffff8109c1c7 enqueue_task_fair ([kernel.kallsyms]) uname 4582 2933425.707978: cycles: ffffffff81308457 clear_page_c ([kernel.kallsyms]) Signed-off-by: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@redhat.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 <a.p.zijlstra@chello.nl> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/1383313899-15987-3-git-send-email-adrian.hunter@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/builtin-script.c64
1 files changed, 48 insertions, 16 deletions
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index b866cc8c3878..baf17989a216 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -229,6 +229,24 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,
229 return 0; 229 return 0;
230} 230}
231 231
232static void set_print_ip_opts(struct perf_event_attr *attr)
233{
234 unsigned int type = attr->type;
235
236 output[type].print_ip_opts = 0;
237 if (PRINT_FIELD(IP))
238 output[type].print_ip_opts |= PRINT_IP_OPT_IP;
239
240 if (PRINT_FIELD(SYM))
241 output[type].print_ip_opts |= PRINT_IP_OPT_SYM;
242
243 if (PRINT_FIELD(DSO))
244 output[type].print_ip_opts |= PRINT_IP_OPT_DSO;
245
246 if (PRINT_FIELD(SYMOFFSET))
247 output[type].print_ip_opts |= PRINT_IP_OPT_SYMOFFSET;
248}
249
232/* 250/*
233 * verify all user requested events exist and the samples 251 * verify all user requested events exist and the samples
234 * have the expected data 252 * have the expected data
@@ -237,7 +255,6 @@ static int perf_session__check_output_opt(struct perf_session *session)
237{ 255{
238 int j; 256 int j;
239 struct perf_evsel *evsel; 257 struct perf_evsel *evsel;
240 struct perf_event_attr *attr;
241 258
242 for (j = 0; j < PERF_TYPE_MAX; ++j) { 259 for (j = 0; j < PERF_TYPE_MAX; ++j) {
243 evsel = perf_session__find_first_evtype(session, j); 260 evsel = perf_session__find_first_evtype(session, j);
@@ -260,20 +277,7 @@ static int perf_session__check_output_opt(struct perf_session *session)
260 if (evsel == NULL) 277 if (evsel == NULL)
261 continue; 278 continue;
262 279
263 attr = &evsel->attr; 280 set_print_ip_opts(&evsel->attr);
264
265 output[j].print_ip_opts = 0;
266 if (PRINT_FIELD(IP))
267 output[j].print_ip_opts |= PRINT_IP_OPT_IP;
268
269 if (PRINT_FIELD(SYM))
270 output[j].print_ip_opts |= PRINT_IP_OPT_SYM;
271
272 if (PRINT_FIELD(DSO))
273 output[j].print_ip_opts |= PRINT_IP_OPT_DSO;
274
275 if (PRINT_FIELD(SYMOFFSET))
276 output[j].print_ip_opts |= PRINT_IP_OPT_SYMOFFSET;
277 } 281 }
278 282
279 return 0; 283 return 0;
@@ -547,6 +551,34 @@ struct perf_script {
547 struct perf_session *session; 551 struct perf_session *session;
548}; 552};
549 553
554static int process_attr(struct perf_tool *tool, union perf_event *event,
555 struct perf_evlist **pevlist)
556{
557 struct perf_script *scr = container_of(tool, struct perf_script, tool);
558 struct perf_evlist *evlist;
559 struct perf_evsel *evsel, *pos;
560 int err;
561
562 err = perf_event__process_attr(tool, event, pevlist);
563 if (err)
564 return err;
565
566 evlist = *pevlist;
567 evsel = perf_evlist__last(*pevlist);
568
569 if (evsel->attr.type >= PERF_TYPE_MAX)
570 return 0;
571
572 list_for_each_entry(pos, &evlist->entries, node) {
573 if (pos->attr.type == evsel->attr.type && pos != evsel)
574 return 0;
575 }
576
577 set_print_ip_opts(&evsel->attr);
578
579 return perf_evsel__check_attr(evsel, scr->session);
580}
581
550static void sig_handler(int sig __maybe_unused) 582static void sig_handler(int sig __maybe_unused)
551{ 583{
552 session_done = 1; 584 session_done = 1;
@@ -1272,7 +1304,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
1272 .comm = perf_event__process_comm, 1304 .comm = perf_event__process_comm,
1273 .exit = perf_event__process_exit, 1305 .exit = perf_event__process_exit,
1274 .fork = perf_event__process_fork, 1306 .fork = perf_event__process_fork,
1275 .attr = perf_event__process_attr, 1307 .attr = process_attr,
1276 .tracing_data = perf_event__process_tracing_data, 1308 .tracing_data = perf_event__process_tracing_data,
1277 .build_id = perf_event__process_build_id, 1309 .build_id = perf_event__process_build_id,
1278 .ordered_samples = true, 1310 .ordered_samples = true,