Skip to content

Commit 28dc445

Browse files
makelinuxlenticularis39
authored andcommitted
tools/rtla: Consolidate -c/--cpus option parsing
Each rtla tool duplicates parsing of -c/--cpus. 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-2-costa.shul@redhat.com Signed-off-by: Tomas Glozar <tglozar@redhat.com>
1 parent 850cd24 commit 28dc445

5 files changed

Lines changed: 11 additions & 33 deletions

File tree

tools/tracing/rtla/src/common.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,20 @@ int common_parse_options(int argc, char **argv, struct common_params *common)
5757
int c;
5858

5959
static struct option long_options[] = {
60+
{"cpus", required_argument, 0, 'c'},
6061
{0, 0, 0, 0}
6162
};
6263

6364
opterr = 0;
64-
c = getopt_long(argc, argv, "", long_options, NULL);
65+
c = getopt_long(argc, argv, "c:", long_options, NULL);
6566
opterr = 1;
6667

6768
switch (c) {
69+
case 'c':
70+
if (parse_cpu_set(optarg, &common->monitored_cpus))
71+
fatal("Invalid -c cpu list");
72+
common->cpus = optarg;
73+
break;
6874
default:
6975
optind = saved_state;
7076
return 0;

tools/tracing/rtla/src/osnoise_hist.c

Lines changed: 1 addition & 8 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-
{"cpus", required_argument, 0, 'c'},
489488
{"cgroup", optional_argument, 0, 'C'},
490489
{"debug", no_argument, 0, 'D'},
491490
{"duration", required_argument, 0, 'd'},
@@ -515,7 +514,7 @@ static struct common_params
515514
if (common_parse_options(argc, argv, &params->common))
516515
continue;
517516

518-
c = getopt_long(argc, argv, "a:c:C::b:d:e:E:DhH:p:P:r:s:S:t::T:01234:5:6:7:",
517+
c = getopt_long(argc, argv, "a:C::b:d:e:E:DhH:p:P:r:s:S:t::T:01234:5:6:7:",
519518
long_options, NULL);
520519

521520
/* detect the end of the options. */
@@ -541,12 +540,6 @@ static struct common_params
541540
params->common.hist.bucket_size >= 1000000)
542541
fatal("Bucket size needs to be > 0 and <= 1000000");
543542
break;
544-
case 'c':
545-
retval = parse_cpu_set(optarg, &params->common.monitored_cpus);
546-
if (retval)
547-
fatal("Invalid -c cpu list");
548-
params->common.cpus = optarg;
549-
break;
550543
case 'C':
551544
params->common.cgroup = 1;
552545
params->common.cgroup_name = parse_optional_arg(argc, argv);

tools/tracing/rtla/src/osnoise_top.c

Lines changed: 1 addition & 8 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-
{"cpus", required_argument, 0, 'c'},
343342
{"cgroup", optional_argument, 0, 'C'},
344343
{"debug", no_argument, 0, 'D'},
345344
{"duration", required_argument, 0, 'd'},
@@ -366,7 +365,7 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)
366365
if (common_parse_options(argc, argv, &params->common))
367366
continue;
368367

369-
c = getopt_long(argc, argv, "a:c:C::d:De:hH:p:P:qr:s:S:t::T:0:1:2:3:",
368+
c = getopt_long(argc, argv, "a:C::d:De:hH:p:P:qr:s:S:t::T:0:1:2:3:",
370369
long_options, NULL);
371370

372371
/* Detect the end of the options. */
@@ -385,12 +384,6 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)
385384
if (!trace_output)
386385
trace_output = "osnoise_trace.txt";
387386

388-
break;
389-
case 'c':
390-
retval = parse_cpu_set(optarg, &params->common.monitored_cpus);
391-
if (retval)
392-
fatal("Invalid -c cpu list");
393-
params->common.cpus = optarg;
394387
break;
395388
case 'C':
396389
params->common.cgroup = 1;

tools/tracing/rtla/src/timerlat_hist.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,6 @@ static struct common_params
791791
while (1) {
792792
static struct option long_options[] = {
793793
{"auto", required_argument, 0, 'a'},
794-
{"cpus", required_argument, 0, 'c'},
795794
{"cgroup", optional_argument, 0, 'C'},
796795
{"bucket-size", required_argument, 0, 'b'},
797796
{"debug", no_argument, 0, 'D'},
@@ -833,7 +832,7 @@ static struct common_params
833832
if (common_parse_options(argc, argv, &params->common))
834833
continue;
835834

836-
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:",
835+
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:",
837836
long_options, NULL);
838837

839838
/* detect the end of the options. */
@@ -855,12 +854,6 @@ static struct common_params
855854
if (!trace_output)
856855
trace_output = "timerlat_trace.txt";
857856

858-
break;
859-
case 'c':
860-
retval = parse_cpu_set(optarg, &params->common.monitored_cpus);
861-
if (retval)
862-
fatal("Invalid -c cpu list");
863-
params->common.cpus = optarg;
864857
break;
865858
case 'C':
866859
params->common.cgroup = 1;

tools/tracing/rtla/src/timerlat_top.c

Lines changed: 1 addition & 8 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-
{"cpus", required_argument, 0, 'c'},
565564
{"cgroup", optional_argument, 0, 'C'},
566565
{"debug", no_argument, 0, 'D'},
567566
{"duration", required_argument, 0, 'd'},
@@ -597,7 +596,7 @@ static struct common_params
597596
if (common_parse_options(argc, argv, &params->common))
598597
continue;
599598

600-
c = getopt_long(argc, argv, "a:c:C::d:De:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:",
599+
c = getopt_long(argc, argv, "a:C::d:De:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:",
601600
long_options, NULL);
602601

603602
/* detect the end of the options. */
@@ -634,12 +633,6 @@ static struct common_params
634633
/* set aa_only to avoid parsing the trace */
635634
params->common.aa_only = 1;
636635
break;
637-
case 'c':
638-
retval = parse_cpu_set(optarg, &params->common.monitored_cpus);
639-
if (retval)
640-
fatal("Invalid -c cpu list");
641-
params->common.cpus = optarg;
642-
break;
643636
case 'C':
644637
params->common.cgroup = 1;
645638
params->common.cgroup_name = optarg;

0 commit comments

Comments
 (0)