Skip to content

Commit 3c49b52

Browse files
committed
tracing: Do not do anything special with tracepoint_string when tracing is disabled
When CONFIG_TRACING is not enabled, there's no reason to save the trace strings either by the linker or as a static variable that can be referenced later. Simply pass back the string that is given to tracepoint_string(). Had to move the define to include/linux/tracepoint.h so that it is still visible when CONFIG_TRACING is not set. Link: http://lkml.kernel.org/p/1406318733-26754-2-git-send-email-nicolas.pitre@linaro.org Suggested-by: Nicolas Pitre <nico@linaro.org> Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
1 parent 19583ca commit 3c49b52

File tree

2 files changed

+44
-34
lines changed

2 files changed

+44
-34
lines changed

include/linux/ftrace_event.h

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -574,40 +574,6 @@ do { \
574574
__trace_printk(ip, fmt, ##args); \
575575
} while (0)
576576

577-
/**
578-
* tracepoint_string - register constant persistent string to trace system
579-
* @str - a constant persistent string that will be referenced in tracepoints
580-
*
581-
* If constant strings are being used in tracepoints, it is faster and
582-
* more efficient to just save the pointer to the string and reference
583-
* that with a printf "%s" instead of saving the string in the ring buffer
584-
* and wasting space and time.
585-
*
586-
* The problem with the above approach is that userspace tools that read
587-
* the binary output of the trace buffers do not have access to the string.
588-
* Instead they just show the address of the string which is not very
589-
* useful to users.
590-
*
591-
* With tracepoint_string(), the string will be registered to the tracing
592-
* system and exported to userspace via the debugfs/tracing/printk_formats
593-
* file that maps the string address to the string text. This way userspace
594-
* tools that read the binary buffers have a way to map the pointers to
595-
* the ASCII strings they represent.
596-
*
597-
* The @str used must be a constant string and persistent as it would not
598-
* make sense to show a string that no longer exists. But it is still fine
599-
* to be used with modules, because when modules are unloaded, if they
600-
* had tracepoints, the ring buffers are cleared too. As long as the string
601-
* does not change during the life of the module, it is fine to use
602-
* tracepoint_string() within a module.
603-
*/
604-
#define tracepoint_string(str) \
605-
({ \
606-
static const char *___tp_str __tracepoint_string = str; \
607-
___tp_str; \
608-
})
609-
#define __tracepoint_string __attribute__((section("__tracepoint_str")))
610-
611577
#ifdef CONFIG_PERF_EVENTS
612578
struct perf_event;
613579

include/linux/tracepoint.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,50 @@ extern void syscall_unregfunc(void);
249249

250250
#endif /* CONFIG_TRACEPOINTS */
251251

252+
#ifdef CONFIG_TRACING
253+
/**
254+
* tracepoint_string - register constant persistent string to trace system
255+
* @str - a constant persistent string that will be referenced in tracepoints
256+
*
257+
* If constant strings are being used in tracepoints, it is faster and
258+
* more efficient to just save the pointer to the string and reference
259+
* that with a printf "%s" instead of saving the string in the ring buffer
260+
* and wasting space and time.
261+
*
262+
* The problem with the above approach is that userspace tools that read
263+
* the binary output of the trace buffers do not have access to the string.
264+
* Instead they just show the address of the string which is not very
265+
* useful to users.
266+
*
267+
* With tracepoint_string(), the string will be registered to the tracing
268+
* system and exported to userspace via the debugfs/tracing/printk_formats
269+
* file that maps the string address to the string text. This way userspace
270+
* tools that read the binary buffers have a way to map the pointers to
271+
* the ASCII strings they represent.
272+
*
273+
* The @str used must be a constant string and persistent as it would not
274+
* make sense to show a string that no longer exists. But it is still fine
275+
* to be used with modules, because when modules are unloaded, if they
276+
* had tracepoints, the ring buffers are cleared too. As long as the string
277+
* does not change during the life of the module, it is fine to use
278+
* tracepoint_string() within a module.
279+
*/
280+
#define tracepoint_string(str) \
281+
({ \
282+
static const char *___tp_str __tracepoint_string = str; \
283+
___tp_str; \
284+
})
285+
#define __tracepoint_string __attribute__((section("__tracepoint_str")))
286+
#else
287+
/*
288+
* tracepoint_string() is used to save the string address for userspace
289+
* tracing tools. When tracing isn't configured, there's no need to save
290+
* anything.
291+
*/
292+
# define tracepoint_string(str) str
293+
# define __tracepoint_string
294+
#endif
295+
252296
/*
253297
* The need for the DECLARE_TRACE_NOARGS() is to handle the prototype
254298
* (void). "void" is a special value in a function prototype and can

0 commit comments

Comments
 (0)