[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20171130131957.21617-9-vladislav.valtchev@gmail.com>
Date: Thu, 30 Nov 2017 15:19:55 +0200
From: "Vladislav Valtchev (VMware)" <vladislav.valtchev@...il.com>
To: rostedt@...dmis.org
Cc: linux-kernel@...r.kernel.org, y.karadz@...il.com,
"Vladislav Valtchev (VMware)" <vladislav.valtchev@...il.com>
Subject: [PATCH v2 08/10] trace-cmd: Introducing get_trace_cmd_type()
This patch aims to reduce the size of common_record_commads_code() by removing
a relatively long 'else if' sequence that was used to do the mapping between the
current trace command and the trace_type used by it.
Signed-off-by: Vladislav Valtchev (VMware) <vladislav.valtchev@...il.com>
---
trace-record.c | 34 ++++++++++++++++++++++------------
1 file changed, 22 insertions(+), 12 deletions(-)
diff --git a/trace-record.c b/trace-record.c
index 7688565..ec0eaed 100644
--- a/trace-record.c
+++ b/trace-record.c
@@ -4746,6 +4746,27 @@ static void parse_record_options(int argc,
}
}
+static enum trace_type get_trace_cmd_type(enum trace_cmd cmd)
+{
+ const static struct {
+ enum trace_cmd cmd;
+ enum trace_type ttype;
+ } trace_type_per_command[] = {
+ {CMD_record, TRACE_TYPE_RECORD},
+ {CMD_stream, TRACE_TYPE_STREAM},
+ {CMD_extract, TRACE_TYPE_EXTRACT},
+ {CMD_profile, TRACE_TYPE_STREAM},
+ {CMD_start, TRACE_TYPE_START}
+ };
+
+ for (int i = 0; i < ARRAY_SIZE(trace_type_per_command); i++) {
+ if (trace_type_per_command[i].cmd == cmd)
+ return trace_type_per_command[i].ttype;
+ }
+
+ die("Trace type UNKNOWN for the given cmd_fun");
+}
+
/*
* This function contains common code for the following commands:
* record, start, extract, stream, profile.
@@ -4753,7 +4774,7 @@ static void parse_record_options(int argc,
static void record_trace(int argc, char **argv,
struct common_record_context *ctx)
{
- enum trace_type type = 0;
+ enum trace_type type = get_trace_cmd_type(ctx->curr_cmd);
/*
* If top_instance doesn't have any plugins or events, then
@@ -4820,17 +4841,6 @@ static void record_trace(int argc, char **argv,
set_buffer_size();
}
- if (IS_RECORD(ctx))
- type = TRACE_TYPE_RECORD;
- else if (IS_STREAM(ctx))
- type = TRACE_TYPE_STREAM;
- else if (IS_EXTRACT(ctx))
- type = TRACE_TYPE_EXTRACT;
- else if (IS_PROFILE(ctx))
- type = TRACE_TYPE_STREAM;
- else
- type = TRACE_TYPE_START;
-
update_plugins(type);
set_options();
--
2.14.1
Powered by blists - more mailing lists