]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
tools/rtla: Consolidate -c/--cpus option parsing
authorCosta Shulyupin <costa.shul@redhat.com>
Tue, 9 Dec 2025 10:00:41 +0000 (12:00 +0200)
committerTomas Glozar <tglozar@redhat.com>
Wed, 7 Jan 2026 14:57:16 +0000 (15:57 +0100)
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>
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 c01de7972bea52c8e82e8f84c0d831724dbb50a4..1b9e0108b0ba67a5fd202202291dc5e0d881a2ec 100644 (file)
@@ -57,14 +57,20 @@ int common_parse_options(int argc, char **argv, struct common_params *common)
        int c;
 
        static struct option long_options[] = {
+               {"cpus",                required_argument,      0, 'c'},
                {0, 0, 0, 0}
        };
 
        opterr = 0;
-       c = getopt_long(argc, argv, "", long_options, NULL);
+       c = getopt_long(argc, argv, "c:", long_options, NULL);
        opterr = 1;
 
        switch (c) {
+       case 'c':
+               if (parse_cpu_set(optarg, &common->monitored_cpus))
+                       fatal("Invalid -c cpu list");
+               common->cpus = optarg;
+               break;
        default:
                optind = saved_state;
                return 0;
index d5c78e07bf60774fb18fb37319fdc116e1893d65..443cb7f0e3a24d76fda9f8e3232e9d2f10dff76e 100644 (file)
@@ -485,7 +485,6 @@ static struct common_params
                        {"auto",                required_argument,      0, 'a'},
                        {"bucket-size",         required_argument,      0, 'b'},
                        {"entries",             required_argument,      0, 'E'},
-                       {"cpus",                required_argument,      0, 'c'},
                        {"cgroup",              optional_argument,      0, 'C'},
                        {"debug",               no_argument,            0, 'D'},
                        {"duration",            required_argument,      0, 'd'},
@@ -515,7 +514,7 @@ static struct common_params
                if (common_parse_options(argc, argv, &params->common))
                        continue;
 
-               c = getopt_long(argc, argv, "a:c:C::b:d:e:E:DhH:p:P:r:s:S:t::T:01234:5:6:7:",
+               c = getopt_long(argc, argv, "a:C::b:d:e:E:DhH:p:P:r:s:S:t::T:01234:5:6:7:",
                                 long_options, NULL);
 
                /* detect the end of the options. */
@@ -541,12 +540,6 @@ static struct common_params
                            params->common.hist.bucket_size >= 1000000)
                                fatal("Bucket size needs to be > 0 and <= 1000000");
                        break;
-               case 'c':
-                       retval = parse_cpu_set(optarg, &params->common.monitored_cpus);
-                       if (retval)
-                               fatal("Invalid -c cpu list");
-                       params->common.cpus = optarg;
-                       break;
                case 'C':
                        params->common.cgroup = 1;
                        params->common.cgroup_name = parse_optional_arg(argc, argv);
index 2bb154da1139595bd7328409637bc1b9f0145a1c..8ba0757225b3c4e6420d999aa183e45e9b0cb0ff 100644 (file)
@@ -339,7 +339,6 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)
        while (1) {
                static struct option long_options[] = {
                        {"auto",                required_argument,      0, 'a'},
-                       {"cpus",                required_argument,      0, 'c'},
                        {"cgroup",              optional_argument,      0, 'C'},
                        {"debug",               no_argument,            0, 'D'},
                        {"duration",            required_argument,      0, 'd'},
@@ -366,7 +365,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:c:C::d:De:hH:p:P:qr:s:S:t::T:0:1:2:3:",
+               c = getopt_long(argc, argv, "a:C::d:De:hH:p:P:qr:s:S:t::T:0:1:2:3:",
                                 long_options, NULL);
 
                /* Detect the end of the options. */
@@ -385,12 +384,6 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)
                        if (!trace_output)
                                trace_output = "osnoise_trace.txt";
 
-                       break;
-               case 'c':
-                       retval = parse_cpu_set(optarg, &params->common.monitored_cpus);
-                       if (retval)
-                               fatal("Invalid -c cpu list");
-                       params->common.cpus = optarg;
                        break;
                case 'C':
                        params->common.cgroup = 1;
index a17111b6aa6dae232501bbb974fc4e7b3050db47..3571aa8233c18be3d53230a0751d563a0e6e47c2 100644 (file)
@@ -791,7 +791,6 @@ static struct common_params
        while (1) {
                static struct option long_options[] = {
                        {"auto",                required_argument,      0, 'a'},
-                       {"cpus",                required_argument,      0, 'c'},
                        {"cgroup",              optional_argument,      0, 'C'},
                        {"bucket-size",         required_argument,      0, 'b'},
                        {"debug",               no_argument,            0, 'D'},
@@ -833,7 +832,7 @@ static struct common_params
                if (common_parse_options(argc, argv, &params->common))
                        continue;
 
-               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:",
+               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:",
                                 long_options, NULL);
 
                /* detect the end of the options. */
@@ -855,12 +854,6 @@ static struct common_params
                        if (!trace_output)
                                trace_output = "timerlat_trace.txt";
 
-                       break;
-               case 'c':
-                       retval = parse_cpu_set(optarg, &params->common.monitored_cpus);
-                       if (retval)
-                               fatal("Invalid -c cpu list");
-                       params->common.cpus = optarg;
                        break;
                case 'C':
                        params->common.cgroup = 1;
index b14a785361b1738402368bac5a712ea6e683520b..b0a048cded29c091286fa0b12aba4515237b79d3 100644 (file)
@@ -561,7 +561,6 @@ static struct common_params
        while (1) {
                static struct option long_options[] = {
                        {"auto",                required_argument,      0, 'a'},
-                       {"cpus",                required_argument,      0, 'c'},
                        {"cgroup",              optional_argument,      0, 'C'},
                        {"debug",               no_argument,            0, 'D'},
                        {"duration",            required_argument,      0, 'd'},
@@ -597,7 +596,7 @@ static struct common_params
                if (common_parse_options(argc, argv, &params->common))
                        continue;
 
-               c = getopt_long(argc, argv, "a:c:C::d:De:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:",
+               c = getopt_long(argc, argv, "a:C::d:De:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:",
                                 long_options, NULL);
 
                /* detect the end of the options. */
@@ -634,12 +633,6 @@ static struct common_params
                        /* set aa_only to avoid parsing the trace */
                        params->common.aa_only = 1;
                        break;
-               case 'c':
-                       retval = parse_cpu_set(optarg, &params->common.monitored_cpus);
-                       if (retval)
-                               fatal("Invalid -c cpu list");
-                       params->common.cpus = optarg;
-                       break;
                case 'C':
                        params->common.cgroup = 1;
                        params->common.cgroup_name = optarg;