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 11/11] 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 ae0733a..cc75b11 100644
--- a/trace-record.c
+++ b/trace-record.c
@@ -4734,6 +4734,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.
@@ -4741,7 +4762,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
@@ -4810,17 +4831,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-23 17:36    [W:0.169 / U:0.860 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site