From 450718c9c424bce67e8580183788380431f90434 Mon Sep 17 00:00:00 2001 From: "Frank Ch. Eigler" Date: Wed, 23 Sep 2009 07:41:47 -0400 Subject: [PATCH] PR10390: ftrace() tapset function * tapset/logging.stp (ftrace): New function. (*): Add kerneldoc to other functions. * doc/SystemTap_Tapset_Reference/tapsets.tmpl: Process logging.stp. * stapfuncs.3stap.in: Remove "LOGGING" section, now redundant. * runtime/autoconf-trace-printk.c: New autoconf test. * buildrun.cxx (compile_pass): Build it. * NEWS: Mention it. * testsuite/buildok/logging.stp: Test it. --- NEWS | 5 ++ buildrun.cxx | 1 + doc/SystemTap_Tapset_Reference/tapsets.tmpl | 8 +++ runtime/autoconf-trace-printk.c | 8 +++ stapfuncs.3stap.in | 30 ---------- tapset/logging.stp | 63 +++++++++++++++++++-- testsuite/buildok/logging.stp | 11 ++++ 7 files changed, 92 insertions(+), 34 deletions(-) create mode 100644 runtime/autoconf-trace-printk.c create mode 100644 testsuite/buildok/logging.stp diff --git a/NEWS b/NEWS index ce1eaf2e0..f01876146 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 100cbc4d5..cebe3b8e2 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 448d4b204..fcfb1e856 100644 --- a/doc/SystemTap_Tapset_Reference/tapsets.tmpl +++ b/doc/SystemTap_Tapset_Reference/tapsets.tmpl @@ -206,4 +206,12 @@ !Itapset/dentry.stp + + Logging Tapset + + This family of functions is used to send simple + message strings to various destinations. + +!Itapset/logging.stp + diff --git a/runtime/autoconf-trace-printk.c b/runtime/autoconf-trace-printk.c new file mode 100644 index 000000000..8330a58aa --- /dev/null +++ b/runtime/autoconf-trace-printk.c @@ -0,0 +1,8 @@ +#include + +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 3d88b2ea9..48018b417 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 91f9672ba..44c050093 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 000000000..636770c70 --- /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") +} -- 2.43.5