Skip to contentSkip to conversation

Simple LTTng userspace events through debugfs

PATCH In review Mathieu Desnoyers 4 participants 6 messages Dec 15, 2008 – Dec 18, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Simple LTTng userspace events through debugfs

Hi,

I looked at kmemtrace and noticed that the presence of a debugfs "marker" file, which lets userspace write events into the trace buffers.

So I just did the same with a

/debugfs/ltt/write_event

file in LTTng. This should be OK for userspace tracing which does not require high throughput. It allows userspace to write a string up to 4095-bytes long into the channel named "userspace", event named "event".

This new feature is available in LTTng 0.68 (for kernel 2.6.27.9). For the curious, I provide the patch applied on top of the LTTng tree below.

Mathieu

LTTng userspace event

Add userspace event support to LTTng.

Simply has to write to :

/debugfs/ltt/write_event

E.g. :

echo "Error X happened !" > /debugfs/ltt/write_event

(assuming debugfs is mounted under /debugfs)

Todo :
Maybe use ltt_relay_user_blocking to block if channel is full rather than losing an event ? Be careful about effect of stopped tracing on userspace...

---
 ltt/Kconfig               |    9 +++
 ltt/Makefile              |    1 
 ltt/ltt-userspace-event.c |  120 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 130 insertions(+)
ltt/Kconfig +9 -0
Index: linux-2.6-lttng/ltt/Kconfig
===================================================================
@@ -125,6 +125,15 @@ config LTT_DEBUG_EVENT_SIZE
 	help
 	  Tracer-internal option to help debugging event type encoding problems.
 
+config LTT_USERSPACE_EVENT
+	tristate "Support logging events from userspace"
+	depends on LTT_TRACER
+	depends on LTT_TRACEPROBES
+	default m
+	help
+	  This option lets userspace write text events in
+	  /debugfs/ltt/write_event.
+
 config LTT_VMCORE
 	bool "Support trace extraction from crash dump"
 	default y
ltt/Makefile +1 -0
Index: linux-2.6-lttng/ltt/Makefile
===================================================================
@@ -5,6 +5,7 @@
 obj-$(CONFIG_MARKERS)			+= ltt-channels.o
 obj-$(CONFIG_LTT)			+= ltt-core.o
 obj-$(CONFIG_LTT_TRACER)		+= ltt-tracer.o
+obj-$(CONFIG_LTT_USERSPACE_EVENT)	+= ltt-userspace-event.o
 obj-$(CONFIG_LTT_RELAY)			+= ltt-relay.o
 obj-$(CONFIG_LTT_RELAY_LOCKED)		+= ltt-relay-locked.o
 obj-$(CONFIG_LTT_RELAY_ALLOC)		+= ltt-relay-alloc.o
ltt/ltt-userspace-event.c new file +120 -0

120 lines not on this page · raw message

Signature · 2 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
#1 lore raw
Quoted 8 lines · Mathieu Desnoyers

Hi,

I looked at kmemtrace and noticed that the presence of a debugfs "marker" file, which lets userspace write events into the trace buffers.

So I just did the same with a

/debugfs/ltt/write_event

you mean similar to ftrace's /debug/tracing/trace_marker ? ;-)

Ingo

#2 lore raw
Quoted 5 lines · * Ingo Molnar ([email protected]) wrote:
Quoted 2 lines · Mathieu Desnoyers

Hi,

Quoted 9 lines
Quoted 6 lines

I looked at kmemtrace and noticed that the presence of a debugfs "marker" file, which lets userspace write events into the trace buffers.

So I just did the same with a

/debugfs/ltt/write_event

you mean similar to ftrace's /debug/tracing/trace_marker ? ;-)

Quite similar, yes :)

Looking at tracing_mark_write(), I am wondering if the fact that it returns a count including the added \n is an expected side effect ? A write() returning a count larger than the number of bytes written seems to be a bit unexpected... But if we remove the \n from the count, then the case where one write \0 into the event content would end up doing an endless loop.

Mathieu

Quoted 7 lines

Ingo

_______________________________________________
ltt-dev mailing list
[email protected]
http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev

Signature · 2 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
#3 lore raw
Quoted 16 lines · * Mathieu Desnoyers ([email protected]) wrote:
Quoted 5 lines · * Ingo Molnar ([email protected]) wrote:
Quoted 2 lines · Mathieu Desnoyers

Hi,

Quoted 9 lines
Quoted 6 lines

I looked at kmemtrace and noticed that the presence of a debugfs "marker" file, which lets userspace write events into the trace buffers.

So I just did the same with a

/debugfs/ltt/write_event

you mean similar to ftrace's /debug/tracing/trace_marker ? ;-)

Quoted 9 lines

Quite similar, yes :)

Looking at tracing_mark_write(), I am wondering if the fact that it returns a count including the added \n is an expected side effect ? A write() returning a count larger than the number of bytes written seems to be a bit unexpected... But if we remove the \n from the count, then the case where one write \0 into the event content would end up doing an endless loop.

I fixed this in the following implementation for LTTng. Made an hybrid of both approaches, using \n and \0 as string delimiter, and fixed the problem with returned count larger than the requested count.

LTTng userspace event v2

Add userspace event support to LTTng.

Simply has to write to :

/debugfs/ltt/write_event

E.g. :

