aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2012-10-24 15:24:47 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2012-10-24 15:24:47 -0400
commit60c907abc635622964f7862c8f2977182124f89d (patch)
treeaeb18e5f9be0da64789b069e014900ec2ff13928 /tools
parent752fde44fd1c4a411d709c7d4ad0f121f427f234 (diff)
perf trace: Add an event duration column
# perf trace usleep 1 | tail -10 0.453 ( 0.002 ms): mmap(addr: 0, len: 4096, prot: 3, flags: 34, fd: 4294967295, off: 0 ) = -763342848 0.456 ( 0.001 ms): mmap(addr: 0, len: 4096, prot: 3, flags: 34, fd: 4294967295, off: 0 ) = -763346944 0.459 ( 0.001 ms): arch_prctl(option: 4098, arg2: 140126839658240, arg3: 140126839652352, arg4: 34, arg5: 4294967295) = 0 0.473 ( 0.003 ms): mprotect(start: 208741634048, len: 16384, prot: 1 ) = 0 0.477 ( 0.003 ms): mprotect(start: 208735956992, len: 4096, prot: 1 ) = 0 0.483 ( 0.004 ms): munmap(addr: 140126839664640, len: 91882 ) = 0 0.540 ( 0.001 ms): brk(brk: 0 ) = 31928320 0.542 ( 0.002 ms): brk(brk: 32063488 ) = 32063488 1.456 ( 0.901 ms): nanosleep(rqtp: 140735472817168, rmtp: 0 ) = 0 1.462 ( 0.000 ms): exit_group(error_code: 0 # This also comes from the tmp.perf/trace2 branch. 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> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/n/tip-g9akh5hjw2kvjerpo9xror6f@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/perf/builtin-trace.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 873f50b10cc9..ddb6e3721b1a 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -46,6 +46,20 @@ struct syscall {
46 struct syscall_fmt *fmt; 46 struct syscall_fmt *fmt;
47}; 47};
48 48
49static size_t fprintf_duration(unsigned long t, FILE *fp)
50{
51 double duration = (double)t / NSEC_PER_MSEC;
52 size_t printed = fprintf(fp, "(");
53
54 if (duration >= 1.0)
55 printed += color_fprintf(fp, PERF_COLOR_RED, "%6.3f ms", duration);
56 else if (duration >= 0.01)
57 printed += color_fprintf(fp, PERF_COLOR_YELLOW, "%6.3f ms", duration);
58 else
59 printed += color_fprintf(fp, PERF_COLOR_NORMAL, "%6.3f ms", duration);
60 return printed + fprintf(stdout, "): ");
61}
62
49struct thread_trace { 63struct thread_trace {
50 u64 entry_time; 64 u64 entry_time;
51 u64 exit_time; 65 u64 exit_time;
@@ -92,7 +106,7 @@ static size_t trace__fprintf_tstamp(struct trace *trace, u64 tstamp, FILE *fp)
92{ 106{
93 double ts = (double)(tstamp - trace->base_time) / NSEC_PER_MSEC; 107 double ts = (double)(tstamp - trace->base_time) / NSEC_PER_MSEC;
94 108
95 return fprintf(fp, "%10.3f: ", ts); 109 return fprintf(fp, "%10.3f ", ts);
96} 110}
97 111
98static bool done = false; 112static bool done = false;
@@ -103,9 +117,10 @@ static void sig_handler(int sig __maybe_unused)
103} 117}
104 118
105static size_t trace__fprintf_entry_head(struct trace *trace, struct thread *thread, 119static size_t trace__fprintf_entry_head(struct trace *trace, struct thread *thread,
106 u64 tstamp, FILE *fp) 120 u64 duration, u64 tstamp, FILE *fp)
107{ 121{
108 size_t printed = trace__fprintf_tstamp(trace, tstamp, fp); 122 size_t printed = trace__fprintf_tstamp(trace, tstamp, fp);
123 printed += fprintf_duration(duration, fp);
109 124
110 if (trace->multiple_threads) 125 if (trace->multiple_threads)
111 printed += fprintf(fp, "%d ", thread->pid); 126 printed += fprintf(fp, "%d ", thread->pid);
@@ -292,7 +307,7 @@ static int trace__sys_enter(struct trace *trace, struct perf_evsel *evsel,
292 printed += syscall__scnprintf_args(sc, msg + printed, 1024 - printed, args); 307 printed += syscall__scnprintf_args(sc, msg + printed, 1024 - printed, args);
293 308
294 if (!strcmp(sc->name, "exit_group") || !strcmp(sc->name, "exit")) { 309 if (!strcmp(sc->name, "exit_group") || !strcmp(sc->name, "exit")) {
295 trace__fprintf_entry_head(trace, thread, sample->time, stdout); 310 trace__fprintf_entry_head(trace, thread, 1, sample->time, stdout);
296 printf("%-70s\n", ttrace->entry_str); 311 printf("%-70s\n", ttrace->entry_str);
297 } else 312 } else
298 ttrace->entry_pending = true; 313 ttrace->entry_pending = true;
@@ -304,6 +319,7 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
304 struct perf_sample *sample) 319 struct perf_sample *sample)
305{ 320{
306 int ret; 321 int ret;
322 u64 duration = 0;
307 struct thread *thread = machine__findnew_thread(&trace->host, sample->tid); 323 struct thread *thread = machine__findnew_thread(&trace->host, sample->tid);
308 struct thread_trace *ttrace = thread__trace(thread); 324 struct thread_trace *ttrace = thread__trace(thread);
309 struct syscall *sc = trace__syscall_info(trace, evsel, sample); 325 struct syscall *sc = trace__syscall_info(trace, evsel, sample);
@@ -317,7 +333,10 @@ static int trace__sys_exit(struct trace *trace, struct perf_evsel *evsel,
317 333
318 ttrace->exit_time = sample->time; 334 ttrace->exit_time = sample->time;
319 335
320 trace__fprintf_entry_head(trace, thread, sample->time, stdout); 336 if (ttrace->entry_time)
337 duration = sample->time - ttrace->entry_time;
338
339 trace__fprintf_entry_head(trace, thread, duration, sample->time, stdout);
321 340
322 if (ttrace->entry_pending) { 341 if (ttrace->entry_pending) {
323 printf("%-70s", ttrace->entry_str); 342 printf("%-70s", ttrace->entry_str);