Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932343AbbFEFi3 (ORCPT ); Fri, 5 Jun 2015 01:38:29 -0400 Received: from mail-wg0-f52.google.com ([74.125.82.52]:36711 "EHLO mail-wg0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932066AbbFEFi1 (ORCPT ); Fri, 5 Jun 2015 01:38:27 -0400 MIME-Version: 1.0 Date: Fri, 5 Jun 2015 13:38:26 +0800 Message-ID: Subject: [RFC PATCH 3/3] Introduce trace log output function for STM From: Chunyan Zhang To: Steven Rostedt , mingo@redhat.com Cc: Mathieu Poirier , Kaixu Xia , Serge Broslavsky , Mark Brown , alexander.shishkin@linux.intel.com, "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3871 Lines: 137 This patch introduced a few functions to print the event trace log to STM buffer when the trace event happen and the event information would be committed to ring buffer. Before outputting the trace log to STM, we have to get the human readable trace log content and print it into a local buffer in the format of a string, the function 'trace_event_buf_vprintf()' is just for this purpose. Signed-off-by: Chunyan Zhang --- kernel/trace/Makefile | 1 + kernel/trace/trace_output_stm.c | 99 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 kernel/trace/trace_output_stm.c diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile index 9b1044e..002de34 100644 --- a/kernel/trace/Makefile +++ b/kernel/trace/Makefile @@ -67,4 +67,5 @@ obj-$(CONFIG_UPROBE_EVENT) += trace_uprobe.o obj-$(CONFIG_TRACEPOINT_BENCHMARK) += trace_benchmark.o +obj-$(CONFIG_STM_TRACE_EVENT) += trace_output_stm.o libftrace-y := ftrace.o diff --git a/kernel/trace/trace_output_stm.c b/kernel/trace/trace_output_stm.c new file mode 100644 index 0000000..1cf6d87 --- /dev/null +++ b/kernel/trace/trace_output_stm.c @@ -0,0 +1,99 @@ +#include +#include +#include +#include "trace.h" + +#define STM_OUTPUT_STRLEN 128 + +/* store the event trace log for STM */ +struct trace_buffer_stm { + char buffer[STM_OUTPUT_STRLEN]; + unsigned int used_len; + unsigned int size; +}; + +static struct trace_buffer_stm *trace_event_stm_buffer; +static struct trace_seq *stm_tmp_seq; +static int stm_buffers_allocated; + +void trace_event_buf_vprintf(struct trace_buffer_stm *tb, const char *fmt, ...) +{ + va_list ap; + char *buffer = tb->buffer + tb->used_len; + unsigned int size = tb->size - tb->used_len; + + va_start(ap, fmt); + tb->used_len += vsnprintf(buffer, size, fmt, ap); + va_end(ap); +} +EXPORT_SYMBOL_GPL(trace_event_buf_vprintf); + +static inline void stm_buf_reset(struct trace_buffer_stm *tb) +{ + tb->used_len = 0; +} + +void trace_event_stm_log(struct ftrace_event_buffer *fbuffer) +{ + + struct trace_seq *p = stm_tmp_seq; + struct trace_buffer_stm *tb; + struct ftrace_event_call *event_call = fbuffer->ftrace_file->event_call; + struct trace_entry *entry = (struct trace_entry *)fbuffer->entry; + + if (!stm_buffers_allocated) + return; + + tb = trace_event_stm_buffer; + + if (event_call->output_stm) + event_call->output_stm(p, entry, tb); + + stm_trace_event_write(tb->buffer, tb->used_len); + + stm_buf_reset(tb); +} +EXPORT_SYMBOL_GPL(trace_event_stm_log); + +static int alloc_stm_tmp_seq(void) +{ + struct trace_seq *seq; + + seq = kzalloc(sizeof(struct trace_seq), GFP_KERNEL); + if (!seq) + return -ENOMEM; + + stm_tmp_seq = seq; + + return 0; +} + +static int alloc_stm_trace_buffer(void) +{ + struct trace_buffer_stm *buffer; + + buffer = kzalloc(sizeof(struct trace_buffer_stm), GFP_KERNEL); + if (!buffer) + return -ENOMEM; + + buffer->used_len = 0; + buffer->size = ARRAY_SIZE(buffer->buffer); + + trace_event_stm_buffer = buffer; + + return 0; +} + +static __init int trace_stm_init_buffers(void) +{ + if (alloc_stm_trace_buffer()) + return -ENOMEM; + + if (alloc_stm_tmp_seq()) + return -ENOMEM; + + stm_buffers_allocated = 1; + + return 0; +} +fs_initcall(trace_stm_init_buffers); -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/