All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>,
	Andrew Morton <akpm@linux-foundation.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Peter Zijlstra <peterz@infradead.org>,
	Frederic Weisbecker <fweisbec@gmail.com>
Subject: [PATCH 4/5] tracing/events/ring-buffer: expose format of ring buffer headers to users
Date: Wed, 15 Apr 2009 22:18:34 -0400	[thread overview]
Message-ID: <20090416021928.702433445@goodmis.org> (raw)
In-Reply-To: 20090416021830.556671772@goodmis.org

[-- Attachment #1: 0004-tracing-events-ring-buffer-expose-format-of-ring-bu.patch --]
[-- Type: text/plain, Size: 5429 bytes --]

From: Steven Rostedt <srostedt@redhat.com>

Currently, every thing needed to read the binary output from the
ring buffers is available, with the exception of the way the ring
buffers handles itself internally.

This patch creates two special files in the debugfs/tracing/events
directory:

 # cat /debug/tracing/events/header_page
        field: u64 timestamp;   offset:0;       size:8;
        field: local_t commit;  offset:8;       size:8;
        field: char data;       offset:16;      size:4080;

 # cat /debug/tracing/events/header_event
        type        :    2 bits
        len         :    3 bits
        time_delta  :   27 bits
        array       :   32 bits

        padding     : type == 0
        time_extend : type == 1
        data        : type == 3

This is to allow a userspace app to see if the ring buffer format changes
or not.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 include/linux/ring_buffer.h |    5 ++++
 kernel/trace/ring_buffer.c  |   44 +++++++++++++++++++++++++++++++++++++++++++
 kernel/trace/trace_events.c |   38 +++++++++++++++++++++++++++++++++++++
 3 files changed, 87 insertions(+), 0 deletions(-)

diff --git a/include/linux/ring_buffer.h b/include/linux/ring_buffer.h
index f0aa486..fac8f1a 100644
--- a/include/linux/ring_buffer.h
+++ b/include/linux/ring_buffer.h
@@ -166,6 +166,11 @@ void ring_buffer_free_read_page(struct ring_buffer *buffer, void *data);
 int ring_buffer_read_page(struct ring_buffer *buffer, void **data_page,
 			  size_t len, int cpu, int full);
 
+struct trace_seq;
+
+int ring_buffer_print_entry_header(struct trace_seq *s);
+int ring_buffer_print_page_header(struct trace_seq *s);
+
 enum ring_buffer_flags {
 	RB_FL_OVERWRITE		= 1 << 0,
 };
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index f935bd5..84a6055 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -22,6 +22,28 @@
 #include "trace.h"
 
 /*
+ * The ring buffer header is special. We must manually up keep it.
+ */
+int ring_buffer_print_entry_header(struct trace_seq *s)
+{
+	int ret;
+
+	ret = trace_seq_printf(s, "\ttype        :    2 bits\n");
+	ret = trace_seq_printf(s, "\tlen         :    3 bits\n");
+	ret = trace_seq_printf(s, "\ttime_delta  :   27 bits\n");
+	ret = trace_seq_printf(s, "\tarray       :   32 bits\n");
+	ret = trace_seq_printf(s, "\n");
+	ret = trace_seq_printf(s, "\tpadding     : type == %d\n",
+			       RINGBUF_TYPE_PADDING);
+	ret = trace_seq_printf(s, "\ttime_extend : type == %d\n",
+			       RINGBUF_TYPE_TIME_EXTEND);
+	ret = trace_seq_printf(s, "\tdata        : type == %d\n",
+			       RINGBUF_TYPE_DATA);
+
+	return ret;
+}
+
+/*
  * The ring buffer is made up of a list of pages. A separate list of pages is
  * allocated for each CPU. A writer may only write to a buffer that is
  * associated with the CPU it is currently executing on.  A reader may read
@@ -340,6 +362,28 @@ static inline int test_time_stamp(u64 delta)
 
 #define BUF_PAGE_SIZE (PAGE_SIZE - BUF_PAGE_HDR_SIZE)
 
+int ring_buffer_print_page_header(struct trace_seq *s)
+{
+	struct buffer_data_page field;
+	int ret;
+
+	ret = trace_seq_printf(s, "\tfield: u64 timestamp;\t"
+			       "offset:0;\tsize:%u;\n",
+			       (unsigned int)sizeof(field.time_stamp));
+
+	ret = trace_seq_printf(s, "\tfield: local_t commit;\t"
+			       "offset:%u;\tsize:%u;\n",
+			       (unsigned int)offsetof(typeof(field), commit),
+			       (unsigned int)sizeof(field.commit));
+
+	ret = trace_seq_printf(s, "\tfield: char data;\t"
+			       "offset:%u;\tsize:%u;\n",
+			       (unsigned int)offsetof(typeof(field), data),
+			       (unsigned int)BUF_PAGE_SIZE);
+
+	return ret;
+}
+
 /*
  * head_page == tail_page && head == tail then buffer is empty.
  */
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 6d5b1bd..96934f0 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -609,6 +609,30 @@ subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
 	return cnt;
 }
 
