aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace/trace_output.c
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2008-12-23 23:24:13 -0500
committerIngo Molnar <mingo@elte.hu>2008-12-29 06:46:12 -0500
commitf633cef0200bbaec539e2dbb0bc4bed7f022f98b (patch)
tree725d0b181b8e417303e27fa9e62d06b780fe4934 /kernel/trace/trace_output.c
parentf0868d1e23a8efec33beb3aa688aab7fdb1ae093 (diff)
ftrace: change trace.c to use registered events
Impact: rework trace.c to use new event register API Almost every ftrace event has to implement its output display in trace.c through a different function. Some events did not handle all the formats (trace, latency-trace, raw, hex, binary), and this method does not scale well. This patch converts the format functions to use the event API to find the event and and print its format. Currently, we have a print function for trace, latency_trace, raw, hex and binary. A trace_nop_print is available if the event wants to avoid output on a particular format. Perhaps other tracers could use this in the future (like mmiotrace and function_graph). Signed-off-by: Steven Rostedt <srostedt@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.c467
1 files changed, 467 insertions, 0 deletions
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index 1f3f80002b5..df0c25cbed3 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -286,6 +286,15 @@ 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 const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
290
291static int task_state_char(unsigned long state)
292{
293 int bit = state ? __ffs(state) + 1 : 0;
294
295 return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
296}
297
289/** 298/**
290 * ftrace_find_event - find a registered event 299 * ftrace_find_event - find a registered event
291 * @type: the type of event to look for 300 * @type: the type of event to look for
@@ -363,3 +372,461 @@ int unregister_ftrace_event(struct trace_event *event)
363 372
364 return 0; 373 return 0;
365} 374}
375
376/*
377 * Standard events
378 */
379
380int
381trace_nop_print(struct trace_seq *s, struct trace_entry *entry, int flags)
382{
383 return 0;
384}
385
386/* TRACE_FN */
387static int
388trace_fn_latency(struct trace_seq *s, struct trace_entry *entry, int flags)
389{
390 struct ftrace_entry *field;
391
392 trace_assign_type(field, entry);
393
394 if (!seq_print_ip_sym(s, field->ip, flags))
395 goto partial;
396 if (!trace_seq_puts(s, " ("))
397 goto partial;
398 if (!seq_print_ip_sym(s, field->parent_ip, flags))
399 goto partial;
400 if (!trace_seq_puts(s, ")\n"))
401 goto partial;
402
403 return 0;
404
405 partial:
406 return TRACE_TYPE_PARTIAL_LINE;
407}
408
409static int
410trace_fn_trace(struct trace_seq *s, struct trace_entry *entry, int flags)
411{
412 struct ftrace_entry *field;
413
414 trace_assign_type(field, entry);
415
416 if (!seq_print_ip_sym(s, field->ip, flags))
417 goto partial;
418
419 if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
420 if (!trace_seq_printf(s, " <-"))
421 goto partial;
422 if (!seq_print_ip_sym(s,
423 field->parent_ip,
424 flags))
425 goto partial;
426 }
427 if (!trace_seq_printf(s, "\n"))
428 goto partial;
429
430 return 0;
431
432 partial:
433 return TRACE_TYPE_PARTIAL_LINE;
434}
435
436static int
437trace_fn_raw(struct trace_seq *s, struct trace_entry *entry, int flags)
438{
439 struct ftrace_entry *field;
440
441 trace_assign_type(field, entry);
442
443 if (trace_seq_printf(s, "%x %x\n",
444 field->ip,
445 field->parent_ip))
446 return TRACE_TYPE_PARTIAL_LINE;
447
448 return 0;
449}
450
451static int
452trace_fn_hex(struct trace_seq *s, struct trace_entry *entry, int flags)
453{
454 struct ftrace_entry *field;
455
456 trace_assign_type(field, entry);
457
458 SEQ_PUT_HEX_FIELD_RET(s, field->ip);
459 SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
460
461 return 0;
462}
463
464static int
465trace_fn_bin(struct trace_seq *s, struct trace_entry *entry, int flags)
466{
467 struct ftrace_entry *field;
468
469 trace_assign_type(field, entry);
470
471 SEQ_PUT_FIELD_RET(s, field->ip);
472 SEQ_PUT_FIELD_RET(s, field->parent_ip);
473
474 return 0;
475}
476
477static struct trace_event trace_fn_event = {
478 .type = TRACE_FN,
479 .trace = trace_fn_trace,
480 .latency_trace = trace_fn_latency,
481 .raw = trace_fn_raw,
482 .hex = trace_fn_hex,
483 .binary = trace_fn_bin,
484};
485
486/* TRACE_CTX an TRACE_WAKE */
487static int
488trace_ctxwake_print(struct trace_seq *s, struct trace_entry *entry, int flags,
489 char *delim)
490{
491 struct ctx_switch_entry *field;
492 char *comm;
493 int S, T;
494
495 trace_assign_type(field, entry);
496
497 T = task_state_char(field->next_state);
498 S = task_state_char(field->prev_state);
499 comm = trace_find_cmdline(field->next_pid);
500 if (trace_seq_printf(s, " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
501 field->prev_pid,
502 field->prev_prio,
503 S, delim,
504 field->next_cpu,
505 field->next_pid,
506 field->next_prio,
507 T, comm))
508 return TRACE_TYPE_PARTIAL_LINE;
509
510 return 0;
511}
512
513static int
514trace_ctx_print(struct trace_seq *s, struct trace_entry *entry, int flags)
515{
516 return trace_ctxwake_print(s, entry, flags, "==>");
517}
518
519static int
520trace_wake_print(struct trace_seq *s, struct trace_entry *entry, int flags)
521{
522 return trace_ctxwake_print(s, entry, flags, " +");
523}
524
525static int
526trace_ctxwake_raw(struct trace_seq *s, struct trace_entry *entry, int flags,
527 char S)
528{
529 struct ctx_switch_entry *field;
530 int T;
531
532 trace_assign_type(field, entry);
533
534 if (!S)
535 task_state_char(field->prev_state);
536 T = task_state_char(field->next_state);
537 if (trace_seq_printf(s, "%d %d %c %d %d %d %c\n",
538 field->prev_pid,
539 field->prev_prio,
540 S,
541 field->next_cpu,
542 field->next_pid,
543 field->next_prio,
544 T))
545 return TRACE_TYPE_PARTIAL_LINE;
546
547 return 0;
548}
549
550static int
551trace_ctx_raw(struct trace_seq *s, struct trace_entry *entry, int flags)
552{
553 return trace_ctxwake_raw(s, entry, flags, 0);
554}
555
556static int
557trace_wake_raw(struct trace_seq *s, struct trace_entry *entry, int flags)
558{
559 return trace_ctxwake_raw(s, entry, flags, '+');
560}
561
562
563static int
564trace_ctxwake_hex(struct trace_seq *s, struct trace_entry *entry, int flags,
565 char S)
566{
567 struct ctx_switch_entry *field;
568 int T;
569
570 trace_assign_type(field, entry);
571
572 if (!S)
573 task_state_char(field->prev_state);
574 T = task_state_char(field->next_state);
575
576 SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
577 SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
578 SEQ_PUT_HEX_FIELD_RET(s, S);
579 SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
580 SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
581 SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
582 SEQ_PUT_HEX_FIELD_RET(s, T);
583
584 return 0;
585}
586
587static int
588trace_ctx_hex(struct trace_seq *s, struct trace_entry *entry, int flags)
589{
590 return trace_ctxwake_hex(s, entry, flags, 0);
591}
592
593static int
594trace_wake_hex(struct trace_seq *s, struct trace_entry *entry, int flags)
595{
596 return trace_ctxwake_hex(s, entry, flags, '+');
597}
598
599static int
600trace_ctxwake_bin(struct trace_seq *s, struct trace_entry *entry, int flags)
601{
602 struct ctx_switch_entry *field;
603
604 trace_assign_type(field, entry);
605
606 SEQ_PUT_FIELD_RET(s, field->prev_pid);
607 SEQ_PUT_FIELD_RET(s, field->prev_prio);
608 SEQ_PUT_FIELD_RET(s, field->prev_state);
609 SEQ_PUT_FIELD_RET(s, field->next_pid);
610 SEQ_PUT_FIELD_RET(s, field->next_prio);
611 SEQ_PUT_FIELD_RET(s, field->next_state);
612
613 return 0;
614}
615
616static struct trace_event trace_ctx_event = {
617 .type = TRACE_CTX,
618 .trace = trace_ctx_print,
619 .latency_trace = trace_ctx_print,
620 .raw = trace_ctx_raw,
621 .hex = trace_ctx_hex,
622 .binary = trace_ctxwake_bin,
623};
624
625static struct trace_event trace_wake_event = {
626 .type = TRACE_WAKE,
627 .trace = trace_wake_print,
628 .latency_trace = trace_wake_print,
629 .raw = trace_wake_raw,
630 .hex = trace_wake_hex,
631 .binary = trace_ctxwake_bin,
632};
633
634/* TRACE_SPECIAL */
635static int
636trace_special_print(struct trace_seq *s, struct trace_entry *entry, int flags)
637{
638 struct special_entry *field;
639
640 trace_assign_type(field, entry);
641
642 if (trace_seq_printf(s, "# %ld %ld %ld\n",
643 field->arg1,
644 field->arg2,
645 field->arg3))
646 return TRACE_TYPE_PARTIAL_LINE;
647
648 return 0;
649}
650
651static int
652trace_special_hex(struct trace_seq *s, struct trace_entry *entry, int flags)
653{
654 struct special_entry *field;
655
656 trace_assign_type(field, entry);
657
658 SEQ_PUT_HEX_FIELD_RET(s, field->arg1);
659 SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
660 SEQ_PUT_HEX_FIELD_RET(s, field->arg3);
661
662 return 0;
663}
664
665static int
666trace_special_bin(struct trace_seq *s, struct trace_entry *entry, int flags)
667{
668 struct special_entry *field;
669
670 trace_assign_type(field, entry);
671
672 SEQ_PUT_FIELD_RET(s, field->arg1);
673 SEQ_PUT_FIELD_RET(s, field->arg2);
674 SEQ_PUT_FIELD_RET(s, field->arg3);
675
676 return 0;
677}
678
679static struct trace_event trace_special_event = {
680 .type = TRACE_SPECIAL,
681 .trace = trace_special_print,
682 .latency_trace = trace_special_print,
683 .raw = trace_special_print,
684 .hex = trace_special_hex,
685 .binary = trace_special_bin,
686};
687
688/* TRACE_STACK */
689
690static int
691trace_stack_print(struct trace_seq *s, struct trace_entry *entry, int flags)
692{
693 struct stack_entry *field;
694 int i;
695
696 trace_assign_type(field, entry);
697
698 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
699 if (i) {
700 if (trace_seq_puts(s, " <= "))
701 goto partial;
702
703 if (seq_print_ip_sym(s, field->caller[i], flags))
704 goto partial;
705 }
706 if (trace_seq_puts(s, "\n"))
707 goto partial;
708 }
709
710 return 0;
711
712 partial:
713 return TRACE_TYPE_PARTIAL_LINE;
714}
715
716static struct trace_event trace_stack_event = {
717 .type = TRACE_STACK,
718 .trace = trace_stack_print,
719 .latency_trace = trace_stack_print,
720 .raw = trace_special_print,
721 .hex = trace_special_hex,
722 .binary = trace_special_bin,
723};
724
725/* TRACE_USER_STACK */
726static int
727trace_user_stack_print(struct trace_seq *s, struct trace_entry *entry,
728 int flags)
729{
730 struct userstack_entry *field;
731
732 trace_assign_type(field, entry);
733
734 if (seq_print_userip_objs(field, s, flags))
735 goto partial;
736
737 if (trace_seq_putc(s, '\n'))
738 goto partial;
739
740 return 0;
741
742 partial:
743 return TRACE_TYPE_PARTIAL_LINE;
744}
745
746static struct trace_event trace_user_stack_event = {
747 .type = TRACE_USER_STACK,
748 .trace = trace_user_stack_print,
749 .latency_trace = trace_user_stack_print,
750 .raw = trace_special_print,
751 .hex = trace_special_hex,
752 .binary = trace_special_bin,
753};
754
755/* TRACE_PRINT */
756static int
757trace_print_print(struct trace_seq *s, struct trace_entry *entry, int flags)
758{
759 struct print_entry *field;
760
761 trace_assign_type(field, entry);
762
763 if (seq_print_ip_sym(s, field->ip, flags))
764 goto partial;
765
766 if (trace_seq_printf(s, ": %s", field->buf))
767 goto partial;
768
769 return 0;
770
771 partial:
772 return TRACE_TYPE_PARTIAL_LINE;
773}
774
775static int
776trace_print_raw(struct trace_seq *s, struct trace_entry *entry, int flags)
777{
778 struct print_entry *field;
779
780 trace_assign_type(field, entry);
781
782 if (seq_print_ip_sym(s, field->ip, flags))
783 goto partial;
784
785 if (trace_seq_printf(s, "# %lx %s", field->ip, field->buf))
786 goto partial;
787
788 return 0;
789
790 partial:
791 return TRACE_TYPE_PARTIAL_LINE;
792}
793
794static struct trace_event trace_print_event = {
795 .type = TRACE_PRINT,
796 .trace = trace_print_print,
797 .latency_trace = trace_print_print,
798 .raw = trace_print_raw,
799 .hex = trace_nop_print,
800 .binary = trace_nop_print,
801};
802
803static struct trace_event *events[] __initdata = {
804 &trace_fn_event,
805 &trace_ctx_event,
806 &trace_wake_event,
807 &trace_special_event,
808 &trace_stack_event,
809 &trace_user_stack_event,
810 &trace_print_event,
811 NULL
812};
813
814__init static int init_events(void)
815{
816 struct trace_event *event;
817 int i, ret;
818
819 for (i = 0; events[i]; i++) {
820 event = events[i];
821
822 ret = register_ftrace_event(event);
823 if (!ret) {
824 printk(KERN_WARNING "event %d failed to register\n",
825 event->type);
826 WARN_ON_ONCE(1);
827 }
828 }
829
830 return 0;
831}
832device_initcall(init_events);