tools/rtla: Consolidate common command line options
Subsystems (2)
cover tools/rtla: Consolidate common command line options
Argument parsing functions are the longest functions of the project:
lizard --warnings_only --sort nloc -L100 | head -n 4./src/timerlat_hist.c:766: warning: timerlat_hist_parse_args has 247 NLOC, 76 CCN, 1579 token, 1 PARAM, 287 length, 0 ND ./src/timerlat_top.c:538: warning: timerlat_top_parse_args has 217 NLOC, 64 CCN, 1338 token, 2 PARAM, 262 length, 0 ND ./src/osnoise_hist.c:469: warning: osnoise_hist_parse_args has 195 NLOC, 56 CCN, 1225 token, 1 PARAM, 216 length, 0 ND ./src/osnoise_top.c:322: warning: osnoise_top_parse_args has 169 NLOC, 46 CCN, 1019 token, 2 PARAM, 191 length, 0 ND
Moreover, they contain a lot of duplicate code and growing.
Refactor these functions to reduce code duplication.
Benefits:
- Single implementation for common options
- Easier maintenance and consistent behavior
Costa Shulyupin (8):
tools/rtla: Add common_parse_options() tools/rtla: Consolidate -c/--cpus option parsing tools/rtla: Consolidate -C/--cgroup option parsing tools/rtla: Consolidate -D/--debug option parsing tools/rtla: Consolidate -d/--duration option parsing tools/rtla: Consolidate -e/--event option parsing tools/rtla: Consolidate -P/--priority option parsing tools/rtla: Consolidate -H/--house-keeping option parsing
tools/tracing/rtla/src/common.c | 78 ++++++++++++++++++++++++++ tools/tracing/rtla/src/common.h | 1 + tools/tracing/rtla/src/osnoise_hist.c | 53 ++--------------- tools/tracing/rtla/src/osnoise_top.c | 53 ++--------------- tools/tracing/rtla/src/timerlat_hist.c | 53 ++--------------- tools/tracing/rtla/src/timerlat_top.c | 52 ++--------------- 6 files changed, 95 insertions(+), 195 deletions(-)
Signature · 1 line
2.51.1
PATCH 1/8 tools/rtla: Add common_parse_options()
Each rtla tool duplicates parsing of many common options. This creates maintenance overhead and risks inconsistencies when updating these options.
Add common_parse_options() to centralize parsing of options used across all tools.
Common options to be migrated in future patches.
--- tools/tracing/rtla/src/common.c | 34 ++++++++++++++++++++++++++ tools/tracing/rtla/src/common.h | 1 + tools/tracing/rtla/src/osnoise_hist.c | 3 +++ tools/tracing/rtla/src/osnoise_top.c | 3 +++ tools/tracing/rtla/src/timerlat_hist.c | 3 +++ tools/tracing/rtla/src/timerlat_top.c | 3 +++ 6 files changed, 47 insertions(+)
tools/tracing/rtla/src/common.c +34 -0
@@ -5,6 +5,7 @@#include <signal.h> #include <stdlib.h> #include <unistd.h> +#include <getopt.h> #include "common.h" struct trace_instance *trace_inst;
@@ -37,6 +38,39 @@ static void set_signals(struct common_params *params) } } +/* +* common_parse_options - parse common command line options +* +* @argc: argument count +* @argv: argument vector +* @common: common parameters structure +* +* Parse command line options that are common to all rtla tools. +* +* Returns: non zero if a common option was parsed, or 0 +* if the option should be handled by tool-specific parsing. +*/ +int common_parse_options (int argc,char **argv,struct common_params *common) +{ +int saved_state = optind; +int c; + +static struct option long_options[] = { + {0 ,0 ,0 ,0 } + }; + + opterr =0 ; + c =getopt_long (argc, argv,"" , long_options,NULL ); + +switch (c) { +default : + optind = saved_state; +return 0 ; + } + +return c; +} +/* * common_apply_config - apply common configs to the initialized tool */
tools/tracing/rtla/src/common.h +1 -0
@@ -153,6 +153,7 @@ struct osnoise_tool *osnoise_init_tool(char *tool_name);struct osnoise_tool *osnoise_init_trace_tool (const char *tracer);bool osnoise_trace_is_off (struct osnoise_tool *tool,struct osnoise_tool *record); +int common_parse_options (int argc,char **argv,struct common_params *common);int common_apply_config (struct osnoise_tool *tool,struct common_params *params);int top_main_loop (struct osnoise_tool *tool);int hist_main_loop (struct osnoise_tool *tool);
tools/tracing/rtla/src/osnoise_hist.c +3 -0
@@ -518,6 +518,9 @@ static struct common_params {0, 0, 0, 0} }; +if (common_parse_options (argc, argv, ¶ms->common)) +continue ; + c =getopt_long (argc, argv,"a:c:C::b:d:e:E:DhH:p:P:r:s:S:t::T:01234:5:6:7:" , long_options,NULL );
tools/tracing/rtla/src/osnoise_top.c +3 -0
@@ -370,6 +370,9 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv) {0, 0, 0, 0} }; +if (common_parse_options (argc, argv, ¶ms->common)) +continue ; + c =getopt_long (argc, argv,"a:c:C::d:De:hH:p:P:qr:s:S:t::T:0:1:2:3:" , long_options,NULL );
tools/tracing/rtla/src/timerlat_hist.c +3 -0
@@ -834,6 +834,9 @@ static struct common_params {0, 0, 0, 0} }; +if (common_parse_options (argc, argv, ¶ms->common)) +continue ; + c =getopt_long (argc, argv,"a:c:C::b:d:e:E:DhH:i:knp:P:s:t::T:uU0123456:7:8:9\1\2:\3:" , long_options,NULL );
tools/tracing/rtla/src/timerlat_top.c +3 -0
@@ -598,6 +598,9 @@ static struct common_params {0, 0, 0, 0} }; +if (common_parse_options (argc, argv, ¶ms->common)) +continue ; + c =getopt_long (argc, argv,"a:c:C::d:De:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:" , long_options,NULL );
Signature · 1 line
2.51.1
PATCH 2/8 tools/rtla: Consolidate -c/--cpus option parsing
In reply to Costa ShulyupinEach rtla tool duplicates parsing of -c/--cpus.
Migrate the option parsing from individual tools to the common_parse_options().
--- tools/tracing/rtla/src/common.c | 8 +++++++- tools/tracing/rtla/src/osnoise_hist.c | 9 +-------- tools/tracing/rtla/src/osnoise_top.c | 9 +-------- tools/tracing/rtla/src/timerlat_hist.c | 9 +-------- tools/tracing/rtla/src/timerlat_top.c | 9 +-------- 5 files changed, 11 insertions(+), 33 deletions(-)
tools/tracing/rtla/src/common.c +7 -1
@@ -56,13 +56,19 @@ int common_parse_options(int argc, char **argv, struct common_params *common)int c;static struct option long_options[] = { + {"cpus" , required_argument,0 ,'c' }, {0 ,0 ,0 ,0 } }; opterr =0 ; - c =getopt_long (argc, argv,"" , long_options,NULL ); + c =getopt_long (argc, argv,"c:" , long_options,NULL );switch (c) { +case 'c' : +if (parse_cpu_set (optarg, &common->monitored_cpus)) +fatal ("Invalid -c cpu list" ); + common->cpus = optarg; +break ;default : optind = saved_state;return 0 ;
tools/tracing/rtla/src/osnoise_hist.c +1 -8
@@ -491,7 +491,6 @@ static struct common_params {"auto", required_argument, 0, 'a'}, {"bucket-size", required_argument, 0, 'b'}, {"entries", required_argument, 0, 'E'}, - {"cpus", required_argument, 0, 'c'}, {"cgroup", optional_argument, 0, 'C'}, {"debug", no_argument, 0, 'D'}, {"duration", required_argument, 0, 'd'},
@@ -521,7 +520,7 @@ static struct common_paramsif (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:c:C::b:d:e:E:DhH:p:P:r:s:S:t::T:01234:5:6:7:" , + c =getopt_long (argc, argv,"a:C::b:d:e:E:DhH:p:P:r:s:S:t::T:01234:5:6:7:" , long_options,NULL );/* detect the end of the options. */
@@ -547,12 +546,6 @@ static struct common_params params->common.hist.bucket_size >= 1000000)fatal ("Bucket size needs to be > 0 and <= 1000000" );break ; -case 'c' : - retval =parse_cpu_set (optarg, ¶ms->common.monitored_cpus); -if (retval) -fatal ("Invalid -c cpu list" ); - params->common.cpus = optarg; -break ;case 'C' : params->common.cgroup =1 ; params->common.cgroup_name =parse_optional_arg (argc, argv);
tools/tracing/rtla/src/osnoise_top.c +1 -8
@@ -346,7 +346,6 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)while (1 ) {static struct option long_options[] = { {"auto" , required_argument,0 ,'a' }, - {"cpus" , required_argument,0 ,'c' }, {"cgroup" , optional_argument,0 ,'C' }, {"debug" , no_argument,0 ,'D' }, {"duration" , required_argument,0 ,'d' },
@@ -373,7 +372,7 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)if (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:c:C::d:De:hH:p:P:qr:s:S:t::T:0:1:2:3:" , + c =getopt_long (argc, argv,"a:C::d:De:hH:p:P:qr:s:S:t::T:0:1:2:3:" , long_options,NULL );/* Detect the end of the options. */
@@ -392,12 +391,6 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)if (!trace_output) trace_output ="osnoise_trace.txt" ; -break ; -case 'c' : - retval =parse_cpu_set (optarg, ¶ms->common.monitored_cpus); -if (retval) -fatal ("Invalid -c cpu list" ); - params->common.cpus = optarg;break ;case 'C' : params->common.cgroup =1 ;
tools/tracing/rtla/src/timerlat_hist.c +1 -8
@@ -796,7 +796,6 @@ static struct common_paramswhile (1 ) {static struct option long_options[] = { {"auto" , required_argument,0 ,'a' }, - {"cpus" , required_argument,0 ,'c' }, {"cgroup" , optional_argument,0 ,'C' }, {"bucket-size" , required_argument,0 ,'b' }, {"debug" , no_argument,0 ,'D' },
@@ -837,7 +836,7 @@ static struct common_paramsif (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:c:C::b:d:e:E:DhH:i:knp:P:s:t::T:uU0123456:7:8:9\1\2:\3:" , + c =getopt_long (argc, argv,"a:C::b:d:e:E:DhH:i:knp:P:s:t::T:uU0123456:7:8:9\1\2:\3:" , long_options,NULL );/* detect the end of the options. */
@@ -859,12 +858,6 @@ static struct common_paramsif (!trace_output) trace_output ="timerlat_trace.txt" ; -break ; -case 'c' : - retval =parse_cpu_set (optarg, ¶ms->common.monitored_cpus); -if (retval) -fatal ("Invalid -c cpu list" ); - params->common.cpus = optarg;break ;case 'C' : params->common.cgroup =1 ;
tools/tracing/rtla/src/timerlat_top.c +1 -8
@@ -566,7 +566,6 @@ static struct common_paramswhile (1 ) {static struct option long_options[] = { {"auto" , required_argument,0 ,'a' }, - {"cpus" , required_argument,0 ,'c' }, {"cgroup" , optional_argument,0 ,'C' }, {"debug" , no_argument,0 ,'D' }, {"duration" , required_argument,0 ,'d' },
@@ -601,7 +600,7 @@ static struct common_paramsif (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:c:C::d:De:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:" , + c =getopt_long (argc, argv,"a:C::d:De:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:" , long_options,NULL );/* detect the end of the options. */
@@ -638,12 +637,6 @@ static struct common_params/* set aa_only to avoid parsing the trace */ params->common.aa_only =1 ;break ; -case 'c' : - retval =parse_cpu_set (optarg, ¶ms->common.monitored_cpus); -if (retval) -fatal ("Invalid -c cpu list" ); - params->common.cpus = optarg; -break ;case 'C' : params->common.cgroup =1 ; params->common.cgroup_name = optarg;
Signature · 1 line
2.51.1
PATCH 3/8 tools/rtla: Consolidate -C/--cgroup option parsing
In reply to Costa ShulyupinEach rtla tool duplicates parsing of -C/--cgroup.
Migrate the option parsing from individual tools to the common_parse_options().
--- tools/tracing/rtla/src/common.c | 7 ++++++- tools/tracing/rtla/src/osnoise_hist.c | 7 +------ tools/tracing/rtla/src/osnoise_top.c | 7 +------ tools/tracing/rtla/src/timerlat_hist.c | 7 +------ tools/tracing/rtla/src/timerlat_top.c | 7 +------ 5 files changed, 10 insertions(+), 25 deletions(-)
tools/tracing/rtla/src/common.c +6 -1
@@ -57,11 +57,12 @@ int common_parse_options(int argc, char **argv, struct common_params *common)static struct option long_options[] = { {"cpus" , required_argument,0 ,'c' }, + {"cgroup" , optional_argument,0 ,'C' }, {0 ,0 ,0 ,0 } }; opterr =0 ; - c =getopt_long (argc, argv,"c:" , long_options,NULL ); + c =getopt_long (argc, argv,"c:C::" , long_options,NULL );switch (c) {case 'c' :
@@ -69,6 +70,10 @@ int common_parse_options(int argc, char **argv, struct common_params *common)fatal ("Invalid -c cpu list" ); common->cpus = optarg;break ; +case 'C' : + common->cgroup =1 ; + common->cgroup_name =parse_optional_arg (argc, argv); +break ;default : optind = saved_state;return 0 ;
tools/tracing/rtla/src/osnoise_hist.c +1 -6
@@ -491,7 +491,6 @@ static struct common_params {"auto", required_argument, 0, 'a'}, {"bucket-size", required_argument, 0, 'b'}, {"entries", required_argument, 0, 'E'}, - {"cgroup", optional_argument, 0, 'C'}, {"debug", no_argument, 0, 'D'}, {"duration", required_argument, 0, 'd'}, {"house-keeping", required_argument, 0, 'H'},
@@ -520,7 +519,7 @@ static struct common_paramsif (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:C::b:d:e:E:DhH:p:P:r:s:S:t::T:01234:5:6:7:" , + c =getopt_long (argc, argv,"a:b:d:e:E:DhH:p:P:r:s:S:t::T:01234:5:6:7:" , long_options,NULL );/* detect the end of the options. */
@@ -546,10 +545,6 @@ static struct common_params params->common.hist.bucket_size >= 1000000)fatal ("Bucket size needs to be > 0 and <= 1000000" );break ; -case 'C' : - params->common.cgroup =1 ; - params->common.cgroup_name =parse_optional_arg (argc, argv); -break ;case 'D' : config_debug =1 ;break ;
tools/tracing/rtla/src/osnoise_top.c +1 -6
@@ -346,7 +346,6 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)while (1 ) {static struct option long_options[] = { {"auto" , required_argument,0 ,'a' }, - {"cgroup" , optional_argument,0 ,'C' }, {"debug" , no_argument,0 ,'D' }, {"duration" , required_argument,0 ,'d' }, {"event" , required_argument,0 ,'e' },
@@ -372,7 +371,7 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)if (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:C::d:De:hH:p:P:qr:s:S:t::T:0:1:2:3:" , + c =getopt_long (argc, argv,"a:d:De:hH:p:P:qr:s:S:t::T:0:1:2:3:" , long_options,NULL );/* Detect the end of the options. */
@@ -391,10 +390,6 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)if (!trace_output) trace_output ="osnoise_trace.txt" ; -break ; -case 'C' : - params->common.cgroup =1 ; - params->common.cgroup_name =parse_optional_arg (argc, argv);break ;case 'D' : config_debug =1 ;
tools/tracing/rtla/src/timerlat_hist.c +1 -6
@@ -796,7 +796,6 @@ static struct common_paramswhile (1 ) {static struct option long_options[] = { {"auto" , required_argument,0 ,'a' }, - {"cgroup" , optional_argument,0 ,'C' }, {"bucket-size" , required_argument,0 ,'b' }, {"debug" , no_argument,0 ,'D' }, {"entries" , required_argument,0 ,'E' },
@@ -836,7 +835,7 @@ static struct common_paramsif (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:C::b:d:e:E:DhH:i:knp:P:s:t::T:uU0123456:7:8:9\1\2:\3:" , + c =getopt_long (argc, argv,"a:b:d:e:E:DhH:i:knp:P:s:t::T:uU0123456:7:8:9\1\2:\3:" , long_options,NULL );/* detect the end of the options. */
@@ -858,10 +857,6 @@ static struct common_paramsif (!trace_output) trace_output ="timerlat_trace.txt" ; -break ; -case 'C' : - params->common.cgroup =1 ; - params->common.cgroup_name =parse_optional_arg (argc, argv);break ;case 'b' : params->common.hist.bucket_size =get_llong_from_str (optarg);
tools/tracing/rtla/src/timerlat_top.c +1 -6
@@ -566,7 +566,6 @@ static struct common_paramswhile (1 ) {static struct option long_options[] = { {"auto" , required_argument,0 ,'a' }, - {"cgroup" , optional_argument,0 ,'C' }, {"debug" , no_argument,0 ,'D' }, {"duration" , required_argument,0 ,'d' }, {"event" , required_argument,0 ,'e' },
@@ -600,7 +599,7 @@ static struct common_paramsif (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:C::d:De:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:" , + c =getopt_long (argc, argv,"a:d:De:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:" , long_options,NULL );/* detect the end of the options. */
@@ -637,10 +636,6 @@ static struct common_params/* set aa_only to avoid parsing the trace */ params->common.aa_only =1 ;break ; -case 'C' : - params->common.cgroup =1 ; - params->common.cgroup_name = optarg; -break ;case 'D' : config_debug =1 ;break ;
Signature · 1 line
2.51.1
PATCH 4/8 tools/rtla: Consolidate -D/--debug option parsing
In reply to Costa ShulyupinEach rtla tool duplicates parsing of -D/--debug.
Migrate the option parsing from individual tools to the common_parse_options().
--- tools/tracing/rtla/src/common.c | 6 +++++- tools/tracing/rtla/src/osnoise_hist.c | 6 +----- tools/tracing/rtla/src/osnoise_top.c | 6 +----- tools/tracing/rtla/src/timerlat_hist.c | 6 +----- tools/tracing/rtla/src/timerlat_top.c | 6 +----- 5 files changed, 9 insertions(+), 21 deletions(-)
tools/tracing/rtla/src/common.c +5 -1
@@ -58,11 +58,12 @@ int common_parse_options(int argc, char **argv, struct common_params *common)static struct option long_options[] = { {"cpus" , required_argument,0 ,'c' }, {"cgroup" , optional_argument,0 ,'C' }, + {"debug" , no_argument,0 ,'D' }, {0 ,0 ,0 ,0 } }; opterr =0 ; - c =getopt_long (argc, argv,"c:C::" , long_options,NULL ); + c =getopt_long (argc, argv,"c:C::D" , long_options,NULL );switch (c) {case 'c' :
@@ -74,6 +75,9 @@ int common_parse_options(int argc, char **argv, struct common_params *common) common->cgroup =1 ; common->cgroup_name =parse_optional_arg (argc, argv);break ; +case 'D' : + config_debug =1 ; +break ;default : optind = saved_state;return 0 ;
tools/tracing/rtla/src/osnoise_hist.c +1 -5
@@ -491,7 +491,6 @@ static struct common_params {"auto", required_argument, 0, 'a'}, {"bucket-size", required_argument, 0, 'b'}, {"entries", required_argument, 0, 'E'}, - {"debug", no_argument, 0, 'D'}, {"duration", required_argument, 0, 'd'}, {"house-keeping", required_argument, 0, 'H'}, {"help", no_argument, 0, 'h'},
@@ -519,7 +518,7 @@ static struct common_paramsif (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:b:d:e:E:DhH:p:P:r:s:S:t::T:01234:5:6:7:" , + c =getopt_long (argc, argv,"a:b:d:e:E:hH:p:P:r:s:S:t::T:01234:5:6:7:" , long_options,NULL );/* detect the end of the options. */
@@ -545,9 +544,6 @@ static struct common_params params->common.hist.bucket_size >= 1000000)fatal ("Bucket size needs to be > 0 and <= 1000000" );break ; -case 'D' : - config_debug =1 ; -break ;case 'd' : params->common.duration =parse_seconds_duration (optarg);if (!params->common.duration)
tools/tracing/rtla/src/osnoise_top.c +1 -5
@@ -346,7 +346,6 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)while (1 ) {static struct option long_options[] = { {"auto" , required_argument,0 ,'a' }, - {"debug" , no_argument,0 ,'D' }, {"duration" , required_argument,0 ,'d' }, {"event" , required_argument,0 ,'e' }, {"house-keeping" , required_argument,0 ,'H' },
@@ -371,7 +370,7 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)if (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:d:De:hH:p:P:qr:s:S:t::T:0:1:2:3:" , + c =getopt_long (argc, argv,"a:d:e:hH:p:P:qr:s:S:t::T:0:1:2:3:" , long_options,NULL );/* Detect the end of the options. */
@@ -390,9 +389,6 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)if (!trace_output) trace_output ="osnoise_trace.txt" ; -break ; -case 'D' : - config_debug =1 ;break ;case 'd' : params->common.duration =parse_seconds_duration (optarg);
tools/tracing/rtla/src/timerlat_hist.c +1 -5
@@ -797,7 +797,6 @@ static struct common_paramsstatic struct option long_options[] = { {"auto" , required_argument,0 ,'a' }, {"bucket-size" , required_argument,0 ,'b' }, - {"debug" , no_argument,0 ,'D' }, {"entries" , required_argument,0 ,'E' }, {"duration" , required_argument,0 ,'d' }, {"house-keeping" , required_argument,0 ,'H' },
@@ -835,7 +834,7 @@ static struct common_paramsif (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:b:d:e:E:DhH:i:knp:P:s:t::T:uU0123456:7:8:9\1\2:\3:" , + c =getopt_long (argc, argv,"a:b:d:e:E:hH:i:knp:P:s:t::T:uU0123456:7:8:9\1\2:\3:" , long_options,NULL );/* detect the end of the options. */
@@ -864,9 +863,6 @@ static struct common_params params->common.hist.bucket_size >= 1000000)fatal ("Bucket size needs to be > 0 and <= 1000000" );break ; -case 'D' : - config_debug =1 ; -break ;case 'd' : params->common.duration =parse_seconds_duration (optarg);if (!params->common.duration)
tools/tracing/rtla/src/timerlat_top.c +1 -5
@@ -566,7 +566,6 @@ static struct common_paramswhile (1 ) {static struct option long_options[] = { {"auto" , required_argument,0 ,'a' }, - {"debug" , no_argument,0 ,'D' }, {"duration" , required_argument,0 ,'d' }, {"event" , required_argument,0 ,'e' }, {"help" , no_argument,0 ,'h' },
@@ -599,7 +598,7 @@ static struct common_paramsif (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:d:De:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:" , + c =getopt_long (argc, argv,"a:d:e:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:" , long_options,NULL );/* detect the end of the options. */
@@ -636,9 +635,6 @@ static struct common_params/* set aa_only to avoid parsing the trace */ params->common.aa_only =1 ;break ; -case 'D' : - config_debug =1 ; -break ;case 'd' : params->common.duration =parse_seconds_duration (optarg);if (!params->common.duration)
Signature · 1 line
2.51.1
PATCH 5/8 tools/rtla: Consolidate -d/--duration option parsing
In reply to Costa ShulyupinEach rtla tool duplicates parsing of -d/--duration.
Migrate the option parsing from individual tools to the common_parse_options().
--- tools/tracing/rtla/src/common.c | 8 +++++++- tools/tracing/rtla/src/osnoise_hist.c | 8 +------- tools/tracing/rtla/src/osnoise_top.c | 8 +------- tools/tracing/rtla/src/timerlat_hist.c | 8 +------- tools/tracing/rtla/src/timerlat_top.c | 8 +------- 5 files changed, 11 insertions(+), 29 deletions(-)
tools/tracing/rtla/src/common.c +7 -1
@@ -59,11 +59,12 @@ int common_parse_options(int argc, char **argv, struct common_params *common) {"cpus", required_argument, 0, 'c'}, {"cgroup", optional_argument, 0, 'C'}, {"debug", no_argument, 0, 'D'}, + {"duration", required_argument, 0, 'd'}, {0, 0, 0, 0} }; opterr =0 ; - c =getopt_long (argc, argv,"c:C::D" , long_options,NULL ); + c =getopt_long (argc, argv,"c:C::Dd:" , long_options,NULL );switch (c) {case 'c' :
@@ -78,6 +79,11 @@ int common_parse_options(int argc, char **argv, struct common_params *common)case 'D' : config_debug =1 ;break ; +case 'd' : + common->duration =parse_seconds_duration (optarg); +if (!common->duration) +fatal ("Invalid -d duration" ); +break ;default : optind = saved_state;return 0 ;
tools/tracing/rtla/src/osnoise_hist.c +1 -7
@@ -491,7 +491,6 @@ static struct common_params {"auto", required_argument, 0, 'a'}, {"bucket-size", required_argument, 0, 'b'}, {"entries", required_argument, 0, 'E'}, - {"duration", required_argument, 0, 'd'}, {"house-keeping", required_argument, 0, 'H'}, {"help", no_argument, 0, 'h'}, {"period", required_argument, 0, 'p'},
@@ -518,7 +517,7 @@ static struct common_paramsif (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:b:d:e:E:hH:p:P:r:s:S:t::T:01234:5:6:7:" , + c =getopt_long (argc, argv,"a:b:e:E:hH:p:P:r:s:S:t::T:01234:5:6:7:" , long_options,NULL );/* detect the end of the options. */
@@ -544,11 +543,6 @@ static struct common_params params->common.hist.bucket_size >= 1000000)fatal ("Bucket size needs to be > 0 and <= 1000000" );break ; -case 'd' : - params->common.duration =parse_seconds_duration (optarg); -if (!params->common.duration) -fatal ("Invalid -D duration" ); -break ;case 'e' : tevent =trace_event_alloc (optarg);if (!tevent)
tools/tracing/rtla/src/osnoise_top.c +1 -7
@@ -346,7 +346,6 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)while (1 ) {static struct option long_options[] = { {"auto" , required_argument,0 ,'a' }, - {"duration" , required_argument,0 ,'d' }, {"event" , required_argument,0 ,'e' }, {"house-keeping" , required_argument,0 ,'H' }, {"help" , no_argument,0 ,'h' },
@@ -370,7 +369,7 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)if (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:d:e:hH:p:P:qr:s:S:t::T:0:1:2:3:" , + c =getopt_long (argc, argv,"a:e:hH:p:P:qr:s:S:t::T:0:1:2:3:" , long_options,NULL );/* Detect the end of the options. */
@@ -390,11 +389,6 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv) trace_output ="osnoise_trace.txt" ;break ; -case 'd' : - params->common.duration =parse_seconds_duration (optarg); -if (!params->common.duration) -fatal ("Invalid -d duration" ); -break ;case 'e' : tevent =trace_event_alloc (optarg);if (!tevent)
tools/tracing/rtla/src/timerlat_hist.c +1 -7
@@ -798,7 +798,6 @@ static struct common_params {"auto", required_argument, 0, 'a'}, {"bucket-size", required_argument, 0, 'b'}, {"entries", required_argument, 0, 'E'}, - {"duration", required_argument, 0, 'd'}, {"house-keeping", required_argument, 0, 'H'}, {"help", no_argument, 0, 'h'}, {"irq", required_argument, 0, 'i'},
@@ -834,7 +833,7 @@ static struct common_paramsif (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:b:d:e:E:hH:i:knp:P:s:t::T:uU0123456:7:8:9\1\2:\3:" , + c =getopt_long (argc, argv,"a:b:e:E:hH:i:knp:P:s:t::T:uU0123456:7:8:9\1\2:\3:" , long_options,NULL );/* detect the end of the options. */
@@ -863,11 +862,6 @@ static struct common_params params->common.hist.bucket_size >= 1000000)fatal ("Bucket size needs to be > 0 and <= 1000000" );break ; -case 'd' : - params->common.duration =parse_seconds_duration (optarg); -if (!params->common.duration) -fatal ("Invalid -D duration" ); -break ;case 'e' : tevent =trace_event_alloc (optarg);if (!tevent)
tools/tracing/rtla/src/timerlat_top.c +1 -7
@@ -566,7 +566,6 @@ static struct common_paramswhile (1 ) {static struct option long_options[] = { {"auto" , required_argument,0 ,'a' }, - {"duration" , required_argument,0 ,'d' }, {"event" , required_argument,0 ,'e' }, {"help" , no_argument,0 ,'h' }, {"house-keeping" , required_argument,0 ,'H' },
@@ -598,7 +597,7 @@ static struct common_paramsif (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:d:e:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:" , + c =getopt_long (argc, argv,"a:e:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:" , long_options,NULL );/* detect the end of the options. */
@@ -635,11 +634,6 @@ static struct common_params/* set aa_only to avoid parsing the trace */ params->common.aa_only =1 ;break ; -case 'd' : - params->common.duration =parse_seconds_duration (optarg); -if (!params->common.duration) -fatal ("Invalid -d duration" ); -break ;case 'e' : tevent =trace_event_alloc (optarg);if (!tevent)
Signature · 1 line
2.51.1
PATCH 6/8 tools/rtla: Consolidate -e/--event option parsing
In reply to Costa ShulyupinEach rtla tool duplicates parsing of -e/--event.
Migrate the option parsing from individual tools to the common_parse_options().
--- tools/tracing/rtla/src/common.c | 13 ++++++++++++- tools/tracing/rtla/src/osnoise_hist.c | 14 +------------- tools/tracing/rtla/src/osnoise_top.c | 14 +------------- tools/tracing/rtla/src/timerlat_hist.c | 14 +------------- tools/tracing/rtla/src/timerlat_top.c | 13 +------------ 5 files changed, 16 insertions(+), 52 deletions(-)
tools/tracing/rtla/src/common.c +12 -1
@@ -52,6 +52,7 @@ static void set_signals(struct common_params *params)*/ int common_parse_options (int argc,char **argv,struct common_params *common) { +struct trace_events *tevent;int saved_state = optind;int c;
@@ -60,11 +61,12 @@ int common_parse_options(int argc, char **argv, struct common_params *common) {"cgroup", optional_argument, 0, 'C'}, {"debug", no_argument, 0, 'D'}, {"duration", required_argument, 0, 'd'}, + {"event", required_argument, 0, 'e'}, {0, 0, 0, 0} }; opterr =0 ; - c =getopt_long (argc, argv,"c:C::Dd:" , long_options,NULL ); + c =getopt_long (argc, argv,"c:C::Dd:e:" , long_options,NULL );switch (c) {case 'c' :
@@ -84,6 +86,15 @@ int common_parse_options(int argc, char **argv, struct common_params *common)if (!common->duration)fatal ("Invalid -d duration" );break ; +case 'e' : + tevent =trace_event_alloc (optarg); +if (!tevent) +fatal ("Error alloc trace event" ); + +if (common->events) + tevent->next = common->events; + common->events = tevent; +break ;default : optind = saved_state;return 0 ;
tools/tracing/rtla/src/osnoise_hist.c +1 -13
@@ -469,7 +469,6 @@ static struct common_params *osnoise_hist_parse_args(int argc, char *argv[]) {struct osnoise_params *params; -struct trace_events *tevent;int retval;int c;char *trace_output =NULL ;
@@ -499,7 +498,6 @@ static struct common_params {"stop", required_argument, 0, 's'}, {"stop-total", required_argument, 0, 'S'}, {"trace", optional_argument, 0, 't'}, - {"event", required_argument, 0, 'e'}, {"threshold", required_argument, 0, 'T'}, {"no-header", no_argument, 0, '0'}, {"no-summary", no_argument, 0, '1'},
@@ -517,7 +515,7 @@ static struct common_paramsif (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:b:e:E:hH:p:P:r:s:S:t::T:01234:5:6:7:" , + c =getopt_long (argc, argv,"a:b:E:hH:p:P:r:s:S:t::T:01234:5:6:7:" , long_options,NULL );/* detect the end of the options. */
@@ -543,16 +541,6 @@ static struct common_params params->common.hist.bucket_size >= 1000000)fatal ("Bucket size needs to be > 0 and <= 1000000" );break ; -case 'e' : - tevent =trace_event_alloc (optarg); -if (!tevent) -fatal ("Error alloc trace event" ); - -if (params->common.events) - tevent->next = params->common.events; - - params->common.events = tevent; -break ;case 'E' : params->common.hist.entries =get_llong_from_str (optarg); if (params->common.hist.entries < 10 ||
tools/tracing/rtla/src/osnoise_top.c +1 -13
@@ -322,7 +322,6 @@ static void osnoise_top_usage(struct osnoise_params *params)struct common_params *osnoise_top_parse_args (int argc,char **argv) {struct osnoise_params *params; -struct trace_events *tevent;int retval;int c;char *trace_output =NULL ;
@@ -346,7 +345,6 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)while (1 ) {static struct option long_options[] = { {"auto" , required_argument,0 ,'a' }, - {"event" , required_argument,0 ,'e' }, {"house-keeping" , required_argument,0 ,'H' }, {"help" , no_argument,0 ,'h' }, {"period" , required_argument,0 ,'p' },
@@ -369,7 +367,7 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)if (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:e:hH:p:P:qr:s:S:t::T:0:1:2:3:" , + c =getopt_long (argc, argv,"a:hH:p:P:qr:s:S:t::T:0:1:2:3:" , long_options,NULL );/* Detect the end of the options. */
@@ -388,16 +386,6 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)if (!trace_output) trace_output ="osnoise_trace.txt" ; -break ; -case 'e' : - tevent =trace_event_alloc (optarg); -if (!tevent) -fatal ("Error alloc trace event" ); - -if (params->common.events) - tevent->next = params->common.events; - params->common.events = tevent; -break ;case 'h' :case '?' :
tools/tracing/rtla/src/timerlat_hist.c +1 -13
@@ -766,7 +766,6 @@ static struct common_params *timerlat_hist_parse_args(int argc, char *argv[]) {struct timerlat_params *params; -struct trace_events *tevent;int auto_thresh;int retval;int c;
@@ -810,7 +809,6 @@ static struct common_params {"user-threads", no_argument, 0, 'u'}, {"kernel-threads", no_argument, 0, 'k'}, {"user-load", no_argument, 0, 'U'}, - {"event", required_argument, 0, 'e'}, {"no-irq", no_argument, 0, '0'}, {"no-thread", no_argument, 0, '1'}, {"no-header", no_argument, 0, '2'},
@@ -833,7 +831,7 @@ static struct common_paramsif (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:b:e:E:hH:i:knp:P:s:t::T:uU0123456:7:8:9\1\2:\3:" , + c =getopt_long (argc, argv,"a:b:E:hH:i:knp:P:s:t::T:uU0123456:7:8:9\1\2:\3:" , long_options,NULL );/* detect the end of the options. */
@@ -862,16 +860,6 @@ static struct common_params params->common.hist.bucket_size >= 1000000)fatal ("Bucket size needs to be > 0 and <= 1000000" );break ; -case 'e' : - tevent =trace_event_alloc (optarg); -if (!tevent) -fatal ("Error alloc trace event" ); - -if (params->common.events) - tevent->next = params->common.events; - - params->common.events = tevent; -break ;case 'E' : params->common.hist.entries =get_llong_from_str (optarg); if (params->common.hist.entries < 10 ||
tools/tracing/rtla/src/timerlat_top.c +1 -12
@@ -538,7 +538,6 @@ static struct common_params *timerlat_top_parse_args(int argc, char **argv) {struct timerlat_params *params; -struct trace_events *tevent;long long auto_thresh;int retval;int c;
@@ -566,7 +565,6 @@ static struct common_paramswhile (1 ) {static struct option long_options[] = { {"auto" , required_argument,0 ,'a' }, - {"event" , required_argument,0 ,'e' }, {"help" , no_argument,0 ,'h' }, {"house-keeping" , required_argument,0 ,'H' }, {"irq" , required_argument,0 ,'i' },
@@ -597,7 +595,7 @@ static struct common_paramsif (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:e:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:" , + c =getopt_long (argc, argv,"a:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:" , long_options,NULL );/* detect the end of the options. */
@@ -634,15 +632,6 @@ static struct common_params/* set aa_only to avoid parsing the trace */ params->common.aa_only =1 ;break ; -case 'e' : - tevent =trace_event_alloc (optarg); -if (!tevent) -fatal ("Error alloc trace event" ); - -if (params->common.events) - tevent->next = params->common.events; - params->common.events = tevent; -break ;case 'h' :case '?' :timerlat_top_usage ();
Signature · 1 line
2.51.1
PATCH 7/8 tools/rtla: Consolidate -P/--priority option parsing
In reply to Costa ShulyupinEach rtla tool duplicates parsing of -P/--priority.
Migrate the option parsing from individual tools to the common_parse_options().
--- tools/tracing/rtla/src/common.c | 8 +++++++- tools/tracing/rtla/src/osnoise_hist.c | 9 +-------- tools/tracing/rtla/src/osnoise_top.c | 9 +-------- tools/tracing/rtla/src/timerlat_hist.c | 9 +-------- tools/tracing/rtla/src/timerlat_top.c | 9 +-------- 5 files changed, 11 insertions(+), 33 deletions(-)
tools/tracing/rtla/src/common.c +7 -1
@@ -62,11 +62,12 @@ int common_parse_options(int argc, char **argv, struct common_params *common) {"debug", no_argument, 0, 'D'}, {"duration", required_argument, 0, 'd'}, {"event", required_argument, 0, 'e'}, + {"priority", required_argument, 0, 'P'}, {0, 0, 0, 0} }; opterr =0 ; - c =getopt_long (argc, argv,"c:C::Dd:e:" , long_options,NULL ); + c =getopt_long (argc, argv,"c:C::Dd:e:P:" , long_options,NULL );switch (c) {case 'c' :
@@ -95,6 +96,11 @@ int common_parse_options(int argc, char **argv, struct common_params *common) tevent->next = common->events; common->events = tevent;break ; +case 'P' : +if (parse_prio (optarg, &common->sched_param) ==-1 ) +fatal ("Invalid -P priority" ); + common->set_sched =1 ; +break ;default : optind = saved_state;return 0 ;
tools/tracing/rtla/src/osnoise_hist.c +1 -8
@@ -493,7 +493,6 @@ static struct common_params {"house-keeping", required_argument, 0, 'H'}, {"help", no_argument, 0, 'h'}, {"period", required_argument, 0, 'p'}, - {"priority", required_argument, 0, 'P'}, {"runtime", required_argument, 0, 'r'}, {"stop", required_argument, 0, 's'}, {"stop-total", required_argument, 0, 'S'},
@@ -515,7 +514,7 @@ static struct common_paramsif (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:b:E:hH:p:P:r:s:S:t::T:01234:5:6:7:" , + c =getopt_long (argc, argv,"a:b:E:hH:p:r:s:S:t::T:01234:5:6:7:" , long_options,NULL );/* detect the end of the options. */
@@ -562,12 +561,6 @@ static struct common_paramsif (params->period >10000000 )fatal ("Period longer than 10 s" );break ; -case 'P' : - retval =parse_prio (optarg, ¶ms->common.sched_param); -if (retval ==-1 ) -fatal ("Invalid -P priority" ); - params->common.set_sched =1 ; -break ;case 'r' : params->runtime =get_llong_from_str (optarg);if (params->runtime <100 )
tools/tracing/rtla/src/osnoise_top.c +1 -8
@@ -348,7 +348,6 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv) {"house-keeping", required_argument, 0, 'H'}, {"help", no_argument, 0, 'h'}, {"period", required_argument, 0, 'p'}, - {"priority", required_argument, 0, 'P'}, {"quiet", no_argument, 0, 'q'}, {"runtime", required_argument, 0, 'r'}, {"stop", required_argument, 0, 's'},
@@ -367,7 +366,7 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)if (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:hH:p:P:qr:s:S:t::T:0:1:2:3:" , + c =getopt_long (argc, argv,"a:hH:p:qr:s:S:t::T:0:1:2:3:" , long_options,NULL );/* Detect the end of the options. */
@@ -402,12 +401,6 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)if (params->period >10000000 )fatal ("Period longer than 10 s" );break ; -case 'P' : - retval =parse_prio (optarg, ¶ms->common.sched_param); -if (retval ==-1 ) -fatal ("Invalid -P priority" ); - params->common.set_sched =1 ; -break ;case 'q' : params->common.quiet =1 ;break ;
tools/tracing/rtla/src/timerlat_hist.c +1 -8
@@ -802,7 +802,6 @@ static struct common_params {"irq", required_argument, 0, 'i'}, {"nano", no_argument, 0, 'n'}, {"period", required_argument, 0, 'p'}, - {"priority", required_argument, 0, 'P'}, {"stack", required_argument, 0, 's'}, {"thread", required_argument, 0, 'T'}, {"trace", optional_argument, 0, 't'},
@@ -831,7 +830,7 @@ static struct common_paramsif (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:b:E:hH:i:knp:P:s:t::T:uU0123456:7:8:9\1\2:\3:" , + c =getopt_long (argc, argv,"a:b:E:hH:i:knp:s:t::T:uU0123456:7:8:9\1\2:\3:" , long_options,NULL );/* detect the end of the options. */
@@ -890,12 +889,6 @@ static struct common_paramsif (params->timerlat_period_us >1000000 )fatal ("Period longer than 1 s" );break ; -case 'P' : - retval =parse_prio (optarg, ¶ms->common.sched_param); -if (retval ==-1 ) -fatal ("Invalid -P priority" ); - params->common.set_sched =1 ; -break ;case 's' : params->print_stack =get_llong_from_str (optarg);break ;
tools/tracing/rtla/src/timerlat_top.c +1 -8
@@ -570,7 +570,6 @@ static struct common_params {"irq", required_argument, 0, 'i'}, {"nano", no_argument, 0, 'n'}, {"period", required_argument, 0, 'p'}, - {"priority", required_argument, 0, 'P'}, {"quiet", no_argument, 0, 'q'}, {"stack", required_argument, 0, 's'}, {"thread", required_argument, 0, 'T'},
@@ -595,7 +594,7 @@ static struct common_paramsif (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:" , + c =getopt_long (argc, argv,"a:hH:i:knp:qs:t::T:uU0:1:2:345:6:7:" , long_options,NULL );/* detect the end of the options. */
@@ -656,12 +655,6 @@ static struct common_paramsif (params->timerlat_period_us >1000000 )fatal ("Period longer than 1 s" );break ; -case 'P' : - retval =parse_prio (optarg, ¶ms->common.sched_param); -if (retval ==-1 ) -fatal ("Invalid -P priority" ); - params->common.set_sched =1 ; -break ;case 'q' : params->common.quiet =1 ;break ;
Signature · 1 line
2.51.1
PATCH 8/8 tools/rtla: Consolidate -H/--house-keeping option parsing
In reply to Costa ShulyupinEach rtla tool duplicates parsing of -H/--house-keeping.
Migrate the option parsing from individual tools to the common_parse_options().
--- tools/tracing/rtla/src/common.c | 8 +++++++- tools/tracing/rtla/src/osnoise_hist.c | 9 +-------- tools/tracing/rtla/src/osnoise_top.c | 9 +-------- tools/tracing/rtla/src/timerlat_hist.c | 9 +-------- tools/tracing/rtla/src/timerlat_top.c | 9 +-------- 5 files changed, 11 insertions(+), 33 deletions(-)
tools/tracing/rtla/src/common.c +7 -1
@@ -62,12 +62,13 @@ int common_parse_options(int argc, char **argv, struct common_params *common) {"debug", no_argument, 0, 'D'}, {"duration", required_argument, 0, 'd'}, {"event", required_argument, 0, 'e'}, + {"house-keeping", required_argument, 0, 'H'}, {"priority", required_argument, 0, 'P'}, {0, 0, 0, 0} }; opterr =0 ; - c =getopt_long (argc, argv,"c:C::Dd:e:P:" , long_options,NULL ); + c =getopt_long (argc, argv,"c:C::Dd:e:H:P:" , long_options,NULL );switch (c) {case 'c' :
@@ -96,6 +97,11 @@ int common_parse_options(int argc, char **argv, struct common_params *common) tevent->next = common->events; common->events = tevent;break ; +case 'H' : + common->hk_cpus =1 ; +if (parse_cpu_set (optarg, &common->hk_cpu_set)) +fatal ("Error parsing house keeping CPUs" ); +break ;case 'P' :if (parse_prio (optarg, &common->sched_param) ==-1 )fatal ("Invalid -P priority" );
tools/tracing/rtla/src/osnoise_hist.c +1 -8
@@ -490,7 +490,6 @@ static struct common_params {"auto", required_argument, 0, 'a'}, {"bucket-size", required_argument, 0, 'b'}, {"entries", required_argument, 0, 'E'}, - {"house-keeping", required_argument, 0, 'H'}, {"help", no_argument, 0, 'h'}, {"period", required_argument, 0, 'p'}, {"runtime", required_argument, 0, 'r'},
@@ -514,7 +513,7 @@ static struct common_paramsif (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:b:E:hH:p:r:s:S:t::T:01234:5:6:7:" , + c =getopt_long (argc, argv,"a:b:E:hp:r:s:S:t::T:01234:5:6:7:" , long_options,NULL );/* detect the end of the options. */
@@ -550,12 +549,6 @@ static struct common_paramscase '?' :osnoise_hist_usage ();break ; -case 'H' : - params->common.hk_cpus =1 ; - retval =parse_cpu_set (optarg, ¶ms->common.hk_cpu_set); -if (retval) -fatal ("Error parsing house keeping CPUs" ); -break ;case 'p' : params->period =get_llong_from_str (optarg);if (params->period >10000000 )
tools/tracing/rtla/src/osnoise_top.c +1 -8
@@ -345,7 +345,6 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)while (1 ) {static struct option long_options[] = { {"auto" , required_argument,0 ,'a' }, - {"house-keeping" , required_argument,0 ,'H' }, {"help" , no_argument,0 ,'h' }, {"period" , required_argument,0 ,'p' }, {"quiet" , no_argument,0 ,'q' },
@@ -366,7 +365,7 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)if (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:hH:p:qr:s:S:t::T:0:1:2:3:" , + c =getopt_long (argc, argv,"a:hp:qr:s:S:t::T:0:1:2:3:" , long_options,NULL );/* Detect the end of the options. */
@@ -390,12 +389,6 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)case '?' :osnoise_top_usage (params);break ; -case 'H' : - params->common.hk_cpus =1 ; - retval =parse_cpu_set (optarg, ¶ms->common.hk_cpu_set); -if (retval) -fatal ("Error parsing house keeping CPUs" ); -break ;case 'p' : params->period =get_llong_from_str (optarg);if (params->period >10000000 )
tools/tracing/rtla/src/timerlat_hist.c +1 -8
@@ -797,7 +797,6 @@ static struct common_params {"auto", required_argument, 0, 'a'}, {"bucket-size", required_argument, 0, 'b'}, {"entries", required_argument, 0, 'E'}, - {"house-keeping", required_argument, 0, 'H'}, {"help", no_argument, 0, 'h'}, {"irq", required_argument, 0, 'i'}, {"nano", no_argument, 0, 'n'},
@@ -830,7 +829,7 @@ static struct common_paramsif (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:b:E:hH:i:knp:s:t::T:uU0123456:7:8:9\1\2:\3:" , + c =getopt_long (argc, argv,"a:b:E:hi:knp:s:t::T:uU0123456:7:8:9\1\2:\3:" , long_options,NULL );/* detect the end of the options. */
@@ -869,12 +868,6 @@ static struct common_paramscase '?' :timerlat_hist_usage ();break ; -case 'H' : - params->common.hk_cpus =1 ; - retval =parse_cpu_set (optarg, ¶ms->common.hk_cpu_set); -if (retval) -fatal ("Error parsing house keeping CPUs" ); -break ;case 'i' : params->common.stop_us =get_llong_from_str (optarg);break ;
tools/tracing/rtla/src/timerlat_top.c +1 -8
@@ -566,7 +566,6 @@ static struct common_paramsstatic struct option long_options[] = { {"auto" , required_argument,0 ,'a' }, {"help" , no_argument,0 ,'h' }, - {"house-keeping" , required_argument,0 ,'H' }, {"irq" , required_argument,0 ,'i' }, {"nano" , no_argument,0 ,'n' }, {"period" , required_argument,0 ,'p' },
@@ -594,7 +593,7 @@ static struct common_paramsif (common_parse_options (argc, argv, ¶ms->common))continue ; - c =getopt_long (argc, argv,"a:hH:i:knp:qs:t::T:uU0:1:2:345:6:7:" , + c =getopt_long (argc, argv,"a:hi:knp:qs:t::T:uU0:1:2:345:6:7:" , long_options,NULL );/* detect the end of the options. */
@@ -635,12 +634,6 @@ static struct common_paramscase '?' :timerlat_top_usage ();break ; -case 'H' : - params->common.hk_cpus =1 ; - retval =parse_cpu_set (optarg, ¶ms->common.hk_cpu_set); -if (retval) -fatal ("Error parsing house keeping CPUs" ); -break ;case 'i' : params->common.stop_us =get_llong_from_str (optarg);break ;
Signature · 1 line
2.51.1
Quoted 26 lines · Costa Shulyupin
Argument parsing functions are the longest functions of the project:
lizard --warnings_only --sort nloc -L100 | head -n 4
./src/timerlat_hist.c:766: warning:timerlat_hist_parse_argshas 247 NLOC, 76 CCN, 1579 token, 1 PARAM, 287 length, 0 ND./src/timerlat_top.c:538: warning:timerlat_top_parse_argshas 217 NLOC, 64 CCN, 1338 token, 2 PARAM, 262 length, 0 ND./src/osnoise_hist.c:469: warning:osnoise_hist_parse_argshas 195 NLOC, 56 CCN, 1225 token, 1 PARAM, 216 length, 0 ND./src/osnoise_top.c:322: warning:osnoise_top_parse_argshas 169 NLOC, 46 CCN, 1019 token, 2 PARAM, 191 length, 0 NDMoreover, they contain a lot of duplicate code and growing.
Refactor these functions to reduce code duplication.
Benefits:
- Single implementation for common options
- Easier maintenance and consistent behaviorCosta Shulyupin (8):
tools/rtla: Addcommon_parse_options()tools/rtla: Consolidate -c/--cpus option parsingtools/rtla: Consolidate -C/--cgroup option parsingtools/rtla: Consolidate -D/--debug option parsingtools/rtla: Consolidate -d/--duration option parsingtools/rtla: Consolidate -e/--event option parsingtools/rtla: Consolidate -P/--priority option parsingtools/rtla: Consolidate -H/--house-keeping option parsing
Quoted 7 lines
tools/tracing/rtla/src/common.c | 78 ++++++++++++++++++++++++++ tools/tracing/rtla/src/common.h | 1 + tools/tracing/rtla/src/osnoise_hist.c | 53 ++--------------- tools/tracing/rtla/src/osnoise_top.c | 53 ++--------------- tools/tracing/rtla/src/timerlat_hist.c | 53 ++--------------- tools/tracing/rtla/src/timerlat_top.c | 52 ++--------------- 6 files changed, 95 insertions(+), 195 deletions(-)
-Crystal