From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>,
Andrew Morton <akpm@linux-foundation.org>,
Peter Zijlstra <peterz@infradead.org>,
Frederic Weisbecker <fweisbec@gmail.com>,
Lai Jiangshan <laijs@cn.fujitsu.com>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
Steven Rostedt <srostedt@redhat.com>
Subject: [PATCH 09/16] tracing: export trace formats to user space
Date: Thu, 12 Mar 2009 22:37:13 -0400 [thread overview]
Message-ID: <20090313023826.694210967@goodmis.org> (raw)
In-Reply-To: 20090313023704.971438367@goodmis.org
[-- Attachment #1: 0009-tracing-export-trace-formats-to-user-space.patch --]
[-- Type: text/plain, Size: 3760 bytes --]
From: Steven Rostedt <srostedt@redhat.com>
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 | 119 +++++++++++++++++++++++++++++++++++++++++--
1 files changed, 114 insertions(+), 5 deletions(-)
diff --git a/kernel/trace/trace_printk.c b/kernel/trace/trace_printk.c
index f307a11..4867852 100644
--- a/kernel/trace/trace_printk.c
+++ b/kernel/trace/trace_printk.c
@@ -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);
--
1.6.1.3
--
next prev parent reply other threads:[~2009-03-13 2:45 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-03-13 2:37 [PATCH 00/16] [GIT PULL] updates for tip/tracing/ftrace Steven Rostedt
2009-03-13 2:37 ` [PATCH 01/16] tracing: fix comments about trace buffer resizing Steven Rostedt
2009-03-13 2:37 ` [PATCH 02/16] tracing: protect ring_buffer_expanded with trace_types_lock Steven Rostedt
2009-03-13 2:37 ` [PATCH 03/16] ring-buffer: use CONFIG_HOTPLUG_CPU not CONFIG_HOTPLUG Steven Rostedt
2009-03-13 2:37 ` [PATCH 04/16] ring-buffer: remove unneeded get_online_cpus Steven Rostedt
2009-03-13 2:37 ` [PATCH 05/16] tracing: show that buffer size is not expanded Steven Rostedt
2009-03-13 3:05 ` KOSAKI Motohiro
2009-03-13 3:20 ` Steven Rostedt
2009-03-13 3:28 ` KOSAKI Motohiro
2009-03-13 2:37 ` [PATCH 06/16] tracing/core: bring back raw trace_printk for dynamic formats strings Steven Rostedt
2009-03-13 2:37 ` [PATCH 07/16] tracing: make bprint event use the proper event id Steven Rostedt
2009-03-13 2:37 ` [PATCH 08/16] tracing: have event_trace_printk use static tracer Steven Rostedt
2009-03-13 2:49 ` Andrew Morton
2009-03-13 3:08 ` Steven Rostedt
2009-03-13 3:09 ` KOSAKI Motohiro
2009-03-13 3:17 ` Steven Rostedt
2009-03-13 3:28 ` KOSAKI Motohiro
2009-03-13 3:34 ` Steven Rostedt
2009-03-13 5:36 ` [tip:tracing/ftrace] tracing: add comment for use of double __builtin_consant_p Steven Rostedt
2009-03-13 2:37 ` Steven Rostedt [this message]
2009-03-13 15:03 ` [PATCH 09/16] tracing: export trace formats to user space Frederic Weisbecker
2009-03-13 2:37 ` [PATCH 10/16] tracing: fix stack tracer header Steven Rostedt
2009-03-13 2:37 ` [PATCH 11/16] tracing: explain why stack tracer is empty Steven Rostedt
2009-03-13 2:37 ` [PATCH 12/16] tracing: tracepoints for softirq entry/exit - add softirq-to-name array Steven Rostedt
2009-03-13 4:12 ` Andrew Morton
2009-03-13 4:22 ` Steven Rostedt
2009-03-13 2:37 ` [PATCH 13/16] tracing: tracepoints for softirq entry/exit - tracepoints Steven Rostedt
2009-03-13 2:37 ` [PATCH 14/16] tracing: Dont use tracing_record_cmdline() in workqueue tracer fix Steven Rostedt
2009-03-13 2:37 ` [PATCH 15/16] tracing: show event name in trace for TRACE_EVENT created events Steven Rostedt
2009-03-13 2:37 ` [PATCH 16/16] ring-buffer: document reader page design Steven Rostedt
2009-03-13 3:35 ` [PATCH 00/16] [GIT PULL] updates for tip/tracing/ftrace Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20090313023826.694210967@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=fweisbec@gmail.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
--cc=srostedt@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox