summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS5
-rw-r--r--buildrun.cxx1
-rw-r--r--doc/SystemTap_Tapset_Reference/tapsets.tmpl8
-rw-r--r--runtime/autoconf-trace-printk.c8
-rw-r--r--stapfuncs.3stap.in30
-rw-r--r--tapset/logging.stp63
-rw-r--r--testsuite/buildok/logging.stp11
7 files changed, 92 insertions, 34 deletions
diff --git a/NEWS b/NEWS
index ce1eaf2e..f0187614 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,8 @@
+* What's new
+
+- ftrace(msg:string) tapset function to send strings to the system-wide
+ ftrace ring-buffer (if any).
+
* What's new in verson 1.0
- process().mark() probes now use an enabling semaphore to reduce the
diff --git a/buildrun.cxx b/buildrun.cxx
index 100cbc4d..cebe3b8e 100644
--- a/buildrun.cxx
+++ b/buildrun.cxx
@@ -160,6 +160,7 @@ compile_pass (systemtap_session& s)
output_autoconf(s, o, "autoconf-alloc-percpu-align.c", "STAPCONF_ALLOC_PERCPU_ALIGN", NULL);
output_autoconf(s, o, "autoconf-x86-gs.c", "STAPCONF_X86_GS", NULL);
output_autoconf(s, o, "autoconf-grsecurity.c", "STAPCONF_GRSECURITY", NULL);
+ output_autoconf(s, o, "autoconf-trace-printk.c", "STAPCONF_TRACE_PRINTK", NULL);
#if 0
/* NB: For now, the performance hit of probe_kernel_read/write (vs. our
diff --git a/doc/SystemTap_Tapset_Reference/tapsets.tmpl b/doc/SystemTap_Tapset_Reference/tapsets.tmpl
index 448d4b20..fcfb1e85 100644
--- a/doc/SystemTap_Tapset_Reference/tapsets.tmpl
+++ b/doc/SystemTap_Tapset_Reference/tapsets.tmpl
@@ -206,4 +206,12 @@
</para>
!Itapset/dentry.stp
</chapter>
+ <chapter id="logging.stp">
+ <title>Logging Tapset</title>
+ <para>
+ This family of functions is used to send simple
+ message strings to various destinations.
+ </para>
+!Itapset/logging.stp
+ </chapter>
</book>
diff --git a/runtime/autoconf-trace-printk.c b/runtime/autoconf-trace-printk.c
new file mode 100644
index 00000000..8330a58a
--- /dev/null
+++ b/runtime/autoconf-trace-printk.c
@@ -0,0 +1,8 @@
+#include <linux/kernel.h>
+
+int bar (void) {
+ static char *fmt = "%s\n";
+ trace_printk (fmt, "hello world");
+ return 0;
+}
+
diff --git a/stapfuncs.3stap.in b/stapfuncs.3stap.in
index 3d88b2ea..48018b41 100644
--- a/stapfuncs.3stap.in
+++ b/stapfuncs.3stap.in
@@ -23,36 +23,6 @@ example2:unknown ()
In function "example2", do something. There is no explicit return value
and take no parameters.
-.SS PRINTING
-
-.TP
-log:unknown (msg:string)
-Writes the given string to the common trace buffer. Append an implicit
-end-of-line. Deprecated. Please use the faster print functions.
-
-.TP
-warn:unknown (msg:string)
-Write the given string to the warning stream. Append an implicit end-of-line.
-.I staprun
-prepends the string "WARNING:".
-
-.TP
-error:unknown (msg:string)
-An error has occurred. Write the given string to the error stream.
-Append an implicit end-of-line.
-.I staprun
-prepends the string "ERROR:".
-Block any further execution of statements in this probe. If the number
-of errors so far exceeds the MAXERRORS parameter, also trigger an
-.IR exit() .
-
-.TP
-exit:unknown ()
-Enqueue a request to shut down the systemtap session. This does
-.B not
-unwind the current probe handler, nor block new probe handlers.
-.I staprun
-will shortly respond to the request and initiate an orderly shutdown.
.SS CONVERSIONS
.PP
diff --git a/tapset/logging.stp b/tapset/logging.stp
index 91f9672b..44c05009 100644
--- a/tapset/logging.stp
+++ b/tapset/logging.stp
@@ -6,22 +6,54 @@
// Public License (GPL); either version 2, or (at your option) any
// later version.
-// send a string out with a newline
-// Deprecated. print* functions are much more efficient.
+
+/**
+ * sfunction log - Send a line to the common trace buffer.
+ * @msg: The formatted message string.
+ *
+ * Description: An implicit end-of-line is added.
+ * Same as println() with a single string argument.
+ */
function log (msg:string) %{ /* unprivileged */
- _stp_printf ("%s\n", THIS->msg);
+ _stp_print (THIS->msg);
%}
+
+/**
+ * sfunction warn - Send a line to the warning stream.
+ * @msg: The formatted message string.
+ *
+ * Description: An implicit end-of-line is added. staprun
+ * prepends the string "WARNING:".
+ */
function warn (msg:string) %{ /* unprivileged */
_stp_warn ("%s", THIS->msg);
%}
-// NB: exit() does *not* cause immediate return from current function/probe
+
+/**
+ * sfunction exit - Start shutting down probing script.
+ *
+ * Description: This only enqueues a request to start
+ * shutting down the script. New probes will not fire
+ * (except "end" probes), but all currently
+ * running ones may complete their work.
+ */
function exit () %{ /* unprivileged */
atomic_set (&session_state, STAP_SESSION_STOPPING);
_stp_exit ();
%}
+
+/**
+ * sfunction error - Send an error message.
+ * @msg: The formatted message string.
+ *
+ * Description: An implicit end-of-line is added. staprun prepends
+ * the string "ERROR:". Sending an error message aborts the currently
+ * running probe. Depending on the MAXERRORS parameter, it may
+ * trigger an exit().
+ */
function error (msg:string) %{ /* unprivileged */
/* This is an assignment of a local char[] to a global char*.
It would normally be just as unsafe as returning a pointer to
@@ -36,3 +68,26 @@ function error (msg:string) %{ /* unprivileged */
function stp_print_binary(n:long, arg1:long, arg2:long, arg3:long, arg4:long) %{
_stp_print_binary (THIS->n, THIS->arg1, THIS->arg2, THIS->arg3, THIS->arg4);
%}
+
+
+/**
+ * sfunction ftrace - Send a message to the ftrace ring-buffer (or else printk).
+ * @msg: The formatted message string.
+ *
+ * Description: If the ftrace ring-buffer is configured & available,
+ * see /debugfs/tracing/trace for the message. Otherwise, the
+ * message may be quietly dropped. An implicit end-of-line is added.
+ */
+function ftrace (msg:string) %{ /* unprivileged */
+#ifdef STAPCONF_TRACE_PRINTK
+ static char *fmt = "%s\n";
+ trace_printk (fmt, THIS->msg);
+
+ /* The "fmt" is designed to be non __builtin_constant_p(), so as
+ to defeat trace_printk -> __trace_bprintk optimization. That's
+ because bprintk doesn't save the incoming strings, only their
+ addresses. */
+#else
+ /* printk(KERN_DEBUG "%s\n", THIS->msg); */
+#endif
+%}
diff --git a/testsuite/buildok/logging.stp b/testsuite/buildok/logging.stp
new file mode 100644
index 00000000..636770c7
--- /dev/null
+++ b/testsuite/buildok/logging.stp
@@ -0,0 +1,11 @@
+#! stap -p4
+
+// build-test the logging tapset functions
+
+probe begin {
+ ftrace("ftrace")
+ log("log")
+ warn("warn")
+ exit()
+ error("error")
+}