From: "Vladislav Valtchev (VMware)" <vladislav.valtchev@gmail.com>
To: rostedt@goodmis.org
Cc: linux-kernel@vger.kernel.org, y.karadz@gmail.com,
"Vladislav Valtchev (VMware)" <vladislav.valtchev@gmail.com>
Subject: [PATCH v2 05/10] trace-cmd: Making start,extract,stream,profile separate funcs
Date: Thu, 30 Nov 2017 15:19:52 +0200 [thread overview]
Message-ID: <20171130131957.21617-6-vladislav.valtchev@gmail.com> (raw)
In-Reply-To: <20171130131957.21617-1-vladislav.valtchev@gmail.com>
This simple patch make the above-mentioned commands independent from 'record'.
The point of doing so is to follow the convention of one entry-point per command
that is followed by most of trace-cmd's code. Ultimately that aims to prevent
the complexity to concentrate in a single point, making the code simpler to
maintain.
Signed-off-by: Vladislav Valtchev (VMware) <vladislav.valtchev@gmail.com>
---
trace-cmd.c | 8 +++----
trace-local.h | 8 +++++++
trace-record.c | 72 ++++++++++++++++++++++++++++++++++++++++++----------------
3 files changed, 64 insertions(+), 24 deletions(-)
diff --git a/trace-cmd.c b/trace-cmd.c
index dd1c108..6c2efa3 100644
--- a/trace-cmd.c
+++ b/trace-cmd.c
@@ -102,11 +102,11 @@ struct command commands[] = {
{"stack", trace_stack},
{"check-events", trace_check_events},
{"record", trace_record},
- {"start", trace_record},
- {"extract", trace_record},
+ {"start", trace_start},
+ {"extract", trace_extract},
{"stop", trace_stop},
- {"stream", trace_record},
- {"profile", trace_record},
+ {"stream", trace_stream},
+ {"profile", trace_profile},
{"restart", trace_restart},
{"reset", trace_reset},
{"stat", trace_stat},
diff --git a/trace-local.h b/trace-local.h
index fa5232b..eaae430 100644
--- a/trace-local.h
+++ b/trace-local.h
@@ -64,6 +64,14 @@ void trace_restart(int argc, char **argv);
void trace_reset(int argc, char **argv);
+void trace_start(int argc, char **argv);
+
+void trace_extract(int argc, char **argv);
+
+void trace_stream(int argc, char **argv);
+
+void trace_profile(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 827189d..6c12416 100644
--- a/trace-record.c
+++ b/trace-record.c
@@ -4387,10 +4387,12 @@ struct common_record_context {
int run_command;
};
-static void init_common_record_context(struct common_record_context *ctx)
+static void init_common_record_context(struct common_record_context *ctx,
+ enum trace_cmd curr_cmd)
{
memset(ctx, 0, sizeof(*ctx));
ctx->instance = &top_instance;
+ ctx->curr_cmd = curr_cmd;
init_instance(ctx->instance);
cpu_count = count_cpus();
}
@@ -4739,9 +4741,12 @@ static void parse_record_options(int argc,
"Did you mean 'record'?");
ctx->run_command = 1;
}
-
}
+/*
+ * This function contains common code for the following commands:
+ * record, start, extract, stream, profile.
+ */
static void record_trace(int argc, char **argv,
struct common_record_context *ctx)
{
@@ -4901,7 +4906,7 @@ static void record_trace(int argc, char **argv,
destroy_stats();
if (keep)
- exit(0);
+ return;
update_reset_files();
update_reset_triggers();
@@ -4924,7 +4929,49 @@ static void record_trace(int argc, char **argv,
if (IS_PROFILE(ctx))
do_trace_profile();
+}
+void trace_start(int argc, char **argv)
+{
+ struct common_record_context ctx;
+
+ init_common_record_context(&ctx, CMD_start);
+ parse_record_options(argc, argv, &ctx);
+ record_trace(argc, argv, &ctx);
+ exit(0);
+}
+
+void trace_extract(int argc, char **argv)
+{
+ struct common_record_context ctx;
+
+ init_common_record_context(&ctx, CMD_extract);
+ parse_record_options(argc, argv, &ctx);
+ record_trace(argc, argv, &ctx);
+ exit(0);
+}
+
+void trace_stream(int argc, char **argv)
+{
+ struct common_record_context ctx;
+
+ init_common_record_context(&ctx, CMD_stream);
+ parse_record_options(argc, argv, &ctx);
+ record_trace(argc, argv, &ctx);
+ exit(0);
+}
+
+void trace_profile(int argc, char **argv)
+{
+ struct common_record_context ctx;
+
+ init_common_record_context(&ctx, CMD_profile);
+
+ handle_init = trace_init_profile;
+ ctx.events = 1;
+
+ parse_record_options(argc, argv, &ctx);
+ record_trace(argc, argv, &ctx);
exit(0);
}
@@ -4932,23 +4979,8 @@ void trace_record(int argc, char **argv)
{
struct common_record_context ctx;
- init_common_record_context(&ctx);
-
- if (strcmp(argv[1], "record") == 0)
- ctx.curr_cmd = CMD_record;
- else if (strcmp(argv[1], "start") == 0)
- ctx.curr_cmd = CMD_start;
- else if (strcmp(argv[1], "extract") == 0)
- ctx.curr_cmd = CMD_extract;
- else if (strcmp(argv[1], "stream") == 0)
- ctx.curr_cmd = CMD_stream;
- else if (strcmp(argv[1], "profile") == 0) {
- ctx.curr_cmd = CMD_profile;
- handle_init = trace_init_profile;
- ctx.events = 1;
- } else
- usage(argv);
-
+ init_common_record_context(&ctx, CMD_record);
parse_record_options(argc, argv, &ctx);
record_trace(argc, argv, &ctx);
+ exit(0);
}
--
2.14.1
next prev parent reply other threads:[~2017-11-30 13:23 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-30 13:19 [PATCH v2 00/10] trace-cmd: Refactoring trace_record() Vladislav Valtchev (VMware)
2017-11-30 13:19 ` [PATCH v2 01/10] trace-cmd: Extract parse_record_options() from trace_record() Vladislav Valtchev (VMware)
2017-11-30 13:19 ` [PATCH v2 02/10] trace-cmd: Replacing cmd flags w/ a trace_cmd enum Vladislav Valtchev (VMware)
2017-11-30 13:19 ` [PATCH v2 03/10] trace-cmd: Extracting record_trace() Vladislav Valtchev (VMware)
2017-11-30 13:19 ` [PATCH v2 04/10] trace-cmd: Rename trace_profile() to do_trace_profile() Vladislav Valtchev (VMware)
2017-11-30 13:19 ` Vladislav Valtchev (VMware) [this message]
2017-11-30 13:19 ` [PATCH v2 06/10] trace-cmd: Extr. profile-specific code from record_trace Vladislav Valtchev (VMware)
2017-11-30 17:05 ` Steven Rostedt
2017-12-01 11:10 ` Vladislav Valtchev
2017-11-30 13:19 ` [PATCH v2 07/10] trace-cmd: Mov init_common_record_context in parse_record_options Vladislav Valtchev (VMware)
2017-11-30 17:07 ` Steven Rostedt
2017-12-01 11:20 ` Vladislav Valtchev
2017-11-30 13:19 ` [PATCH v2 08/10] trace-cmd: Introducing get_trace_cmd_type() Vladislav Valtchev (VMware)
2017-11-30 13:19 ` [PATCH v2 09/10] trace-cmd: Extract finalize_record_trace() Vladislav Valtchev (VMware)
2017-11-30 13:19 ` [PATCH v2 10/10] trace-cmd: Fork record_trace() for the extract case Vladislav Valtchev (VMware)
2017-11-30 21:37 ` [PATCH v2 00/10] trace-cmd: Refactoring trace_record() Steven Rostedt
2017-12-01 10:46 ` Vladislav Valtchev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171130131957.21617-6-vladislav.valtchev@gmail.com \
--to=vladislav.valtchev@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rostedt@goodmis.org \
--cc=y.karadz@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®