tracing: give easy way to clear trace buffer

There is currently no easy way to clear the trace buffer. Currently
the only way is to change the current tracer.

This patch lets the user clear the trace buffer by simply writing
into the trace files.

 echo > /debug/tracing/trace

or to clear a single cpu (i.e. for CPU 1):

 echo > /debug/tracing/per_cpu/cpu1/trace

Requested-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
This commit is contained in:
Steven Rostedt 2009-03-18 10:40:24 -04:00
parent 4903620034
commit 4acd4d00f7

View File

@ -1941,9 +1941,14 @@ int tracing_open_generic(struct inode *inode, struct file *filp)
static int tracing_release(struct inode *inode, struct file *file) static int tracing_release(struct inode *inode, struct file *file)
{ {
struct seq_file *m = (struct seq_file *)file->private_data; struct seq_file *m = (struct seq_file *)file->private_data;
struct trace_iterator *iter = m->private; struct trace_iterator *iter;
int cpu; int cpu;
if (!(file->f_mode & FMODE_READ))
return 0;
iter = m->private;
mutex_lock(&trace_types_lock); mutex_lock(&trace_types_lock);
for_each_tracing_cpu(cpu) { for_each_tracing_cpu(cpu) {
if (iter->buffer_iter[cpu]) if (iter->buffer_iter[cpu])
@ -1969,12 +1974,24 @@ static int tracing_open(struct inode *inode, struct file *file)
struct trace_iterator *iter; struct trace_iterator *iter;
int ret = 0; int ret = 0;
iter = __tracing_open(inode, file); /* If this file was open for write, then erase contents */
if (IS_ERR(iter)) if ((file->f_mode & FMODE_WRITE) &&
ret = PTR_ERR(iter); !(file->f_flags & O_APPEND)) {
else if (trace_flags & TRACE_ITER_LATENCY_FMT) long cpu = (long) inode->i_private;
iter->iter_flags |= TRACE_FILE_LAT_FMT;
if (cpu == TRACE_PIPE_ALL_CPU)
tracing_reset_online_cpus(&global_trace);
else
tracing_reset(&global_trace, cpu);
}
if (file->f_mode & FMODE_READ) {
iter = __tracing_open(inode, file);
if (IS_ERR(iter))
ret = PTR_ERR(iter);
else if (trace_flags & TRACE_ITER_LATENCY_FMT)
iter->iter_flags |= TRACE_FILE_LAT_FMT;
}
return ret; return ret;
} }
@ -2049,9 +2066,17 @@ static int show_traces_open(struct inode *inode, struct file *file)
return ret; return ret;
} }
static ssize_t
tracing_write_stub(struct file *filp, const char __user *ubuf,
size_t count, loff_t *ppos)
{
return count;
}
static const struct file_operations tracing_fops = { static const struct file_operations tracing_fops = {
.open = tracing_open, .open = tracing_open,
.read = seq_read, .read = seq_read,
.write = tracing_write_stub,
.llseek = seq_lseek, .llseek = seq_lseek,
.release = tracing_release, .release = tracing_release,
}; };
@ -3576,7 +3601,7 @@ static void tracing_init_debugfs_percpu(long cpu)
pr_warning("Could not create debugfs 'trace_pipe' entry\n"); pr_warning("Could not create debugfs 'trace_pipe' entry\n");
/* per cpu trace */ /* per cpu trace */
entry = debugfs_create_file("trace", 0444, d_cpu, entry = debugfs_create_file("trace", 0644, d_cpu,
(void *) cpu, &tracing_fops); (void *) cpu, &tracing_fops);
if (!entry) if (!entry)
pr_warning("Could not create debugfs 'trace' entry\n"); pr_warning("Could not create debugfs 'trace' entry\n");
@ -3890,7 +3915,7 @@ static __init int tracer_init_debugfs(void)
if (!entry) if (!entry)
pr_warning("Could not create debugfs 'tracing_cpumask' entry\n"); pr_warning("Could not create debugfs 'tracing_cpumask' entry\n");
entry = debugfs_create_file("trace", 0444, d_tracer, entry = debugfs_create_file("trace", 0644, d_tracer,
(void *) TRACE_PIPE_ALL_CPU, &tracing_fops); (void *) TRACE_PIPE_ALL_CPU, &tracing_fops);
if (!entry) if (!entry)
pr_warning("Could not create debugfs 'trace' entry\n"); pr_warning("Could not create debugfs 'trace' entry\n");