aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace/trace_output.c
diff options
context:
space:
mode:
authorFrederic Weisbecker <fweisbec@gmail.com>2009-02-02 17:29:21 -0500
committerIngo Molnar <mingo@elte.hu>2009-02-03 08:03:52 -0500
commitc4a8e8be2d43cc22b371e8e9c05c253409759d94 (patch)
tree274962a78a082a11550d07c6cc088817d6558db5 /kernel/trace/trace_output.c
parentdc573f9b20c8710105ac35c08ed0fe1da5160ecd (diff)
trace: better manage the context info for events
Impact: make trace_event more convenient for tracers All tracers (for the moment) that use the struct trace_event want to have the context info printed before their own output: the pid/cmdline, cpu, and timestamp. But some other tracers that want to implement their trace_event callbacks will not necessary need these information or they may want to format them as they want. This patch adds a new default-enabled trace option: TRACE_ITER_CONTEXT_INFO When disabled through: echo nocontext-info > /debugfs/tracing/trace_options The pid, cpu and timestamps headers will not be printed. IE with the sched_switch tracer with context-info (default): bash-2935 [001] 100.356561: 2935:120:S ==> [001] 0:140:R <idle> <idle>-0 [000] 100.412804: 0:140:R + [000] 11:115:S events/0 <idle>-0 [000] 100.412816: 0:140:R ==> [000] 11:115:R events/0 events/0-11 [000] 100.412829: 11:115:S ==> [000] 0:140:R <idle> Without context-info: 2935:120:S ==> [001] 0:140:R <idle> 0:140:R + [000] 11:115:S events/0 0:140:R ==> [000] 11:115:R events/0 11:115:S ==> [000] 0:140:R <idle> A tracer can disable it at runtime by clearing the bit TRACE_ITER_CONTEXT_INFO in trace_flags. The print routines were renamed to trace_print_context and trace_print_lat_context, so that they can be used by tracers if they want to use them for one of the trace_event callbacks. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/trace/trace_output.c')
-rw-r--r--kernel/trace/trace_output.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 1a4e144a9f8f..a5752d4d3c33 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -286,6 +286,113 @@ seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
286 return ret; 286 return ret;
287} 287}
288 288
289static void
290lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
291{
292 int hardirq, softirq;
293 char *comm;
294
295 comm = trace_find_cmdline(entry->pid);
296
297 trace_seq_printf(s, "%8.8s-%-5d ", comm, entry->pid);
298 trace_seq_printf(s, "%3d", cpu);
299 trace_seq_printf(s, "%c%c",
300 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
301 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' : '.',
302 ((entry->flags & TRACE_FLAG_NEED_RESCHED) ? 'N' : '.'));
303
304 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
305 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
306 if (hardirq && softirq) {
307 trace_seq_putc(s, 'H');
308 } else {
309 if (hardirq) {
310 trace_seq_putc(s, 'h');
311 } else {
312 if (softirq)
313 trace_seq_putc(s, 's');
314 else
315 trace_seq_putc(s, '.');
316 }
317 }
318
319 if (entry->preempt_count)
320 trace_seq_printf(s, "%x", entry->preempt_count);
321 else
322 trace_seq_puts(s, ".");
323}
324
325static unsigned long preempt_mark_thresh = 100;
326
327static void
328lat_print_timestamp(struct trace_seq *s, u64 abs_usecs,
329 unsigned long rel_usecs)
330{
331 trace_seq_printf(s, " %4lldus", abs_usecs);
332 if (rel_usecs > preempt_mark_thresh)
333 trace_seq_puts(s, "!: ");
334 else if (rel_usecs > 1)
335 trace_seq_puts(s, "+: ");
336 else
337 trace_seq_puts(s, " : ");
338}
339
340int trace_print_context(struct trace_iterator *iter)
341{
342 struct trace_seq *s = &iter->seq;
343 struct trace_entry *entry = iter->ent;
344 char *comm = trace_find_cmdline(entry->pid);
345 unsigned long long t = ns2usecs(iter->ts);
346 unsigned long usec_rem = do_div(t, USEC_PER_SEC);
347 unsigned long secs = (unsigned long)t;
348
349 if (!trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid))
350 goto partial;
351 if (!trace_seq_printf(s, "[%03d] ", entry->cpu))
352 goto partial;
353 if (!trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem))
354 goto partial;
355
356 return 0;
357
358partial:
359 return TRACE_TYPE_PARTIAL_LINE;
360}
361
362int trace_print_lat_context(struct trace_iterator *iter)
363{
364 u64 next_ts;
365 struct trace_seq *s = &iter->seq;
366 struct trace_entry *entry = iter->ent,
367 *next_entry = trace_find_next_entry(iter, NULL,
368 &next_ts);
369 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
370 unsigned long abs_usecs = ns2usecs(iter->ts - iter->tr->time_start);
371 unsigned long rel_usecs;
372
373 if (!next_entry)
374 next_ts = iter->ts;
375 rel_usecs = ns2usecs(next_ts - iter->ts);
376
377 if (verbose) {
378 char *comm = trace_find_cmdline(entry->pid);
379 trace_seq_printf(s, "%16s %5d %3d %d %08x %08lx [%08lx]"
380 " %ld.%03ldms (+%ld.%03ldms): ",
381 comm,
382 entry->pid, entry->cpu, entry->flags,
383 entry->preempt_count, iter->idx,
384 ns2usecs(iter->ts),
385 abs_usecs/1000,
386 abs_usecs % 1000, rel_usecs/1000,
387 rel_usecs % 1000);
388 } else {
389 lat_print_generic(s, entry, entry->cpu);
390 lat_print_timestamp(s, abs_usecs, rel_usecs);
391 }
392
393 return 0;
394}
395
289static const char state_to_char[] = TASK_STATE_TO_CHAR_STR; 396static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
290 397
291static int task_state_char(unsigned long state) 398static int task_state_char(unsigned long state)