echo "Error X happened !" > /debugfs/ltt/write_event

(assuming debugfs is mounted under /debugfs)

Todo :
Maybe use ltt_relay_user_blocking to block if channel is full rather than losing an event ? Be careful about effect of stopped tracing on userspace...

Changelog :
- Support correctly when multiple strings are sent to the same write.
- Cut the strings at each \n or \0.
- Made sure we never return a count value larger than the requested count. Count is counting the number of _source_ data used, not the number of trace bytes written.

---
 ltt/Kconfig               |    9 +++
 ltt/Makefile              |    1 
 ltt/ltt-userspace-event.c |  129 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 139 insertions(+)
ltt/Kconfig +9 -0
Index: linux-2.6-lttng/ltt/Kconfig
===================================================================
@@ -125,6 +125,15 @@ config LTT_DEBUG_EVENT_SIZE
 	help
 	  Tracer-internal option to help debugging event type encoding problems.
 
+config LTT_USERSPACE_EVENT
+	tristate "Support logging events from userspace"
+	depends on LTT_TRACER
+	depends on LTT_TRACEPROBES
+	default m
+	help
+	  This option lets userspace write text events in
+	  /debugfs/ltt/write_event.
+
 config LTT_VMCORE
 	bool "Support trace extraction from crash dump"
 	default y
ltt/Makefile +1 -0
Index: linux-2.6-lttng/ltt/Makefile
===================================================================
@@ -5,6 +5,7 @@
 obj-$(CONFIG_MARKERS)			+= ltt-channels.o
 obj-$(CONFIG_LTT)			+= ltt-core.o
 obj-$(CONFIG_LTT_TRACER)		+= ltt-tracer.o
+obj-$(CONFIG_LTT_USERSPACE_EVENT)	+= ltt-userspace-event.o
 obj-$(CONFIG_LTT_RELAY)			+= ltt-relay.o
 obj-$(CONFIG_LTT_RELAY_LOCKED)		+= ltt-relay-locked.o
 obj-$(CONFIG_LTT_RELAY_ALLOC)		+= ltt-relay-alloc.o
ltt/ltt-userspace-event.c new file +129 -0

129 lines not on this page · raw message

Signature · 2 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
#4 lore raw

ltt/ltt-userspace-event.c line 3

Quoted 8 lines · On Wed, 17 Dec 2008 12:32:24 -0500 Mathieu Desnoyers wrote:

Index: linux-2.6-lttng/ltt/ltt-userspace-event.c
===================================================================

ltt/ltt-userspace-event.c new file +3 -0
@@ -0,0 +1,129 @@
+
+/**
+ * write_event: write a userspace string into the trace stream

Hi Mathieu,

Please make above line:

* write_event - write a userspace string into the trace system

Thanks.

Quoted 6 lines
ltt/ltt-userspace-event.c new file +6 -0
+ * @file: file pointer
+ * @user_buf: user string
+ * @count: length to copy, including the final NULL
+ * @ppos: unused
+ *
+ * Copy a string into a trace event, in channel "userspace", event "event".

ltt/ltt-userspace-event.c line 50

Quoted 10 lines
ltt/ltt-userspace-event.c new file +10 -0
+ * Copies until either \n or \0 is reached.
+ * On success, returns the number of bytes copied from the source, including the
+ * \n or \0 character (if there was one in the count range). It cannot return
+ * more than count.
+ * Inspired from tracing_mark_write implementation from Steven Rostedt and
+ * Ingo Molnar.
+ */
+static ssize_t write_event(struct file *file, const char __user *user_buf,
+		size_t count, loff_t *ppos)
+{

---
~Randy

#5 lore raw
Quoted 13 lines · * Randy Dunlap ([email protected]) wrote:

ltt/ltt-userspace-event.c line 3

Quoted 8 lines · On Wed, 17 Dec 2008 12:32:24 -0500 Mathieu Desnoyers wrote:

Index: linux-2.6-lttng/ltt/ltt-userspace-event.c
===================================================================

ltt/ltt-userspace-event.c new file +3 -0
@@ -0,0 +1,129 @@
+
+/**
+ * write_event: write a userspace string into the trace stream

Hi Mathieu,

Quoted 4 lines

Please make above line:

* write_event - write a userspace string into the trace system

That for the review,

I'll have to go through all the LTTng tree and fix the kerneldoc.

Mathieu

Quoted 23 lines

Thanks.

Quoted 6 lines
ltt/ltt-userspace-event.c new file +6 -0
+ * @file: file pointer
+ * @user_buf: user string
+ * @count: length to copy, including the final NULL
+ * @ppos: unused
+ *
+ * Copy a string into a trace event, in channel "userspace", event "event".

ltt/ltt-userspace-event.c line 50

Quoted 10 lines
ltt/ltt-userspace-event.c new file +10 -0
+ * Copies until either \n or \0 is reached.
+ * On success, returns the number of bytes copied from the source, including the
+ * \n or \0 character (if there was one in the count range). It cannot return
+ * more than count.
+ * Inspired from tracing_mark_write implementation from Steven Rostedt and
+ * Ingo Molnar.
+ */
+static ssize_t write_event(struct file *file, const char __user *user_buf,
+		size_t count, loff_t *ppos)
+{

---
~Randy

Signature · 2 lines
Mathieu Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68