lkml.org 
[lkml]   [2017]   [Nov]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 02/11] trace-cmd: Extract trace_restart() from trace_record()
Date
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) <vladislav.valtchev@gmail.com>
---
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
\
 
 \ /
  Last update: 2017-11-23 17:38    [W:0.192 / U:0.060 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site