+static ssize_t
+show_header(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
+{
+	int (*func)(struct trace_seq *s) = filp->private_data;
+	struct trace_seq *s;
+	int r;
+
+	if (*ppos)
+		return 0;
+
+	s = kmalloc(sizeof(*s), GFP_KERNEL);
+	if (!s)
+		return -ENOMEM;
+
+	trace_seq_init(s);
+
+	func(s);
+	r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
+
+	kfree(s);
+
+	return r;
+}
+
 static const struct seq_operations show_event_seq_ops = {
 	.start = t_start,
 	.next = t_next,
@@ -666,6 +690,11 @@ static const struct file_operations ftrace_subsystem_filter_fops = {
 	.write = subsystem_filter_write,
 };
 
+static const struct file_operations ftrace_show_header_fops = {
+	.open = tracing_open_generic,
+	.read = show_header,
+};
+
 static struct dentry *event_trace_events_dir(void)
 {
 	static struct dentry *d_tracer;
@@ -908,6 +937,15 @@ static __init int event_trace_init(void)
 	if (!d_events)
 		return 0;
 
+	/* ring buffer internal formats */
+	trace_create_file("header_page", 0444, d_events,
+			  ring_buffer_print_page_header,
+			  &ftrace_show_header_fops);
+
+	trace_create_file("header_event", 0444, d_events,
+			  ring_buffer_print_entry_header,
+			  &ftrace_show_header_fops);
+
 	for_each_event(call, __start_ftrace_events, __stop_ftrace_events) {
 		/* The linker may leave blanks */
 		if (!call->name)
-- 
1.6.2.1

-- 

  parent reply	other threads:[~2009-04-16  2:21 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-16  2:18 [PATCH 0/5] [GIT PULL] updates for tip Steven Rostedt
2009-04-16  2:18 ` [PATCH 1/5] ftrace: use module notifier for function tracer Steven Rostedt
2009-04-16 15:36   ` Frederic Weisbecker
2009-04-16 15:53     ` Steven Rostedt
2009-04-17 11:44   ` Steven Rostedt
2009-04-19 11:25   ` Rusty Russell
2009-04-20 13:57     ` Steven Rostedt
2009-04-21  5:15       ` Rusty Russell
2009-04-21 13:13         ` Steven Rostedt
2009-04-21 13:58           ` Ingo Molnar
2009-04-21 17:51     ` Tim Abbott
2009-04-21 18:17       ` Steven Rostedt
2009-04-21 18:47         ` Tim Abbott
2009-04-22  9:16       ` Ingo Molnar
2009-04-22 22:20         ` Tim Abbott
2009-04-22 22:57           ` Masami Hiramatsu
2009-04-23 19:40             ` Anders Kaseorg
2009-04-23 19:57               ` Mathieu Desnoyers
2009-04-23 22:31                 ` Tim Abbott
2009-04-24  3:11                   ` Masami Hiramatsu
2009-04-23 20:06               ` Masami Hiramatsu
2009-04-16  2:18 ` [PATCH 2/5] tracing/events: add startup tests for events Steven Rostedt
2009-04-16  8:39   ` [PATCH] tracing: add #include <linux/delay.h> to fix build failure in test_work() Ingo Molnar
2009-04-16 14:08     ` Steven Rostedt
2009-04-17  0:30       ` Ingo Molnar
2009-04-16 15:41   ` [PATCH 2/5] tracing/events: add startup tests for events Frederic Weisbecker
2009-04-16 15:51     ` Steven Rostedt
2009-04-16 16:02   ` Frederic Weisbecker
2009-04-16  2:18 ` [PATCH 3/5] tracing/events: add rcu locking around trace event prints Steven Rostedt
2009-04-17 14:08   ` Steven Rostedt
2009-04-17 15:20     ` Jeremy Fitzhardinge
2009-04-17 15:42       ` Steven Rostedt
2009-04-17 23:53         ` Jeremy Fitzhardinge
2009-04-17 16:18     ` Theodore Tso
2009-04-17 16:32       ` Jeremy Fitzhardinge
2009-04-17 16:41         ` Steven Rostedt
2009-05-07  2:10   ` Steven Rostedt
2009-05-07 11:32     ` Ingo Molnar
2009-05-07 13:10       ` Steven Rostedt
2009-04-16  2:18 ` Steven Rostedt [this message]
2009-04-16  2:18 ` [PATCH 5/5] tracing: add saved_cmdlines file to show cached task comms Steven Rostedt
2009-04-16 15:54   ` Frederic Weisbecker
2009-04-16 15:58     ` Steven Rostedt
2009-04-16 16:05       ` Frederic Weisbecker
2009-04-16  9:51 ` [PATCH 0/5] [GIT PULL] updates for tip Ingo Molnar
2009-04-16  9:53   ` Ingo Molnar
2009-04-16 13:52   ` Steven Rostedt
2009-04-16 16:12     ` Ingo Molnar
2009-04-16 16:22       ` Steven Rostedt
2009-04-17  0:29         ` Ingo Molnar
2009-04-16 16:30       ` 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=20090416021928.702433445@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.