From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753345AbdKWQhc (ORCPT ); Thu, 23 Nov 2017 11:37:32 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:42465 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752869AbdKWQeE (ORCPT ); Thu, 23 Nov 2017 11:34:04 -0500 X-Google-Smtp-Source: AGs4zMaqODsk7aAgJ/DGFVTsO83X0JXlAA/tPNQPzQSSm2jsngrVU6n0uoSlqkOmGS6w1QByXI0b1Q== From: "Vladislav Valtchev (VMware)" To: rostedt@goodmis.org Cc: linux-kernel@vger.kernel.org, y.karadz@gmail.com, "Vladislav Valtchev (VMware)" Subject: [PATCH 02/11] trace-cmd: Extract trace_restart() from trace_record() Date: Thu, 23 Nov 2017 18:33:26 +0200 Message-Id: <20171123163335.19078-3-vladislav.valtchev@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171123163335.19078-1-vladislav.valtchev@gmail.com> References: <20171123163335.19078-1-vladislav.valtchev@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In this patch, an entire trace_restart() function has been extracted from trace_record() and added to the commands table in trace-cmd.c, without any ad-hoc changes. Now trace_record() is a little bit smaller and all the code handling the 'restart' command is in a dedicated function. Signed-off-by: Vladislav Valtchev (VMware) --- trace-cmd.c | 2 +- trace-local.h | 2 ++ trace-record.c | 74 ++++++++++++++++++++++++++++++++-------------------------- 3 files changed, 44 insertions(+), 34 deletions(-) diff --git a/trace-cmd.c b/trace-cmd.c index de5283c..2b9146e 100644 --- a/trace-cmd.c +++ b/trace-cmd.c @@ -107,7 +107,7 @@ struct command commands[] = { {"stop", trace_stop}, {"stream", trace_record}, {"profile", trace_record}, - {"restart", trace_record}, + {"restart", trace_restart}, {"reset", trace_record}, {"stat", trace_stat}, {"options", trace_option}, diff --git a/trace-local.h b/trace-local.h index 8010680..2b55aa8 100644 --- a/trace-local.h +++ b/trace-local.h @@ -60,6 +60,8 @@ void trace_record(int argc, char **argv); void trace_stop(int argc, char **argv); +void trace_restart(int argc, char **argv); + void trace_report(int argc, char **argv); void trace_split(int argc, char **argv); diff --git a/trace-record.c b/trace-record.c index c7f7df7..e9cce12 100644 --- a/trace-record.c +++ b/trace-record.c @@ -4239,6 +4239,47 @@ void trace_stop(int argc, char **argv) exit(0); } +void trace_restart(int argc, char **argv) +{ + int topt = 0; + struct buffer_instance *instance = &top_instance; + + init_instance(instance); + + for (;;) { + int c; + + c = getopt(argc-1, argv+1, "hatB:"); + if (c == -1) + break; + switch (c) { + case 'h': + usage(argv); + break; + case 'B': + instance = create_instance(optarg); + if (!instance) + die("Failed to create instance"); + add_instance(instance); + break; + case 'a': + add_all_instances(); + break; + case 't': + /* Force to use top instance */ + topt = 1; + instance = &top_instance; + break; + default: + usage(argv); + } + + } + update_first_instance(instance, topt); + tracecmd_enable_tracing(); + exit(0); +} + void trace_record(int argc, char **argv) { const char *plugin = NULL; @@ -4289,39 +4330,6 @@ void trace_record(int argc, char **argv) else if ((profile = strcmp(argv[1], "profile") == 0)) { handle_init = trace_init_profile; events = 1; - } else if (strcmp(argv[1], "restart") == 0) { - for (;;) { - int c; - - c = getopt(argc-1, argv+1, "hatB:"); - if (c == -1) - break; - switch (c) { - case 'h': - usage(argv); - break; - case 'B': - instance = create_instance(optarg); - if (!instance) - die("Failed to create instance"); - add_instance(instance); - break; - case 'a': - add_all_instances(); - break; - case 't': - /* Force to use top instance */ - topt = 1; - instance = &top_instance; - break; - default: - usage(argv); - } - - } - update_first_instance(instance, topt); - tracecmd_enable_tracing(); - exit(0); } else if (strcmp(argv[1], "reset") == 0) { /* if last arg is -a, then -b and -d apply to all instances */ int last_specified_all = 0; -- 2.14.1