summaryrefslogtreecommitdiffstats
path: root/kernel/trace/trace.c
diff options
context:
space:
mode:
authorSteven Rostedt (Red Hat) <rostedt@goodmis.org>2014-11-12 10:29:54 -0500
committerSteven Rostedt <rostedt@goodmis.org>2014-11-19 15:25:39 -0500
commit19a7fe206232cc875a3083211e0a21c08edd756e (patch)
tree948aba93b9f2f6681eb7cc3209b0ec87e19470d1 /kernel/trace/trace.c
parente400a40cffa77e45c60c5431ec8757579247cae2 (diff)
tracing: Add trace_seq_has_overflowed() and trace_handle_return()
Adding a trace_seq_has_overflowed() which returns true if the trace_seq had too much written into it allows us to simplify the code. Instead of checking the return value of every call to trace_seq_printf() and friends, they can all be called normally, and at the end we can return !trace_seq_has_overflowed() instead. Several functions also return TRACE_TYPE_PARTIAL_LINE when the trace_seq overflowed and TRACE_TYPE_HANDLED otherwise. Another helper function was created called trace_handle_return() which takes a trace_seq and returns these enums. Using this helper function also simplifies the code. This change also makes it possible to remove the return values of trace_seq_printf() and friends. They should instead just be void functions. Link: http://lkml.kernel.org/r/20141114011410.365183157@goodmis.org Reviewed-by: Petr Mladek <pmladek@suse.cz> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'kernel/trace/trace.c')
-rw-r--r--kernel/trace/trace.c69
1 files changed, 35 insertions, 34 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 44d561426700..3ce3c4ccfc94 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2649,24 +2649,21 @@ static enum print_line_t print_trace_fmt(struct trace_iterator *iter)
2649 event = ftrace_find_event(entry->type); 2649 event = ftrace_find_event(entry->type);
2650 2650
2651 if (trace_flags & TRACE_ITER_CONTEXT_INFO) { 2651 if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
2652 if (iter->iter_flags & TRACE_FILE_LAT_FMT) { 2652 if (iter->iter_flags & TRACE_FILE_LAT_FMT)
2653 if (!trace_print_lat_context(iter)) 2653 trace_print_lat_context(iter);
2654 goto partial; 2654 else
2655 } else { 2655 trace_print_context(iter);
2656 if (!trace_print_context(iter))
2657 goto partial;
2658 }
2659 } 2656 }
2660 2657
2658 if (trace_seq_has_overflowed(s))
2659 return TRACE_TYPE_PARTIAL_LINE;
2660
2661 if (event) 2661 if (event)
2662 return event->funcs->trace(iter, sym_flags, event); 2662 return event->funcs->trace(iter, sym_flags, event);
2663 2663
2664 if (!trace_seq_printf(s, "Unknown type %d\n", entry->type)) 2664 trace_seq_printf(s, "Unknown type %d\n", entry->type);
2665 goto partial;
2666 2665
2667 return TRACE_TYPE_HANDLED; 2666 return trace_handle_return(s);
2668partial:
2669 return TRACE_TYPE_PARTIAL_LINE;
2670} 2667}
2671 2668
2672static enum print_line_t print_raw_fmt(struct trace_iterator *iter) 2669static enum print_line_t print_raw_fmt(struct trace_iterator *iter)
@@ -2677,22 +2674,20 @@ static enum print_line_t print_raw_fmt(struct trace_iterator *iter)
2677 2674
2678 entry = iter->ent; 2675 entry = iter->ent;
2679 2676
2680 if (trace_flags & TRACE_ITER_CONTEXT_INFO) { 2677 if (trace_flags & TRACE_ITER_CONTEXT_INFO)
2681 if (!trace_seq_printf(s, "%d %d %llu ", 2678 trace_seq_printf(s, "%d %d %llu ",
2682 entry->pid, iter->cpu, iter->ts)) 2679 entry->pid, iter->cpu, iter->ts);
2683 goto partial; 2680
2684 } 2681 if (trace_seq_has_overflowed(s))
2682 return TRACE_TYPE_PARTIAL_LINE;
2685 2683
2686 event = ftrace_find_event(entry->type); 2684 event = ftrace_find_event(entry->type);
2687 if (event) 2685 if (event)
2688 return event->funcs->raw(iter, 0, event); 2686 return event->funcs->raw(iter, 0, event);
2689 2687
2690 if (!trace_seq_printf(s, "%d ?\n", entry->type)) 2688 trace_seq_printf(s, "%d ?\n", entry->type);
2691 goto partial;
2692 2689
2693 return TRACE_TYPE_HANDLED; 2690 return trace_handle_return(s);
2694partial:
2695 return TRACE_TYPE_PARTIAL_LINE;
2696} 2691}
2697 2692
2698static enum print_line_t print_hex_fmt(struct trace_iterator *iter) 2693static enum print_line_t print_hex_fmt(struct trace_iterator *iter)
@@ -2705,9 +2700,11 @@ static enum print_line_t print_hex_fmt(struct trace_iterator *iter)
2705 entry = iter->ent; 2700 entry = iter->ent;
2706 2701
2707 if (trace_flags & TRACE_ITER_CONTEXT_INFO) { 2702 if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
2708 SEQ_PUT_HEX_FIELD_RET(s, entry->pid); 2703 SEQ_PUT_HEX_FIELD(s, entry->pid);
2709 SEQ_PUT_HEX_FIELD_RET(s, iter->cpu); 2704 SEQ_PUT_HEX_FIELD(s, iter->cpu);
2710 SEQ_PUT_HEX_FIELD_RET(s, iter->ts); 2705 SEQ_PUT_HEX_FIELD(s, iter->ts);
2706 if (trace_seq_has_overflowed(s))
2707 return TRACE_TYPE_PARTIAL_LINE;
2711 } 2708 }
2712 2709
2713 event = ftrace_find_event(entry->type); 2710 event = ftrace_find_event(entry->type);
@@ -2717,9 +2714,9 @@ static enum print_line_t print_hex_fmt(struct trace_iterator *iter)
2717 return ret; 2714 return ret;
2718 } 2715 }
2719 2716
2720 SEQ_PUT_FIELD_RET(s, newline); 2717 SEQ_PUT_FIELD(s, newline);
2721 2718
2722 return TRACE_TYPE_HANDLED; 2719 return trace_handle_return(s);
2723} 2720}
2724 2721
2725static enum print_line_t print_bin_fmt(struct trace_iterator *iter) 2722static enum print_line_t print_bin_fmt(struct trace_iterator *iter)
@@ -2731,9 +2728,11 @@ static enum print_line_t print_bin_fmt(struct trace_iterator *iter)
2731 entry = iter->ent; 2728 entry = iter->ent;
2732 2729
2733 if (trace_flags & TRACE_ITER_CONTEXT_INFO) { 2730 if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
2734 SEQ_PUT_FIELD_RET(s, entry->pid); 2731 SEQ_PUT_FIELD(s, entry->pid);
2735 SEQ_PUT_FIELD_RET(s, iter->cpu); 2732 SEQ_PUT_FIELD(s, iter->cpu);
2736 SEQ_PUT_FIELD_RET(s, iter->ts); 2733 SEQ_PUT_FIELD(s, iter->ts);
2734 if (trace_seq_has_overflowed(s))
2735 return TRACE_TYPE_PARTIAL_LINE;
2737 } 2736 }
2738 2737
2739 event = ftrace_find_event(entry->type); 2738 event = ftrace_find_event(entry->type);
@@ -2779,10 +2778,12 @@ enum print_line_t print_trace_line(struct trace_iterator *iter)
2779{ 2778{
2780 enum print_line_t ret; 2779 enum print_line_t ret;
2781 2780
2782 if (iter->lost_events && 2781 if (iter->lost_events) {
2783 !trace_seq_printf(&iter->seq, "CPU:%d [LOST %lu EVENTS]\n", 2782 trace_seq_printf(&iter->seq, "CPU:%d [LOST %lu EVENTS]\n",
2784 iter->cpu, iter->lost_events)) 2783 iter->cpu, iter->lost_events);
2785 return TRACE_TYPE_PARTIAL_LINE; 2784 if (trace_seq_has_overflowed(&iter->seq))
2785 return TRACE_TYPE_PARTIAL_LINE;
2786 }
2786 2787
2787 if (iter->trace && iter->trace->print_line) { 2788 if (iter->trace && iter->trace->print_line) {
2788 ret = iter->trace->print_line(iter); 2789 ret = iter->trace->print_line(iter);