Skip to content

Commit edb23c8

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

5 files changed

Lines changed: 10 additions & 25 deletions

File tree

tools/tracing/rtla/src/common.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ int common_parse_options(int argc, char **argv, struct common_params *common)
5858

5959
static struct option long_options[] = {
6060
{"cpus", required_argument, 0, 'c'},
61+
{"cgroup", optional_argument, 0, 'C'},
6162
{0, 0, 0, 0}
6263
};
6364

6465
opterr = 0;
65-
c = getopt_long(argc, argv, "c:", long_options, NULL);
66+
c = getopt_long(argc, argv, "c:C::", long_options, NULL);
6667
opterr = 1;
6768

6869
switch (c) {
@@ -71,6 +72,10 @@ int common_parse_options(int argc, char **argv, struct common_params *common)
7172
fatal("Invalid -c cpu list");
7273
common->cpus = optarg;
7374
break;
75+
case 'C':
76+
common->cgroup = 1;
77+
common->cgroup_name = parse_optional_arg(argc, argv);
78+
break;
7479
default:
7580
optind = saved_state;
7681
return 0;

tools/tracing/rtla/src/osnoise_hist.c

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

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

520519
/* detect the end of the options. */
@@ -540,10 +539,6 @@ static struct common_params
540539
params->common.hist.bucket_size >= 1000000)
541540
fatal("Bucket size needs to be > 0 and <= 1000000");
542541
break;
543-
case 'C':
544-
params->common.cgroup = 1;
545-
params->common.cgroup_name = parse_optional_arg(argc, argv);
546-
break;
547542
case 'D':
548543
config_debug = 1;
549544
break;

tools/tracing/rtla/src/osnoise_top.c

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

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

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

387-
break;
388-
case 'C':
389-
params->common.cgroup = 1;
390-
params->common.cgroup_name = parse_optional_arg(argc, argv);
391386
break;
392387
case 'D':
393388
config_debug = 1;

tools/tracing/rtla/src/timerlat_hist.c

Lines changed: 1 addition & 6 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-
{"cgroup", optional_argument, 0, 'C'},
795794
{"bucket-size", required_argument, 0, 'b'},
796795
{"debug", no_argument, 0, 'D'},
797796
{"entries", required_argument, 0, 'E'},
@@ -832,7 +831,7 @@ static struct common_params
832831
if (common_parse_options(argc, argv, &params->common))
833832
continue;
834833

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:",
834+
c = getopt_long(argc, argv, "a:b:d:e:E:DhH:i:knp:P:s:t::T:uU0123456:7:8:9\1\2:\3:",
836835
long_options, NULL);
837836

838837
/* detect the end of the options. */
@@ -854,10 +853,6 @@ static struct common_params
854853
if (!trace_output)
855854
trace_output = "timerlat_trace.txt";
856855

857-
break;
858-
case 'C':
859-
params->common.cgroup = 1;
860-
params->common.cgroup_name = parse_optional_arg(argc, argv);
861856
break;
862857
case 'b':
863858
params->common.hist.bucket_size = get_llong_from_str(optarg);

tools/tracing/rtla/src/timerlat_top.c

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

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

602601
/* detect the end of the options. */
@@ -633,10 +632,6 @@ static struct common_params
633632
/* set aa_only to avoid parsing the trace */
634633
params->common.aa_only = 1;
635634
break;
636-
case 'C':
637-
params->common.cgroup = 1;
638-
params->common.cgroup_name = optarg;
639-
break;
640635
case 'D':
641636
config_debug = 1;
642637
break;

0 commit comments

Comments
 (0)