lkml.org 
[lkml]   [2017]   [Nov]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2 08/10] trace-cmd: Introducing get_trace_cmd_type()
Date
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@gmail.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
\
 
 \ /
  Last update: 2017-11-30 14:22    [W:0.084 / U:0.272 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site