This patch adds an interface into debugfs. /debugfs/tracing/ctrl echoing 1 into the ctrl file turns on the tracer, and echoing 0 turns it off. Signed-off-by: Steven Rostedt --- lib/tracing/tracer.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++- lib/tracing/tracer.h | 1 2 files changed, 87 insertions(+), 1 deletion(-) Index: linux-compile-i386.git/lib/tracing/tracer.c =================================================================== --- linux-compile-i386.git.orig/lib/tracing/tracer.c 2008-01-09 14:10:46.000000000 -0500 +++ linux-compile-i386.git/lib/tracing/tracer.c 2008-01-09 15:17:43.000000000 -0500 @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include "tracer.h" @@ -71,6 +73,89 @@ static notrace void trace_function(const raw_local_irq_restore(flags); } +#ifdef CONFIG_DEBUG_FS +static int mctracer_open_generic(struct inode *inode, struct file *filp) +{ + filp->private_data = inode->i_private; + return 0; +} + + +static ssize_t mctracer_ctrl_read(struct file *filp, char __user *ubuf, + size_t cnt, loff_t *ppos) +{ + struct mctracer_trace *tr = filp->private_data; + char buf[16]; + int r; + + r = sprintf(buf, "%ld\n", tr->ctrl); + return simple_read_from_buffer(ubuf, cnt, ppos, + buf, r); +} + +static ssize_t mctracer_ctrl_write(struct file *filp, + const char __user *ubuf, + size_t cnt, loff_t *ppos) +{ + struct mctracer_trace *tr = filp->private_data; + long val; + char buf[16]; + + if (cnt > 15) + cnt = 15; + + if (copy_from_user(&buf, ubuf, cnt)) + return -EFAULT; + + buf[cnt] = 0; + + val = !!simple_strtoul(buf, NULL, 10); + + if (tr->ctrl ^ val) { + if (val) + register_mcount_function(trace_function); + else + clear_mcount_function(); + tr->ctrl = val; + } + + filp->f_pos += cnt; + + return cnt; +} + +static struct file_operations mctracer_ctrl_fops = { + .open = mctracer_open_generic, + .read = mctracer_ctrl_read, + .write = mctracer_ctrl_write, +}; + +static void mctrace_init_debugfs(void) +{ + struct dentry *d_mctracer; + struct dentry *entry; + + d_mctracer = debugfs_create_dir("tracing", NULL); + if (!d_mctracer) { + pr_warning("Could not create debugfs directory mctracer\n"); + return; + } + + entry = debugfs_create_file("ctrl", 0644, d_mctracer, + &mctracer_trace, &mctracer_ctrl_fops); + if (!entry) + pr_warning("Could not create debugfs 'ctrl' entry\n"); +} +#else /* CONFIG_DEBUG_FS */ +static void mctrace_init_debugfs(void) +{ + /* + * No way to turn on or off the trace function + * without debugfs, so we just turn it on. + */ + register_mcount_function(trace_function); +} +#endif /* CONFIG_DEBUG_FS */ static notrace int page_order(const unsigned long size) { @@ -106,7 +191,7 @@ static notrace int mctracer_alloc_buffer size, MCTRACER_NR_ENTRIES, MCTRACER_ENTRY_SIZE); pr_info(" actual entries %ld\n", mctracer_trace.entries); - register_mcount_function(trace_function); + mctrace_init_debugfs(); return 0; Index: linux-compile-i386.git/lib/tracing/tracer.h =================================================================== --- linux-compile-i386.git.orig/lib/tracing/tracer.h 2008-01-09 14:10:46.000000000 -0500 +++ linux-compile-i386.git/lib/tracing/tracer.h 2008-01-09 15:17:41.000000000 -0500 @@ -13,6 +13,7 @@ struct mctracer_trace { void *trace[NR_CPUS]; unsigned long trace_idx[NR_CPUS]; unsigned long entries; + long ctrl; atomic_t cnt; atomic_t disabled[NR_CPUS]; atomic_t underrun[NR_CPUS]; -- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/