mirror of
https://github.com/lkl/linux.git
synced 2025-12-19 16:13:19 +09:00
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/20230207173026.584717290@goodmis.org Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Andrew Morton <akpm@linux-foundation.org> Reviewed-by: Ross Zwisler <zwisler@google.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
This commit is contained in:
@@ -33,6 +33,18 @@ struct trace_array;
|
|||||||
int register_ftrace_export(struct trace_export *export);
|
int register_ftrace_export(struct trace_export *export);
|
||||||
int unregister_ftrace_export(struct trace_export *export);
|
int unregister_ftrace_export(struct trace_export *export);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* trace_array_puts - write a constant string into the trace buffer.
|
||||||
|
* @tr: The trace array to write to
|
||||||
|
* @str: The constant string to write
|
||||||
|
*/
|
||||||
|
#define trace_array_puts(tr, str) \
|
||||||
|
({ \
|
||||||
|
str ? __trace_array_puts(tr, _THIS_IP_, str, strlen(str)) : -1; \
|
||||||
|
})
|
||||||
|
int __trace_array_puts(struct trace_array *tr, unsigned long ip,
|
||||||
|
const char *str, int size);
|
||||||
|
|
||||||
void trace_printk_init_buffers(void);
|
void trace_printk_init_buffers(void);
|
||||||
__printf(3, 4)
|
__printf(3, 4)
|
||||||
int trace_array_printk(struct trace_array *tr, unsigned long ip,
|
int trace_array_printk(struct trace_array *tr, unsigned long ip,
|
||||||
|
|||||||
@@ -1023,13 +1023,8 @@ __buffer_unlock_commit(struct trace_buffer *buffer, struct ring_buffer_event *ev
|
|||||||
ring_buffer_unlock_commit(buffer);
|
ring_buffer_unlock_commit(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
int __trace_array_puts(struct trace_array *tr, unsigned long ip,
|
||||||
* __trace_puts - write a constant string into the trace buffer.
|
const char *str, int size)
|
||||||
* @ip: The address of the caller
|
|
||||||
* @str: The constant string to write
|
|
||||||
* @size: The size of the string.
|
|
||||||
*/
|
|
||||||
int __trace_puts(unsigned long ip, const char *str, int size)
|
|
||||||
{
|
{
|
||||||
struct ring_buffer_event *event;
|
struct ring_buffer_event *event;
|
||||||
struct trace_buffer *buffer;
|
struct trace_buffer *buffer;
|
||||||
@@ -1037,7 +1032,7 @@ int __trace_puts(unsigned long ip, const char *str, int size)
|
|||||||
unsigned int trace_ctx;
|
unsigned int trace_ctx;
|
||||||
int alloc;
|
int alloc;
|
||||||
|
|
||||||
if (!(global_trace.trace_flags & TRACE_ITER_PRINTK))
|
if (!(tr->trace_flags & TRACE_ITER_PRINTK))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (unlikely(tracing_selftest_running || tracing_disabled))
|
if (unlikely(tracing_selftest_running || tracing_disabled))
|
||||||
@@ -1046,7 +1041,7 @@ int __trace_puts(unsigned long ip, const char *str, int size)
|
|||||||
alloc = sizeof(*entry) + size + 2; /* possible \n added */
|
alloc = sizeof(*entry) + size + 2; /* possible \n added */
|
||||||
|
|
||||||
trace_ctx = tracing_gen_ctx();
|
trace_ctx = tracing_gen_ctx();
|
||||||
buffer = global_trace.array_buffer.buffer;
|
buffer = tr->array_buffer.buffer;
|
||||||
ring_buffer_nest_start(buffer);
|
ring_buffer_nest_start(buffer);
|
||||||
event = __trace_buffer_lock_reserve(buffer, TRACE_PRINT, alloc,
|
event = __trace_buffer_lock_reserve(buffer, TRACE_PRINT, alloc,
|
||||||
trace_ctx);
|
trace_ctx);
|
||||||
@@ -1068,11 +1063,23 @@ int __trace_puts(unsigned long ip, const char *str, int size)
|
|||||||
entry->buf[size] = '\0';
|
entry->buf[size] = '\0';
|
||||||
|
|
||||||
__buffer_unlock_commit(buffer, event);
|
__buffer_unlock_commit(buffer, event);
|
||||||
ftrace_trace_stack(&global_trace, buffer, trace_ctx, 4, NULL);
|
ftrace_trace_stack(tr, buffer, trace_ctx, 4, NULL);
|
||||||
out:
|
out:
|
||||||
ring_buffer_nest_end(buffer);
|
ring_buffer_nest_end(buffer);
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(__trace_array_puts);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* __trace_puts - write a constant string into the trace buffer.
|
||||||
|
* @ip: The address of the caller
|
||||||
|
* @str: The constant string to write
|
||||||
|
* @size: The size of the string.
|
||||||
|
*/
|
||||||
|
int __trace_puts(unsigned long ip, const char *str, int size)
|
||||||
|
{
|
||||||
|
return __trace_array_puts(&global_trace, ip, str, size);
|
||||||
|
}
|
||||||
EXPORT_SYMBOL_GPL(__trace_puts);
|
EXPORT_SYMBOL_GPL(__trace_puts);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user