Skip to content

Commit 7697558

Browse files
makelinuxlenticularis39
authored andcommitted
tools/rtla: Consolidate -d/--duration option parsing
Each rtla tool duplicates parsing of -d/--duration. 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-5-costa.shul@redhat.com Signed-off-by: Tomas Glozar <tglozar@redhat.com>
1 parent fd788c4 commit 7697558

5 files changed

Lines changed: 11 additions & 29 deletions

File tree

tools/tracing/rtla/src/common.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ int common_parse_options(int argc, char **argv, struct common_params *common)
6060
{"cpus", required_argument, 0, 'c'},
6161
{"cgroup", optional_argument, 0, 'C'},
6262
{"debug", no_argument, 0, 'D'},
63+
{"duration", required_argument, 0, 'd'},
6364
{0, 0, 0, 0}
6465
};
6566

6667
opterr = 0;
67-
c = getopt_long(argc, argv, "c:C::D", long_options, NULL);
68+
c = getopt_long(argc, argv, "c:C::Dd:", long_options, NULL);
6869
opterr = 1;
6970

7071
switch (c) {
@@ -80,6 +81,11 @@ int common_parse_options(int argc, char **argv, struct common_params *common)
8081
case 'D':
8182
config_debug = 1;
8283
break;
84+
case 'd':
85+
common->duration = parse_seconds_duration(optarg);
86+
if (!common->duration)
87+
fatal("Invalid -d duration");
88+
break;
8389
default:
8490
optind = saved_state;
8591
return 0;

tools/tracing/rtla/src/osnoise_hist.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,6 @@ static struct common_params
485485
{"auto", required_argument, 0, 'a'},
486486
{"bucket-size", required_argument, 0, 'b'},
487487
{"entries", required_argument, 0, 'E'},
488-
{"duration", required_argument, 0, 'd'},
489488
{"house-keeping", required_argument, 0, 'H'},
490489
{"help", no_argument, 0, 'h'},
491490
{"period", required_argument, 0, 'p'},
@@ -512,7 +511,7 @@ static struct common_params
512511
if (common_parse_options(argc, argv, &params->common))
513512
continue;
514513

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

518517
/* detect the end of the options. */
@@ -538,11 +537,6 @@ static struct common_params
538537
params->common.hist.bucket_size >= 1000000)
539538
fatal("Bucket size needs to be > 0 and <= 1000000");
540539
break;
541-
case 'd':
542-
params->common.duration = parse_seconds_duration(optarg);
543-
if (!params->common.duration)
544-
fatal("Invalid -D duration");
545-
break;
546540
case 'e':
547541
tevent = trace_event_alloc(optarg);
548542
if (!tevent)

tools/tracing/rtla/src/osnoise_top.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)
339339
while (1) {
340340
static struct option long_options[] = {
341341
{"auto", required_argument, 0, 'a'},
342-
{"duration", required_argument, 0, 'd'},
343342
{"event", required_argument, 0, 'e'},
344343
{"house-keeping", required_argument, 0, 'H'},
345344
{"help", no_argument, 0, 'h'},
@@ -363,7 +362,7 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)
363362
if (common_parse_options(argc, argv, &params->common))
364363
continue;
365364

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

369368
/* Detect the end of the options. */
@@ -383,11 +382,6 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)
383382
trace_output = "osnoise_trace.txt";
384383

385384
break;
386-
case 'd':
387-
params->common.duration = parse_seconds_duration(optarg);
388-
if (!params->common.duration)
389-
fatal("Invalid -d duration");
390-
break;
391385
case 'e':
392386
tevent = trace_event_alloc(optarg);
393387
if (!tevent)

tools/tracing/rtla/src/timerlat_hist.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,6 @@ static struct common_params
793793
{"auto", required_argument, 0, 'a'},
794794
{"bucket-size", required_argument, 0, 'b'},
795795
{"entries", required_argument, 0, 'E'},
796-
{"duration", required_argument, 0, 'd'},
797796
{"house-keeping", required_argument, 0, 'H'},
798797
{"help", no_argument, 0, 'h'},
799798
{"irq", required_argument, 0, 'i'},
@@ -830,7 +829,7 @@ static struct common_params
830829
if (common_parse_options(argc, argv, &params->common))
831830
continue;
832831

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

836835
/* detect the end of the options. */
@@ -859,11 +858,6 @@ static struct common_params
859858
params->common.hist.bucket_size >= 1000000)
860859
fatal("Bucket size needs to be > 0 and <= 1000000");
861860
break;
862-
case 'd':
863-
params->common.duration = parse_seconds_duration(optarg);
864-
if (!params->common.duration)
865-
fatal("Invalid -D duration");
866-
break;
867861
case 'e':
868862
tevent = trace_event_alloc(optarg);
869863
if (!tevent)

tools/tracing/rtla/src/timerlat_top.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,6 @@ static struct common_params
561561
while (1) {
562562
static struct option long_options[] = {
563563
{"auto", required_argument, 0, 'a'},
564-
{"duration", required_argument, 0, 'd'},
565564
{"event", required_argument, 0, 'e'},
566565
{"help", no_argument, 0, 'h'},
567566
{"house-keeping", required_argument, 0, 'H'},
@@ -594,7 +593,7 @@ static struct common_params
594593
if (common_parse_options(argc, argv, &params->common))
595594
continue;
596595

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

600599
/* detect the end of the options. */
@@ -631,11 +630,6 @@ static struct common_params
631630
/* set aa_only to avoid parsing the trace */
632631
params->common.aa_only = 1;
633632
break;
634-
case 'd':
635-
params->common.duration = parse_seconds_duration(optarg);
636-
if (!params->common.duration)
637-
fatal("Invalid -d duration");
638-
break;
639633
case 'e':
640634
tevent = trace_event_alloc(optarg);
641635
if (!tevent)

0 commit comments

Comments
 (0)