Skip to content

Commit c93c25f

Browse files
makelinuxlenticularis39
authored andcommitted
tools/rtla: Consolidate -e/--event option parsing
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>
1 parent 7697558 commit c93c25f

5 files changed

Lines changed: 16 additions & 52 deletions

File tree

tools/tracing/rtla/src/common.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ static void set_signals(struct common_params *params)
5353
*/
5454
int common_parse_options(int argc, char **argv, struct common_params *common)
5555
{
56+
struct trace_events *tevent;
5657
int saved_state = optind;
5758
int c;
5859

@@ -61,11 +62,12 @@ int common_parse_options(int argc, char **argv, struct common_params *common)
6162
{"cgroup", optional_argument, 0, 'C'},
6263
{"debug", no_argument, 0, 'D'},
6364
{"duration", required_argument, 0, 'd'},
65+
{"event", required_argument, 0, 'e'},
6466
{0, 0, 0, 0}
6567
};
6668

6769
opterr = 0;
68-
c = getopt_long(argc, argv, "c:C::Dd:", long_options, NULL);
70+
c = getopt_long(argc, argv, "c:C::Dd:e:", long_options, NULL);
6971
opterr = 1;
7072

7173
switch (c) {
@@ -86,6 +88,15 @@ int common_parse_options(int argc, char **argv, struct common_params *common)
8688
if (!common->duration)
8789
fatal("Invalid -d duration");
8890
break;
91+
case 'e':
92+
tevent = trace_event_alloc(optarg);
93+
if (!tevent)
94+
fatal("Error alloc trace event");
95+
96+
if (common->events)
97+
tevent->next = common->events;
98+
common->events = tevent;
99+
break;
89100
default:
90101
optind = saved_state;
91102
return 0;

tools/tracing/rtla/src/osnoise_hist.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,6 @@ static struct common_params
463463
*osnoise_hist_parse_args(int argc, char *argv[])
464464
{
465465
struct osnoise_params *params;
466-
struct trace_events *tevent;
467466
int retval;
468467
int c;
469468
char *trace_output = NULL;
@@ -493,7 +492,6 @@ static struct common_params
493492
{"stop", required_argument, 0, 's'},
494493
{"stop-total", required_argument, 0, 'S'},
495494
{"trace", optional_argument, 0, 't'},
496-
{"event", required_argument, 0, 'e'},
497495
{"threshold", required_argument, 0, 'T'},
498496
{"no-header", no_argument, 0, '0'},
499497
{"no-summary", no_argument, 0, '1'},
@@ -511,7 +509,7 @@ static struct common_params
511509
if (common_parse_options(argc, argv, &params->common))
512510
continue;
513511

514-
c = getopt_long(argc, argv, "a:b:e:E:hH:p:P:r:s:S:t::T:01234:5:6:7:",
512+
c = getopt_long(argc, argv, "a:b:E:hH:p:P:r:s:S:t::T:01234:5:6:7:",
515513
long_options, NULL);
516514

517515
/* detect the end of the options. */
@@ -537,16 +535,6 @@ static struct common_params
537535
params->common.hist.bucket_size >= 1000000)
538536
fatal("Bucket size needs to be > 0 and <= 1000000");
539537
break;
540-
case 'e':
541-
tevent = trace_event_alloc(optarg);
542-
if (!tevent)
543-
fatal("Error alloc trace event");
544-
545-
if (params->common.events)
546-
tevent->next = params->common.events;
547-
548-
params->common.events = tevent;
549-
break;
550538
case 'E':
551539
params->common.hist.entries = get_llong_from_str(optarg);
552540
if (params->common.hist.entries < 10 ||

tools/tracing/rtla/src/osnoise_top.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ static void osnoise_top_usage(struct osnoise_params *params)
315315
struct common_params *osnoise_top_parse_args(int argc, char **argv)
316316
{
317317
struct osnoise_params *params;
318-
struct trace_events *tevent;
319318
int retval;
320319
int c;
321320
char *trace_output = NULL;
@@ -339,7 +338,6 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)
339338
while (1) {
340339
static struct option long_options[] = {
341340
{"auto", required_argument, 0, 'a'},
342-
{"event", required_argument, 0, 'e'},
343341
{"house-keeping", required_argument, 0, 'H'},
344342
{"help", no_argument, 0, 'h'},
345343
{"period", required_argument, 0, 'p'},
@@ -362,7 +360,7 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)
362360
if (common_parse_options(argc, argv, &params->common))
363361
continue;
364362

365-
c = getopt_long(argc, argv, "a:e:hH:p:P:qr:s:S:t::T:0:1:2:3:",
363+
c = getopt_long(argc, argv, "a:hH:p:P:qr:s:S:t::T:0:1:2:3:",
366364
long_options, NULL);
367365

368366
/* Detect the end of the options. */
@@ -381,16 +379,6 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)
381379
if (!trace_output)
382380
trace_output = "osnoise_trace.txt";
383381

384-
break;
385-
case 'e':
386-
tevent = trace_event_alloc(optarg);
387-
if (!tevent)
388-
fatal("Error alloc trace event");
389-
390-
if (params->common.events)
391-
tevent->next = params->common.events;
392-
params->common.events = tevent;
393-
394382
break;
395383
case 'h':
396384
case '?':

tools/tracing/rtla/src/timerlat_hist.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,6 @@ static struct common_params
761761
*timerlat_hist_parse_args(int argc, char *argv[])
762762
{
763763
struct timerlat_params *params;
764-
struct trace_events *tevent;
765764
int auto_thresh;
766765
int retval;
767766
int c;
@@ -805,7 +804,6 @@ static struct common_params
805804
{"user-threads", no_argument, 0, 'u'},
806805
{"kernel-threads", no_argument, 0, 'k'},
807806
{"user-load", no_argument, 0, 'U'},
808-
{"event", required_argument, 0, 'e'},
809807
{"no-irq", no_argument, 0, '0'},
810808
{"no-thread", no_argument, 0, '1'},
811809
{"no-header", no_argument, 0, '2'},
@@ -829,7 +827,7 @@ static struct common_params
829827
if (common_parse_options(argc, argv, &params->common))
830828
continue;
831829

832-
c = getopt_long(argc, argv, "a:b:e:E:hH:i:knp:P:s:t::T:uU0123456:7:8:9\1\2:\3:",
830+
c = getopt_long(argc, argv, "a:b:E:hH:i:knp:P:s:t::T:uU0123456:7:8:9\1\2:\3:",
833831
long_options, NULL);
834832

835833
/* detect the end of the options. */
@@ -858,16 +856,6 @@ static struct common_params
858856
params->common.hist.bucket_size >= 1000000)
859857
fatal("Bucket size needs to be > 0 and <= 1000000");
860858
break;
861-
case 'e':
862-
tevent = trace_event_alloc(optarg);
863-
if (!tevent)
864-
fatal("Error alloc trace event");
865-
866-
if (params->common.events)
867-
tevent->next = params->common.events;
868-
869-
params->common.events = tevent;
870-
break;
871859
case 'E':
872860
params->common.hist.entries = get_llong_from_str(optarg);
873861
if (params->common.hist.entries < 10 ||

tools/tracing/rtla/src/timerlat_top.c

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,6 @@ static struct common_params
533533
*timerlat_top_parse_args(int argc, char **argv)
534534
{
535535
struct timerlat_params *params;
536-
struct trace_events *tevent;
537536
long long auto_thresh;
538537
int retval;
539538
int c;
@@ -561,7 +560,6 @@ static struct common_params
561560
while (1) {
562561
static struct option long_options[] = {
563562
{"auto", required_argument, 0, 'a'},
564-
{"event", required_argument, 0, 'e'},
565563
{"help", no_argument, 0, 'h'},
566564
{"house-keeping", required_argument, 0, 'H'},
567565
{"irq", required_argument, 0, 'i'},
@@ -593,7 +591,7 @@ static struct common_params
593591
if (common_parse_options(argc, argv, &params->common))
594592
continue;
595593

596-
c = getopt_long(argc, argv, "a:e:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:",
594+
c = getopt_long(argc, argv, "a:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:",
597595
long_options, NULL);
598596

599597
/* detect the end of the options. */
@@ -630,15 +628,6 @@ static struct common_params
630628
/* set aa_only to avoid parsing the trace */
631629
params->common.aa_only = 1;
632630
break;
633-
case 'e':
634-
tevent = trace_event_alloc(optarg);
635-
if (!tevent)
636-
fatal("Error alloc trace event");
637-
638-
if (params->common.events)
639-
tevent->next = params->common.events;
640-
params->common.events = tevent;
641-
break;
642631
case 'h':
643632
case '?':
644633
timerlat_top_usage();

0 commit comments

Comments
 (0)