Skip to content

Commit d503b8f

Browse files
committed
tracing: Add trace_array_puts() to write into instance
Add a generic trace_array_puts() that can be used to "trace_puts()" into an allocated trace_array instance. This is just another variant of trace_array_printk(). Link: https://lkml.kernel.org/r/[email protected] Cc: Masami Hiramatsu <[email protected]> Cc: Andrew Morton <[email protected]> Reviewed-by: Ross Zwisler <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent c484648 commit d503b8f

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

include/linux/trace.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ struct trace_array;
3333
int register_ftrace_export(struct trace_export *export);
3434
int unregister_ftrace_export(struct trace_export *export);
3535

36+
/**
37+
* trace_array_puts - write a constant string into the trace buffer.
38+
* @tr: The trace array to write to
39+
* @str: The constant string to write
40+
*/
41+
#define trace_array_puts(tr, str) \
42+
({ \
43+
str ? __trace_array_puts(tr, _THIS_IP_, str, strlen(str)) : -1; \
44+
})
45+
int __trace_array_puts(struct trace_array *tr, unsigned long ip,
46+
const char *str, int size);
47+
3648
void trace_printk_init_buffers(void);
3749
__printf(3, 4)
3850
int trace_array_printk(struct trace_array *tr, unsigned long ip,

kernel/trace/trace.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,21 +1023,16 @@ __buffer_unlock_commit(struct trace_buffer *buffer, struct ring_buffer_event *ev
10231023
ring_buffer_unlock_commit(buffer);
10241024
}
10251025

1026-
/**
1027-
* __trace_puts - write a constant string into the trace buffer.
1028-
* @ip: The address of the caller
1029-
* @str: The constant string to write
1030-
* @size: The size of the string.
1031-
*/
1032-
int __trace_puts(unsigned long ip, const char *str, int size)
1026+
int __trace_array_puts(struct trace_array *tr, unsigned long ip,
1027+
const char *str, int size)
10331028
{
10341029
struct ring_buffer_event *event;
10351030
struct trace_buffer *buffer;
10361031
struct print_entry *entry;
10371032
unsigned int trace_ctx;
10381033
int alloc;
10391034

1040-
if (!(global_trace.trace_flags & TRACE_ITER_PRINTK))
1035+
if (!(tr->trace_flags & TRACE_ITER_PRINTK))
10411036
return 0;
10421037

10431038
if (unlikely(tracing_selftest_running || tracing_disabled))
@@ -1046,7 +1041,7 @@ int __trace_puts(unsigned long ip, const char *str, int size)
10461041
alloc = sizeof(*entry) + size + 2; /* possible \n added */
10471042

10481043
trace_ctx = tracing_gen_ctx();
1049-
buffer = global_trace.array_buffer.buffer;
1044+
buffer = tr->array_buffer.buffer;
10501045
ring_buffer_nest_start(buffer);
10511046
event = __trace_buffer_lock_reserve(buffer, TRACE_PRINT, alloc,
10521047
trace_ctx);
@@ -1068,11 +1063,23 @@ int __trace_puts(unsigned long ip, const char *str, int size)
10681063
entry->buf[size] = '\0';
10691064

10701065
__buffer_unlock_commit(buffer, event);
1071-
ftrace_trace_stack(&global_trace, buffer, trace_ctx, 4, NULL);
1066+
ftrace_trace_stack(tr, buffer, trace_ctx, 4, NULL);
10721067
out:
10731068
ring_buffer_nest_end(buffer);
10741069
return size;
10751070
}
1071+
EXPORT_SYMBOL_GPL(__trace_array_puts);
1072+
1073+
/**
1074+
* __trace_puts - write a constant string into the trace buffer.
1075+
* @ip: The address of the caller
1076+
* @str: The constant string to write
1077+
* @size: The size of the string.
1078+
*/
1079+
int __trace_puts(unsigned long ip, const char *str, int size)
1080+
{
1081+
return __trace_array_puts(&global_trace, ip, str, size);
1082+
}
10761083
EXPORT_SYMBOL_GPL(__trace_puts);
10771084

10781085
/**

0 commit comments

Comments
 (0)