aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorFrederic Weisbecker <fweisbec@gmail.com>2008-12-03 17:45:11 -0500
committerIngo Molnar <mingo@elte.hu>2008-12-04 04:18:39 -0500
commit1fd8f2a3f9a91b287a876cef830b21baafc8a799 (patch)
tree2baf0dfb14e3765efa370edafa2ab7f78d654308 /kernel
parentb29144c317fb748dae6d72c0f88eda9d43165b8d (diff)
tracing/function-graph-tracer: handle ftrace_printk entries
Handle the TRACE_PRINT entries from the function grapg tracer and output them as a C comment just below the function that called it, as if it was a comment inside this function. Example with an ftrace_printk inside might_sleep() function: void __might_sleep(char *file, int line) { static unsigned long prev_jiffy; /* ratelimiting */ ftrace_printk("Hi I'm a comment in might_sleep() :-)"); A chunk of a resulting trace: 0) | _reiserfs_free_block() { 0) | reiserfs_read_bitmap_block() { 0) | __bread() { 0) | __getblk() { 0) | __find_get_block() { 0) 0.698 us | mark_page_accessed(); 0) 2.267 us | } 0) | __might_sleep() { 0) | /* Hi I'm a comment in might_sleep() :-) */ 0) 1.321 us | } 0) 5.872 us | } 0) 7.313 us | } 0) 8.718 us | } And this patch brings two minor fixes: - The newline after a switch-out task has disappeared - The "|" sign just before the cpu number on task-switch has been deleted. 0) 0.616 us | pick_next_task_rt(); 0) 1.457 us | _spin_trylock(); 0) 0.653 us | _spin_unlock(); 0) 0.728 us | _spin_trylock(); 0) 0.631 us | _spin_unlock(); 0) 0.729 us | native_load_sp0(); 0) 0.593 us | native_load_tls(); ------------------------------------------ 0) cat-2834 => migrati-3 ------------------------------------------ 0) | finish_task_switch() { 0) 0.841 us | _spin_unlock_irq(); 0) 0.616 us | post_schedule_rt(); 0) 3.882 us | } Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Acked-by: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/trace/trace.c28
-rw-r--r--kernel/trace/trace.h4
-rw-r--r--kernel/trace/trace_functions_graph.c72
-rw-r--r--kernel/trace/trace_mmiotrace.c2
4 files changed, 97 insertions, 9 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 8b6409a62b54..1ca74c0cee6a 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -3335,7 +3335,7 @@ static int mark_printk(const char *fmt, ...)
3335 int ret; 3335 int ret;
3336 va_list args; 3336 va_list args;
3337 va_start(args, fmt); 3337 va_start(args, fmt);
3338 ret = trace_vprintk(0, fmt, args); 3338 ret = trace_vprintk(0, -1, fmt, args);
3339 va_end(args); 3339 va_end(args);
3340 return ret; 3340 return ret;
3341} 3341}
@@ -3564,9 +3564,16 @@ static __init int tracer_init_debugfs(void)
3564 return 0; 3564 return 0;
3565} 3565}
3566 3566
3567int trace_vprintk(unsigned long ip, const char *fmt, va_list args) 3567int trace_vprintk(unsigned long ip, int depth, const char *fmt, va_list args)
3568{ 3568{
3569 static DEFINE_SPINLOCK(trace_buf_lock); 3569 /*
3570 * Raw Spinlock because a normal spinlock would be traced here
3571 * and append an irrelevant couple spin_lock_irqsave/
3572 * spin_unlock_irqrestore traced by ftrace around this
3573 * TRACE_PRINTK trace.
3574 */
3575 static raw_spinlock_t trace_buf_lock =
3576 (raw_spinlock_t)__RAW_SPIN_LOCK_UNLOCKED;
3570 static char trace_buf[TRACE_BUF_SIZE]; 3577 static char trace_buf[TRACE_BUF_SIZE];
3571 3578
3572 struct ring_buffer_event *event; 3579 struct ring_buffer_event *event;
@@ -3587,7 +3594,8 @@ int trace_vprintk(unsigned long ip, const char *fmt, va_list args)
3587 if (unlikely(atomic_read(&data->disabled))) 3594 if (unlikely(atomic_read(&data->disabled)))
3588 goto out; 3595 goto out;
3589 3596
3590 spin_lock_irqsave(&trace_buf_lock, flags); 3597 local_irq_save(flags);
3598 __raw_spin_lock(&trace_buf_lock);
3591 len = vsnprintf(trace_buf, TRACE_BUF_SIZE, fmt, args); 3599 len = vsnprintf(trace_buf, TRACE_BUF_SIZE, fmt, args);
3592 3600
3593 len = min(len, TRACE_BUF_SIZE-1); 3601 len = min(len, TRACE_BUF_SIZE-1);
@@ -3601,13 +3609,15 @@ int trace_vprintk(unsigned long ip, const char *fmt, va_list args)
3601 tracing_generic_entry_update(&entry->ent, flags, pc); 3609 tracing_generic_entry_update(&entry->ent, flags, pc);
3602 entry->ent.type = TRACE_PRINT; 3610 entry->ent.type = TRACE_PRINT;
3603 entry->ip = ip; 3611 entry->ip = ip;
3612 entry->depth = depth;
3604 3613
3605 memcpy(&entry->buf, trace_buf, len); 3614 memcpy(&entry->buf, trace_buf, len);
3606 entry->buf[len] = 0; 3615 entry->buf[len] = 0;
3607 ring_buffer_unlock_commit(tr->buffer, event, irq_flags); 3616 ring_buffer_unlock_commit(tr->buffer, event, irq_flags);
3608 3617
3609 out_unlock: 3618 out_unlock:
3610 spin_unlock_irqrestore(&trace_buf_lock, flags); 3619 __raw_spin_unlock(&trace_buf_lock);
3620 local_irq_restore(flags);
3611 3621
3612 out: 3622 out:
3613 preempt_enable_notrace(); 3623 preempt_enable_notrace();
@@ -3625,7 +3635,13 @@ int __ftrace_printk(unsigned long ip, const char *fmt, ...)
3625 return 0; 3635 return 0;
3626 3636
3627 va_start(ap, fmt); 3637 va_start(ap, fmt);
3628 ret = trace_vprintk(ip, fmt, ap); 3638
3639#ifdef CONFIG_FUNCTION_GRAPH_TRACER
3640 ret = trace_vprintk(ip, current->curr_ret_stack, fmt, ap);
3641#else
3642 ret = trace_vprintk(ip, -1, fmt, ap);
3643#endif
3644
3629 va_end(ap); 3645 va_end(ap);
3630 return ret; 3646 return ret;
3631} 3647}
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 0565ae9a2210..fce98898205a 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -117,6 +117,7 @@ struct userstack_entry {
117struct print_entry { 117struct print_entry {
118 struct trace_entry ent; 118 struct trace_entry ent;
119 unsigned long ip; 119 unsigned long ip;
120 int depth;
120 char buf[]; 121 char buf[];
121}; 122};
122 123
@@ -498,7 +499,8 @@ seq_print_ip_sym(struct trace_seq *s, unsigned long ip,
498extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf, 499extern ssize_t trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
499 size_t cnt); 500 size_t cnt);
500extern long ns2usecs(cycle_t nsec); 501extern long ns2usecs(cycle_t nsec);
501extern int trace_vprintk(unsigned long ip, const char *fmt, va_list args); 502extern int
503trace_vprintk(unsigned long ip, int depth, const char *fmt, va_list args);
502 504
503extern unsigned long trace_flags; 505extern unsigned long trace_flags;
504 506
diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
index c66578f2fdc2..32b7fb9a19df 100644
--- a/kernel/trace/trace_functions_graph.c
+++ b/kernel/trace/trace_functions_graph.c
@@ -173,7 +173,7 @@ verif_pid(struct trace_seq *s, pid_t pid, int cpu)
173 173
174 */ 174 */
175 ret = trace_seq_printf(s, 175 ret = trace_seq_printf(s,
176 "\n ------------------------------------------\n |"); 176 " ------------------------------------------\n");
177 if (!ret) 177 if (!ret)
178 TRACE_TYPE_PARTIAL_LINE; 178 TRACE_TYPE_PARTIAL_LINE;
179 179
@@ -477,6 +477,71 @@ print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s,
477 return TRACE_TYPE_HANDLED; 477 return TRACE_TYPE_HANDLED;
478} 478}
479 479
480static enum print_line_t
481print_graph_comment(struct print_entry *trace, struct trace_seq *s,
482 struct trace_entry *ent, struct trace_iterator *iter)
483{
484 int i;
485 int ret;
486
487 /* Pid */
488 if (verif_pid(s, ent->pid, iter->cpu) == TRACE_TYPE_PARTIAL_LINE)
489 return TRACE_TYPE_PARTIAL_LINE;
490
491 /* Cpu */
492 if (tracer_flags.val & TRACE_GRAPH_PRINT_CPU) {
493 ret = print_graph_cpu(s, iter->cpu);
494 if (ret == TRACE_TYPE_PARTIAL_LINE)
495 return TRACE_TYPE_PARTIAL_LINE;
496 }
497
498 /* Proc */
499 if (tracer_flags.val & TRACE_GRAPH_PRINT_PROC) {
500 ret = print_graph_proc(s, ent->pid);
501 if (ret == TRACE_TYPE_PARTIAL_LINE)
502 return TRACE_TYPE_PARTIAL_LINE;
503
504 ret = trace_seq_printf(s, " | ");
505 if (!ret)
506 return TRACE_TYPE_PARTIAL_LINE;
507 }
508
509 /* No overhead */
510 if (tracer_flags.val & TRACE_GRAPH_PRINT_OVERHEAD) {
511 ret = trace_seq_printf(s, " ");
512 if (!ret)
513 return TRACE_TYPE_PARTIAL_LINE;
514 }
515
516 /* No time */
517 ret = trace_seq_printf(s, " | ");
518 if (!ret)
519 return TRACE_TYPE_PARTIAL_LINE;
520
521 /* Indentation */
522 if (trace->depth > 0)
523 for (i = 0; i < (trace->depth + 1) * TRACE_GRAPH_INDENT; i++) {
524 ret = trace_seq_printf(s, " ");
525 if (!ret)
526 return TRACE_TYPE_PARTIAL_LINE;
527 }
528
529 /* The comment */
530 ret = trace_seq_printf(s, "/* %s", trace->buf);
531 if (!ret)
532 return TRACE_TYPE_PARTIAL_LINE;
533
534 if (ent->flags & TRACE_FLAG_CONT)
535 trace_seq_print_cont(s, iter);
536
537 ret = trace_seq_printf(s, " */\n");
538 if (!ret)
539 return TRACE_TYPE_PARTIAL_LINE;
540
541 return TRACE_TYPE_HANDLED;
542}
543
544
480enum print_line_t 545enum print_line_t
481print_graph_function(struct trace_iterator *iter) 546print_graph_function(struct trace_iterator *iter)
482{ 547{
@@ -495,6 +560,11 @@ print_graph_function(struct trace_iterator *iter)
495 trace_assign_type(field, entry); 560 trace_assign_type(field, entry);
496 return print_graph_return(&field->ret, s, entry, iter->cpu); 561 return print_graph_return(&field->ret, s, entry, iter->cpu);
497 } 562 }
563 case TRACE_PRINT: {
564 struct print_entry *field;
565 trace_assign_type(field, entry);
566 return print_graph_comment(field, s, entry, iter);
567 }
498 default: 568 default:
499 return TRACE_TYPE_UNHANDLED; 569 return TRACE_TYPE_UNHANDLED;
500 } 570 }
diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
index 2a98a206acc2..2fb6da6523b3 100644
--- a/kernel/trace/trace_mmiotrace.c
+++ b/kernel/trace/trace_mmiotrace.c
@@ -366,5 +366,5 @@ void mmio_trace_mapping(struct mmiotrace_map *map)
366 366
367int mmio_trace_printk(const char *fmt, va_list args) 367int mmio_trace_printk(const char *fmt, va_list args)
368{ 368{
369 return trace_vprintk(0, fmt, args); 369 return trace_vprintk(0, -1, fmt, args);
370} 370}