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: ...
you mean similar to ftrace's /debug/tracing/trace_marker ? ;-) Ingo --
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 --
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 ...
Hi Mathieu, Please make above line: * write_event - write a userspace string into the trace system --- ~Randy --
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 --
