]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
tracing: export trace formats to user space
authorSteven Rostedt <srostedt@redhat.com>
Thu, 12 Mar 2009 18:23:17 +0000 (14:23 -0400)
committerSteven Rostedt <srostedt@redhat.com>
Fri, 13 Mar 2009 01:15:01 +0000 (21:15 -0400)
The binary printk saves a pointer to the format string in the ring buffer.
On output, the format is processed. But if the user is reading the
ring buffer through a binary interface, the pointer is meaningless.

This patch creates a file called printk_formats that maps the pointers
to the formats.

 # cat /debug/tracing/printk_formats
0xffffffff80713d40 : "irq_handler_entry: irq=%d handler=%s\n"
0xffffffff80713d48 : "lock_acquire: %s%s%s\n"
0xffffffff80713d50 : "lock_release: %s\n"

Signed-off-by: Steven Rostedt <srostedt@redhat.com>
kernel/trace/trace_printk.c

index f307a11e23325e030c1091fe42b92972fd9c9349..486785214e3ecaaff82ff78b2f64f9171888513e 100644 (file)
@@ -4,18 +4,19 @@
  * Copyright (C) 2008 Lai Jiangshan <laijs@cn.fujitsu.com>
  *
  */
+#include <linux/seq_file.h>
+#include <linux/debugfs.h>
+#include <linux/uaccess.h>
 #include <linux/kernel.h>
 #include <linux/ftrace.h>
 #include <linux/string.h>
+#include <linux/module.h>
+#include <linux/marker.h>
+#include <linux/mutex.h>
 #include <linux/ctype.h>
 #include <linux/list.h>
-#include <linux/mutex.h>
 #include <linux/slab.h>
-#include <linux/module.h>
-#include <linux/seq_file.h>
 #include <linux/fs.h>
-#include <linux/marker.h>
-#include <linux/uaccess.h>
 
 #include "trace.h"
 
@@ -153,6 +154,114 @@ int __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap)
 }
 EXPORT_SYMBOL_GPL(__ftrace_vprintk);
 
+static void *
+t_next(struct seq_file *m, void *v, loff_t *pos)
+{
+       const char **fmt = m->private;
+       const char **next = fmt;
+
+       (*pos)++;
+
+       if ((unsigned long)fmt >= (unsigned long)__stop___trace_bprintk_fmt)
+               return NULL;
+
+       next = fmt;
+       m->private = ++next;
+
+       return fmt;
+}
+
+static void *t_start(struct seq_file *m, loff_t *pos)
+{
+       return t_next(m, NULL, pos);
+}
+
+static int t_show(struct seq_file *m, void *v)
+{
+       const char **fmt = v;
+       const char *str = *fmt;
+       int i;
+
+       seq_printf(m, "0x%lx : \"", (unsigned long)fmt);
+
+       /*
+        * Tabs and new lines need to be converted.
+        */
+       for (i = 0; str[i]; i++) {
+               switch (str[i]) {
+               case '\n':
+                       seq_puts(m, "\\n");
+                       break;
+               case '\t':
+                       seq_puts(m, "\\t");
+                       break;
+               case '\\':
+                       seq_puts(m, "\\");
+                       break;
+               case '"':
+                       seq_puts(m, "\\\"");
+                       break;
+               default:
+                       seq_putc(m, str[i]);
+               }
+       }
+       seq_puts(m, "\"\n");
+
+       return 0;
+}
+
+static void t_stop(struct seq_file *m, void *p)
+{
+}
+
+static const struct seq_operations show_format_seq_ops = {
+       .start = t_start,
+       .next = t_next,
+       .show = t_show,
+       .stop = t_stop,
+};
+
+static int
+ftrace_formats_open(struct inode *inode, struct file *file)
+{
+       int ret;
+
+       ret = seq_open(file, &show_format_seq_ops);
+       if (!ret) {
+               struct seq_file *m = file->private_data;
+
+               m->private = __start___trace_bprintk_fmt;
+       }
+       return ret;
+}
+
+static const struct file_operations ftrace_formats_fops = {
+       .open = ftrace_formats_open,
+       .read = seq_read,
+       .llseek = seq_lseek,
+       .release = seq_release,
+};
+
+static __init int init_trace_printk_function_export(void)
+{
+       struct dentry *d_tracer;
+       struct dentry *entry;
+
+       d_tracer = tracing_init_dentry();
+       if (!d_tracer)
+               return 0;
+
+       entry = debugfs_create_file("printk_formats", 0444, d_tracer,
+                                   NULL, &ftrace_formats_fops);
+       if (!entry)
+               pr_warning("Could not create debugfs "
+                          "'printk_formats' entry\n");
+
+       return 0;
+}
+
+fs_initcall(init_trace_printk_function_export);
+
 static __init int init_trace_printk(void)
 {
        return register_module_notifier(&module_trace_bprintk_format_nb);