Skip to content

Commit 850cd24

Browse files
makelinuxlenticularis39
authored andcommitted
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. Changes since v1: - restore opterr Signed-off-by: Costa Shulyupin <costa.shul@redhat.com> Link: https://lore.kernel.org/r/20251209100047.2692515-1-costa.shul@redhat.com Signed-off-by: Tomas Glozar <tglozar@redhat.com>
1 parent 26e1a9b commit 850cd24

6 files changed

Lines changed: 48 additions & 0 deletions

File tree

tools/tracing/rtla/src/common.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <stdlib.h>
77
#include <string.h>
88
#include <unistd.h>
9+
#include <getopt.h>
910
#include "common.h"
1011

1112
struct trace_instance *trace_inst;
@@ -38,6 +39,40 @@ static void set_signals(struct common_params *params)
3839
}
3940
}
4041

42+
/*
43+
* common_parse_options - parse common command line options
44+
*
45+
* @argc: argument count
46+
* @argv: argument vector
47+
* @common: common parameters structure
48+
*
49+
* Parse command line options that are common to all rtla tools.
50+
*
51+
* Returns: non zero if a common option was parsed, or 0
52+
* if the option should be handled by tool-specific parsing.
53+
*/
54+
int common_parse_options(int argc, char **argv, struct common_params *common)
55+
{
56+
int saved_state = optind;
57+
int c;
58+
59+
static struct option long_options[] = {
60+
{0, 0, 0, 0}
61+
};
62+
63+
opterr = 0;
64+
c = getopt_long(argc, argv, "", long_options, NULL);
65+
opterr = 1;
66+
67+
switch (c) {
68+
default:
69+
optind = saved_state;
70+
return 0;
71+
}
72+
73+
return c;
74+
}
75+
4176
/*
4277
* common_apply_config - apply common configs to the initialized tool
4378
*/

tools/tracing/rtla/src/common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ int osnoise_set_stop_us(struct osnoise_context *context, long long stop_us);
156156
int osnoise_set_stop_total_us(struct osnoise_context *context,
157157
long long stop_total_us);
158158

159+
int common_parse_options(int argc, char **argv, struct common_params *common);
159160
int common_apply_config(struct osnoise_tool *tool, struct common_params *params);
160161
int top_main_loop(struct osnoise_tool *tool);
161162
int hist_main_loop(struct osnoise_tool *tool);

tools/tracing/rtla/src/osnoise_hist.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,9 @@ static struct common_params
512512
{0, 0, 0, 0}
513513
};
514514

515+
if (common_parse_options(argc, argv, &params->common))
516+
continue;
517+
515518
c = getopt_long(argc, argv, "a:c:C::b:d:e:E:DhH:p:P:r:s:S:t::T:01234:5:6:7:",
516519
long_options, NULL);
517520

tools/tracing/rtla/src/osnoise_top.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)
363363
{0, 0, 0, 0}
364364
};
365365

366+
if (common_parse_options(argc, argv, &params->common))
367+
continue;
368+
366369
c = getopt_long(argc, argv, "a:c:C::d:De:hH:p:P:qr:s:S:t::T:0:1:2:3:",
367370
long_options, NULL);
368371

tools/tracing/rtla/src/timerlat_hist.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,9 @@ static struct common_params
830830
{0, 0, 0, 0}
831831
};
832832

833+
if (common_parse_options(argc, argv, &params->common))
834+
continue;
835+
833836
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:",
834837
long_options, NULL);
835838

tools/tracing/rtla/src/timerlat_top.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,9 @@ static struct common_params
594594
{0, 0, 0, 0}
595595
};
596596

597+
if (common_parse_options(argc, argv, &params->common))
598+
continue;
599+
597600
c = getopt_long(argc, argv, "a:c:C::d:De:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:",
598601
long_options, NULL);
599602

0 commit comments

Comments
 (0)