aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace/trace.c
diff options
context:
space:
mode:
authorDavid Sharp <dhsharp@google.com>2010-12-08 16:46:47 -0500
committerSteven Rostedt <rostedt@goodmis.org>2011-03-09 13:52:27 -0500
commit750912fa366312e9c5bc83eab352898a26750401 (patch)
treebb8e5cd1444a74ea283e3fa55607225e7fda4d70 /kernel/trace/trace.c
parent2a8247a2600c3e087a568fc68a6ec4eedac27ef1 (diff)
tracing: Add an 'overwrite' trace_option.
Add an "overwrite" trace_option for ftrace to control whether the buffer should be overwritten on overflow or not. The default remains to overwrite old events when the buffer is full. This patch adds the option to instead discard newest events when the buffer is full. This is useful to get a snapshot of traces just after enabling traces. Dropping the current event is also a simpler code path. Signed-off-by: David Sharp <dhsharp@google.com> LKML-Reference: <1291844807-15481-1-git-send-email-dhsharp@google.com> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'kernel/trace/trace.c')
-rw-r--r--kernel/trace/trace.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 8dc8da6733f9..85e3ee1e474e 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -41,8 +41,6 @@
41#include "trace.h" 41#include "trace.h"
42#include "trace_output.h" 42#include "trace_output.h"
43 43
44#define TRACE_BUFFER_FLAGS (RB_FL_OVERWRITE)
45
46/* 44/*
47 * On boot up, the ring buffer is set to the minimum size, so that 45 * On boot up, the ring buffer is set to the minimum size, so that
48 * we do not waste memory on systems that are not using tracing. 46 * we do not waste memory on systems that are not using tracing.
@@ -340,7 +338,7 @@ static DECLARE_WAIT_QUEUE_HEAD(trace_wait);
340/* trace_flags holds trace_options default values */ 338/* trace_flags holds trace_options default values */
341unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK | 339unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
342 TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME | 340 TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO | TRACE_ITER_SLEEP_TIME |
343 TRACE_ITER_GRAPH_TIME | TRACE_ITER_RECORD_CMD; 341 TRACE_ITER_GRAPH_TIME | TRACE_ITER_RECORD_CMD | TRACE_ITER_OVERWRITE;
344 342
345static int trace_stop_count; 343static int trace_stop_count;
346static DEFINE_SPINLOCK(tracing_start_lock); 344static DEFINE_SPINLOCK(tracing_start_lock);
@@ -425,6 +423,7 @@ static const char *trace_options[] = {
425 "sleep-time", 423 "sleep-time",
426 "graph-time", 424 "graph-time",
427 "record-cmd", 425 "record-cmd",
426 "overwrite",
428 NULL 427 NULL
429}; 428};
430 429
@@ -2529,6 +2528,9 @@ static void set_tracer_flags(unsigned int mask, int enabled)
2529 2528
2530 if (mask == TRACE_ITER_RECORD_CMD) 2529 if (mask == TRACE_ITER_RECORD_CMD)
2531 trace_event_enable_cmd_record(enabled); 2530 trace_event_enable_cmd_record(enabled);
2531
2532 if (mask == TRACE_ITER_OVERWRITE)
2533 ring_buffer_change_overwrite(global_trace.buffer, enabled);
2532} 2534}
2533 2535
2534static ssize_t 2536static ssize_t
@@ -4555,9 +4557,11 @@ void ftrace_dump(enum ftrace_dump_mode oops_dump_mode)
4555__init static int tracer_alloc_buffers(void) 4557__init static int tracer_alloc_buffers(void)
4556{ 4558{
4557 int ring_buf_size; 4559 int ring_buf_size;
4560 enum ring_buffer_flags rb_flags;
4558 int i; 4561 int i;
4559 int ret = -ENOMEM; 4562 int ret = -ENOMEM;
4560 4563
4564
4561 if (!alloc_cpumask_var(&tracing_buffer_mask, GFP_KERNEL)) 4565 if (!alloc_cpumask_var(&tracing_buffer_mask, GFP_KERNEL))
4562 goto out; 4566 goto out;
4563 4567
@@ -4570,12 +4574,13 @@ __init static int tracer_alloc_buffers(void)
4570 else 4574 else
4571 ring_buf_size = 1; 4575 ring_buf_size = 1;
4572 4576
4577 rb_flags = trace_flags & TRACE_ITER_OVERWRITE ? RB_FL_OVERWRITE : 0;
4578
4573 cpumask_copy(tracing_buffer_mask, cpu_possible_mask); 4579 cpumask_copy(tracing_buffer_mask, cpu_possible_mask);
4574 cpumask_copy(tracing_cpumask, cpu_all_mask); 4580 cpumask_copy(tracing_cpumask, cpu_all_mask);
4575 4581
4576 /* TODO: make the number of buffers hot pluggable with CPUS */ 4582 /* TODO: make the number of buffers hot pluggable with CPUS */
4577 global_trace.buffer = ring_buffer_alloc(ring_buf_size, 4583 global_trace.buffer = ring_buffer_alloc(ring_buf_size, rb_flags);
4578 TRACE_BUFFER_FLAGS);
4579 if (!global_trace.buffer) { 4584 if (!global_trace.buffer) {
4580 printk(KERN_ERR "tracer: failed to allocate ring buffer!\n"); 4585 printk(KERN_ERR "tracer: failed to allocate ring buffer!\n");
4581 WARN_ON(1); 4586 WARN_ON(1);
@@ -4585,7 +4590,7 @@ __init static int tracer_alloc_buffers(void)
4585 4590
4586 4591
4587#ifdef CONFIG_TRACER_MAX_TRACE 4592#ifdef CONFIG_TRACER_MAX_TRACE
4588 max_tr.buffer = ring_buffer_alloc(1, TRACE_BUFFER_FLAGS); 4593 max_tr.buffer = ring_buffer_alloc(1, rb_flags);
4589 if (!max_tr.buffer) { 4594 if (!max_tr.buffer) {
4590 printk(KERN_ERR "tracer: failed to allocate max ring buffer!\n"); 4595 printk(KERN_ERR "tracer: failed to allocate max ring buffer!\n");
4591 WARN_ON(1); 4596 WARN_ON(1);