From patchwork Mon Mar 9 19:04:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 11427793 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A0B361874 for ; Mon, 9 Mar 2020 19:05:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8ABB322B48 for ; Mon, 9 Mar 2020 19:05:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727613AbgCITF3 (ORCPT ); Mon, 9 Mar 2020 15:05:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:48984 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727854AbgCITF2 (ORCPT ); Mon, 9 Mar 2020 15:05:28 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E397E24654 for ; Mon, 9 Mar 2020 19:05:27 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.93) (envelope-from ) id 1jBNiQ-0033Bc-Rg for linux-trace-devel@vger.kernel.org; Mon, 09 Mar 2020 15:05:26 -0400 Message-Id: <20200309190526.741063088@goodmis.org> User-Agent: quilt/0.65 Date: Mon, 09 Mar 2020 15:04:50 -0400 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Subject: [PATCH 1/2] trace-cmd: Its DEFAULT_INPUT_FILE not DEFAUT_INPUT_FILE References: <20200309190449.207021960@goodmis.org> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org From: "Steven Rostedt (VMware)" Fix the typo in the DEFAULT_INPUT_FILE macro name. Signed-off-by: Steven Rostedt (VMware) --- tracecmd/include/trace-local.h | 2 +- tracecmd/trace-dump.c | 2 +- tracecmd/trace-hist.c | 2 +- tracecmd/trace-mem.c | 2 +- tracecmd/trace-read.c | 2 +- tracecmd/trace-record.c | 2 +- tracecmd/trace-restore.c | 2 +- tracecmd/trace-split.c | 2 +- tracecmd/trace-tsync.c | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h index 49c52b1762b6..5ef569f03553 100644 --- a/tracecmd/include/trace-local.h +++ b/tracecmd/include/trace-local.h @@ -14,7 +14,7 @@ #define TRACE_AGENT_DEFAULT_PORT 823 -#define DEFAUT_INPUT_FILE "trace.dat" +#define DEFAULT_INPUT_FILE "trace.dat" #define GUEST_PIPE_NAME "trace-pipe-cpu" #define GUEST_DIR_FMT "/var/lib/trace-cmd/virt/%s" #define GUEST_FIFO_FMT GUEST_DIR_FMT "/" GUEST_PIPE_NAME "%d" diff --git a/tracecmd/trace-dump.c b/tracecmd/trace-dump.c index ffb1c6b17fff..5642f12a55ed 100644 --- a/tracecmd/trace-dump.c +++ b/tracecmd/trace-dump.c @@ -723,7 +723,7 @@ void trace_dump(int argc, char **argv) } if (!input_file) - input_file = DEFAUT_INPUT_FILE; + input_file = DEFAULT_INPUT_FILE; if (!verbosity && !validate) verbosity = SUMMARY; diff --git a/tracecmd/trace-hist.c b/tracecmd/trace-hist.c index fdfd4a1976d0..c458c25e2aa5 100644 --- a/tracecmd/trace-hist.c +++ b/tracecmd/trace-hist.c @@ -1037,7 +1037,7 @@ void trace_hist(int argc, char **argv) } if (!input_file) - input_file = DEFAUT_INPUT_FILE; + input_file = DEFAULT_INPUT_FILE; handle = tracecmd_alloc(input_file); if (!handle) diff --git a/tracecmd/trace-mem.c b/tracecmd/trace-mem.c index 5caeeb6cf86d..465b1823345d 100644 --- a/tracecmd/trace-mem.c +++ b/tracecmd/trace-mem.c @@ -548,7 +548,7 @@ void trace_mem(int argc, char **argv) } if (!input_file) - input_file = DEFAUT_INPUT_FILE; + input_file = DEFAULT_INPUT_FILE; handle = tracecmd_alloc(input_file); if (!handle) diff --git a/tracecmd/trace-read.c b/tracecmd/trace-read.c index c184c6273316..c1f840d560f2 100644 --- a/tracecmd/trace-read.c +++ b/tracecmd/trace-read.c @@ -74,7 +74,7 @@ struct pid_list *comm_list; static unsigned int page_size; static int input_fd; -static const char *default_input_file = DEFAUT_INPUT_FILE; +static const char *default_input_file = DEFAULT_INPUT_FILE; static const char *input_file; static int multi_inputs; static int max_file_size; diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index c8c853f80d11..280dc9ddf23a 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -69,7 +69,7 @@ static int rt_prio; static int keep; -static const char *output_file = DEFAUT_INPUT_FILE; +static const char *output_file = DEFAULT_INPUT_FILE; static int latency; static int sleep_time = 1000; diff --git a/tracecmd/trace-restore.c b/tracecmd/trace-restore.c index e3b86dd2085c..d6134acf2588 100644 --- a/tracecmd/trace-restore.c +++ b/tracecmd/trace-restore.c @@ -25,7 +25,7 @@ void trace_restore (int argc, char **argv) { struct tracecmd_output *handle; - const char *output_file = DEFAUT_INPUT_FILE; + const char *output_file = DEFAULT_INPUT_FILE; const char *output = NULL; const char *input = NULL; const char *tracing_dir = NULL; diff --git a/tracecmd/trace-split.c b/tracecmd/trace-split.c index b4d0df32217c..bb2c3d5346b3 100644 --- a/tracecmd/trace-split.c +++ b/tracecmd/trace-split.c @@ -23,7 +23,7 @@ #include "trace-local.h" static unsigned int page_size; -static const char *default_input_file = DEFAUT_INPUT_FILE; +static const char *default_input_file = DEFAULT_INPUT_FILE; static const char *input_file; enum split_types { diff --git a/tracecmd/trace-tsync.c b/tracecmd/trace-tsync.c index bf65e441a93e..eab2fda5b120 100644 --- a/tracecmd/trace-tsync.c +++ b/tracecmd/trace-tsync.c @@ -139,7 +139,7 @@ static void write_guest_time_shift(struct buffer_instance *instance) if (ret < 0 || !count || !ts || !offsets) return; - file = trace_get_guest_file(DEFAUT_INPUT_FILE, + file = trace_get_guest_file(DEFAULT_INPUT_FILE, tracefs_instance_get_name(instance->tracefs)); fd = open(file, O_RDWR); if (fd < 0) From patchwork Mon Mar 9 19:04:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 11427795 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C3EC618E8 for ; Mon, 9 Mar 2020 19:05:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AF6D624655 for ; Mon, 9 Mar 2020 19:05:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727854AbgCITF3 (ORCPT ); Mon, 9 Mar 2020 15:05:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:48986 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727855AbgCITF2 (ORCPT ); Mon, 9 Mar 2020 15:05:28 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1469A24655 for ; Mon, 9 Mar 2020 19:05:28 +0000 (UTC) Received: from rostedt by gandalf.local.home with local (Exim 4.93) (envelope-from ) id 1jBNiR-0033C6-0P for linux-trace-devel@vger.kernel.org; Mon, 09 Mar 2020 15:05:27 -0400 Message-Id: <20200309190526.886340672@goodmis.org> User-Agent: quilt/0.65 Date: Mon, 09 Mar 2020 15:04:51 -0400 From: Steven Rostedt To: linux-trace-devel@vger.kernel.org Subject: [PATCH 2/2] trace-cmd: Have instances include a copy of its output file References: <20200309190449.207021960@goodmis.org> MIME-Version: 1.0 Sender: linux-trace-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-trace-devel@vger.kernel.org From: "Steven Rostedt (VMware)" Instead of having a global "output_file", store the output file in the instance itself. That way it can be used instead of having to pass around a global variable. This also fixes a bug when an output file option is used, and it can break the recording of the guest, as the tsync currently looks for the "default" recording name. Instead, it can now look at the output file stored in the instance (which will hold the guest name). Signed-off-by: Steven Rostedt (VMware) --- tracecmd/include/trace-local.h | 1 + tracecmd/trace-record.c | 31 ++++++++++++++++--------------- tracecmd/trace-tsync.c | 6 ++---- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h index 5ef569f03553..0f58c7721b88 100644 --- a/tracecmd/include/trace-local.h +++ b/tracecmd/include/trace-local.h @@ -189,6 +189,7 @@ struct buffer_instance { struct tracefs_instance *tracefs; unsigned long long trace_id; char *cpumask; + char *output_file; struct event_list *events; struct event_list **event_next; diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c index 280dc9ddf23a..c945a56ab7ab 100644 --- a/tracecmd/trace-record.c +++ b/tracecmd/trace-record.c @@ -69,8 +69,6 @@ static int rt_prio; static int keep; -static const char *output_file = DEFAULT_INPUT_FILE; - static int latency; static int sleep_time = 1000; static int recorder_threads; @@ -524,6 +522,7 @@ static void reset_event_list(struct buffer_instance *instance) static char *get_temp_file(struct buffer_instance *instance, int cpu) { + const char *output_file = instance->output_file; const char *name; char *file = NULL; int size; @@ -572,6 +571,7 @@ static void put_temp_file(char *file) static void delete_temp_file(struct buffer_instance *instance, int cpu) { + const char *output_file = instance->output_file; const char *name; char file[PATH_MAX]; @@ -3777,6 +3777,7 @@ static void connect_to_agent(struct buffer_instance *instance) static void setup_guest(struct buffer_instance *instance) { struct tracecmd_msg_handle *msg_handle = instance->msg_handle; + const char *output_file = instance->output_file; char *file; int fd; @@ -3786,8 +3787,10 @@ static void setup_guest(struct buffer_instance *instance) if (!file) die("Failed to allocate memory"); + free(instance->output_file); + instance->output_file = file; + fd = open(file, O_CREAT|O_WRONLY|O_TRUNC, 0644); - put_temp_file(file); if (fd < 0) die("Failed to open", file); @@ -4119,15 +4122,10 @@ static void write_guest_file(struct buffer_instance *instance) char **temp_files; int i, fd; - file = trace_get_guest_file(output_file, - tracefs_instance_get_name(instance->tracefs)); - if (!file) - die("Failed to allocate memory"); - + file = instance->output_file; fd = open(file, O_RDWR); if (fd < 0) die("error opening %s", file); - put_temp_file(file); handle = tracecmd_get_output_handle_fd(fd); if (!handle) @@ -4176,7 +4174,7 @@ static void record_data(struct common_record_context *ctx) return; if (latency) { - handle = tracecmd_create_file_latency(output_file, local_cpu_count); + handle = tracecmd_create_file_latency(ctx->output, local_cpu_count); tracecmd_set_quiet(handle, quiet); } else { if (!local_cpu_count) @@ -4207,7 +4205,7 @@ static void record_data(struct common_record_context *ctx) touch_file(temp_files[i]); } - handle = tracecmd_create_init_file_glob(output_file, listed_events); + handle = tracecmd_create_init_file_glob(ctx->output, listed_events); if (!handle) die("Error creating output file"); tracecmd_set_quiet(handle, quiet); @@ -6165,11 +6163,14 @@ static void record_trace(int argc, char **argv, check_doing_something(); check_function_plugin(); - if (ctx->output) - output_file = ctx->output; + if (!ctx->output) + ctx->output = DEFAULT_INPUT_FILE; /* Save the state of tracing_on before starting */ for_all_instances(instance) { + instance->output_file = strdup(ctx->output); + if (!instance->output_file) + die("Failed to allocate output file name for instance"); if (!ctx->manual && instance->flags & BUFFER_FL_PROFILE) enable_profile(instance); @@ -6300,8 +6301,8 @@ void trace_extract(int argc, char **argv) update_first_instance(ctx.instance, 1); check_function_plugin(); - if (ctx.output) - output_file = ctx.output; + if (!ctx.output) + ctx.output = DEFAULT_INPUT_FILE; /* Save the state of tracing_on before starting */ for_all_instances(instance) { diff --git a/tracecmd/trace-tsync.c b/tracecmd/trace-tsync.c index eab2fda5b120..e639788d2f3f 100644 --- a/tracecmd/trace-tsync.c +++ b/tracecmd/trace-tsync.c @@ -130,7 +130,7 @@ static void write_guest_time_shift(struct buffer_instance *instance) struct iovec vector[4]; long long *offsets; long long *ts; - char *file; + const char *file; int count; int ret; int fd; @@ -139,12 +139,10 @@ static void write_guest_time_shift(struct buffer_instance *instance) if (ret < 0 || !count || !ts || !offsets) return; - file = trace_get_guest_file(DEFAULT_INPUT_FILE, - tracefs_instance_get_name(instance->tracefs)); + file = instance->output_file; fd = open(file, O_RDWR); if (fd < 0) die("error opening %s", file); - free(file); handle = tracecmd_get_output_handle_fd(fd); vector[0].iov_len = 8; vector[0].iov_base = &top_instance.trace_id;