Re: [PATCH] Simple LTTng userspace events through debugfs

Previous thread: RE: [patch 0/7] x86 PAT: v2 - track pfnmap mappings with remap_pfn_range and vm_insert_pfn by Pallipadi, Venkatesh on Monday, December 15, 2008 - 2:50 pm. (7 messages)

Next thread: driver probe error reporting by Ben Dooks on Monday, December 15, 2008 - 4:15 pm. (7 messages)
From: Mathieu Desnoyers
Date: Monday, December 15, 2008 - 4:10 pm

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...

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
---
 ltt/Kconfig               |    9 +++
 ltt/Makefile              |    1 
 ltt/ltt-userspace-event.c |  120 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 130 insertions(+)

Index: linux-2.6-lttng/ltt/Kconfig
===================================================================
--- linux-2.6-lttng.orig/ltt/Kconfig	2008-12-15 16:18:04.000000000 -0500
+++ linux-2.6-lttng/ltt/Kconfig	2008-12-15 16:18:08.000000000 -0500
@@ -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
Index: ...
From: Ingo Molnar
Date: Tuesday, December 16, 2008 - 12:42 pm

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

	Ingo
--

From: Mathieu Desnoyers
Date: Tuesday, December 16, 2008 - 9:16 pm

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 Desnoyers
OpenPGP key fingerprint: 8CD5 52C3 8E3C 4140 715F  BA06 3F25 A8FE 3BAE 9A68
--

From: Mathieu Desnoyers
Date: Wednesday, December 17, 2008 - 10:32 am

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.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
---
 ltt/Kconfig               |    9 +++
 ltt/Makefile              |    1 
 ltt/ltt-userspace-event.c |  129 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 139 insertions(+)

Index: linux-2.6-lttng/ltt/Kconfig
===================================================================
--- linux-2.6-lttng.orig/ltt/Kconfig	2008-12-16 12:21:13.000000000 -0500
+++ linux-2.6-lttng/ltt/Kconfig	2008-12-16 12:21:14.000000000 -0500
@@ -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
Index: linux-2.6-lttng/ltt/Makefile
===================================================================
--- linux-2.6-lttng.orig/ltt/Makefile	2008-12-16 ...
From: Randy Dunlap
Date: Thursday, December 18, 2008 - 9:50 am

Hi Mathieu,

Please make above line:

 * write_event - write a userspace string into the trace system



---
~Randy
--

From: Mathieu Desnoyers
Date: Thursday, December 18, 2008 - 9:58 am

That for the review,

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


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

Previous thread: RE: [patch 0/7] x86 PAT: v2 - track pfnmap mappings with remap_pfn_range and vm_insert_pfn by Pallipadi, Venkatesh on Monday, December 15, 2008 - 2:50 pm. (7 messages)

Next thread: driver probe error reporting by Ben Dooks on Monday, December 15, 2008 - 4:15 pm. (7 messages)