]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
tools/rtla: Consolidate -e/--event option parsing
authorCosta Shulyupin <costa.shul@redhat.com>
Tue, 9 Dec 2025 10:00:45 +0000 (12:00 +0200)
committerTomas Glozar <tglozar@redhat.com>
Wed, 7 Jan 2026 14:57:17 +0000 (15:57 +0100)
Each rtla tool duplicates parsing of -e/--event.

Migrate the option parsing from individual tools to the
common_parse_options().

Signed-off-by: Costa Shulyupin <costa.shul@redhat.com>
Link: https://lore.kernel.org/r/20251209100047.2692515-6-costa.shul@redhat.com
Signed-off-by: Tomas Glozar <tglozar@redhat.com>
tools/tracing/rtla/src/common.c
tools/tracing/rtla/src/osnoise_hist.c
tools/tracing/rtla/src/osnoise_top.c
tools/tracing/rtla/src/timerlat_hist.c
tools/tracing/rtla/src/timerlat_top.c

index 0776f1568d23e63ee5a9bcc2da7203580349e802..fbd38d80f1ac528a62f8e04455afefd4be10a00c 100644 (file)
@@ -53,6 +53,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;
 
@@ -61,11 +62,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);
        opterr = 1;
 
        switch (c) {
@@ -86,6 +88,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;
index f34c88fd57e2d8e05dc5323422bc8e6f2a29cacc..8b3eab6092bbb43a930542b66c01f44b8babfc7e 100644 (file)
@@ -463,7 +463,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;
@@ -493,7 +492,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'},
@@ -511,7 +509,7 @@ static struct common_params
                if (common_parse_options(argc, argv, &params->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. */
@@ -537,16 +535,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 ||
index 695c6ecf00982913007902ca176d5c4b579c1a13..47aac00e2848528338f02a3e09e2dd01377ed8fe 100644 (file)
@@ -315,7 +315,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;
@@ -339,7 +338,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'},
@@ -362,7 +360,7 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)
                if (common_parse_options(argc, argv, &params->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. */
@@ -381,16 +379,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 '?':
index d625dbe446762a651c59dac31ae99a51f5191062..32424e2bd34a505d6fab48fe5a5b143e9181e4f2 100644 (file)
@@ -761,7 +761,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;
@@ -805,7 +804,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'},
@@ -829,7 +827,7 @@ static struct common_params
                if (common_parse_options(argc, argv, &params->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. */
@@ -858,16 +856,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 ||
index 95e949f49cbd55ff23fad2a11f685c5958c5fbfa..928d887e0c2e235619ddfa67614e2980bf849d67 100644 (file)
@@ -533,7 +533,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;
@@ -561,7 +560,6 @@ static struct common_params
        while (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'},
@@ -593,7 +591,7 @@ static struct common_params
                if (common_parse_options(argc, argv, &params->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. */
@@ -630,15 +628,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();