On Tue, Dec 09, 2025 at 12:00:42PM +0200, Costa Shulyupin wrote:
> 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 <[email protected]>
> ---
>  tools/tracing/rtla/src/common.c        | 7 ++++++-
>  tools/tracing/rtla/src/osnoise_hist.c  | 7 +------
>  tools/tracing/rtla/src/osnoise_top.c   | 7 +------
>  tools/tracing/rtla/src/timerlat_hist.c | 7 +------
>  tools/tracing/rtla/src/timerlat_top.c  | 7 +------
>  5 files changed, 10 insertions(+), 25 deletions(-)
> 
> diff --git a/tools/tracing/rtla/src/common.c b/tools/tracing/rtla/src/common.c
> index e5aa8c30cd7d..33428fa77f9f 100644
> --- a/tools/tracing/rtla/src/common.c
> +++ b/tools/tracing/rtla/src/common.c
> @@ -57,11 +57,12 @@ int common_parse_options(int argc, char **argv, struct 
> common_params *common)
>  
>       static struct option long_options[] = {
>               {"cpus",                required_argument,      0, 'c'},
> +             {"cgroup",              optional_argument,      0, 'C'},
>               {0, 0, 0, 0}
>       };
>  
>       opterr = 0;
> -     c = getopt_long(argc, argv, "c:", long_options, NULL);
> +     c = getopt_long(argc, argv, "c:C::", long_options, NULL);
>       opterr = 1;
>  
>       switch (c) {
> @@ -70,6 +71,10 @@ int common_parse_options(int argc, char **argv, struct 
> common_params *common)
>                       fatal("Invalid -c cpu list");
>               common->cpus = optarg;
>               break;
> +     case 'C':
> +             common->cgroup = 1;
> +             common->cgroup_name = parse_optional_arg(argc, argv);
> +             break;
>       default:
>               optind = saved_state;
>               return 0;
> diff --git a/tools/tracing/rtla/src/osnoise_hist.c 
> b/tools/tracing/rtla/src/osnoise_hist.c
> index 9e721362989a..5cbe5e1f1b07 100644
> --- a/tools/tracing/rtla/src/osnoise_hist.c
> +++ b/tools/tracing/rtla/src/osnoise_hist.c
> @@ -491,7 +491,6 @@ static struct common_params
>                       {"auto",                required_argument,      0, 'a'},
>                       {"bucket-size",         required_argument,      0, 'b'},
>                       {"entries",             required_argument,      0, 'E'},
> -                     {"cgroup",              optional_argument,      0, 'C'},
>                       {"debug",               no_argument,            0, 'D'},
>                       {"duration",            required_argument,      0, 'd'},
>                       {"house-keeping",       required_argument,              
> 0, 'H'},
> @@ -520,7 +519,7 @@ static struct common_params
>               if (common_parse_options(argc, argv, &params->common))
>                       continue;
>  
> -             c = getopt_long(argc, argv, 
> "a:C::b:d:e:E:DhH:p:P:r:s:S:t::T:01234:5:6:7:",
> +             c = getopt_long(argc, argv, 
> "a: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. */
> @@ -546,10 +545,6 @@ static struct common_params
>                           params->common.hist.bucket_size >= 1000000)
>                               fatal("Bucket size needs to be > 0 and <= 
> 1000000");
>                       break;
> -             case 'C':
> -                     params->common.cgroup = 1;
> -                     params->common.cgroup_name = parse_optional_arg(argc, 
> argv);
> -                     break;
>               case 'D':
>                       config_debug = 1;
>                       break;
> diff --git a/tools/tracing/rtla/src/osnoise_top.c 
> b/tools/tracing/rtla/src/osnoise_top.c
> index 73736cefd992..35db5b73c0d7 100644
> --- a/tools/tracing/rtla/src/osnoise_top.c
> +++ b/tools/tracing/rtla/src/osnoise_top.c
> @@ -346,7 +346,6 @@ struct common_params *osnoise_top_parse_args(int argc, 
> char **argv)
>       while (1) {
>               static struct option long_options[] = {
>                       {"auto",                required_argument,      0, 'a'},
> -                     {"cgroup",              optional_argument,      0, 'C'},
>                       {"debug",               no_argument,            0, 'D'},
>                       {"duration",            required_argument,      0, 'd'},
>                       {"event",               required_argument,      0, 'e'},
> @@ -372,7 +371,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::d:De:hH:p:P:qr:s:S:t::T:0:1:2:3:",
> +             c = getopt_long(argc, argv, 
> "a:d:De:hH:p:P:qr:s:S:t::T:0:1:2:3:",
>                                long_options, NULL);
>  
>               /* Detect the end of the options. */
> @@ -391,10 +390,6 @@ struct common_params *osnoise_top_parse_args(int argc, 
> char **argv)
>                       if (!trace_output)
>                               trace_output = "osnoise_trace.txt";
>  
> -                     break;
> -             case 'C':
> -                     params->common.cgroup = 1;
> -                     params->common.cgroup_name = parse_optional_arg(argc, 
> argv);
>                       break;
>               case 'D':
>                       config_debug = 1;
> diff --git a/tools/tracing/rtla/src/timerlat_hist.c 
> b/tools/tracing/rtla/src/timerlat_hist.c
> index 4ae77145adea..9ecab2bb0f1e 100644
> --- a/tools/tracing/rtla/src/timerlat_hist.c
> +++ b/tools/tracing/rtla/src/timerlat_hist.c
> @@ -796,7 +796,6 @@ static struct common_params
>       while (1) {
>               static struct option long_options[] = {
>                       {"auto",                required_argument,      0, 'a'},
> -                     {"cgroup",              optional_argument,      0, 'C'},
>                       {"bucket-size",         required_argument,      0, 'b'},
>                       {"debug",               no_argument,            0, 'D'},
>                       {"entries",             required_argument,      0, 'E'},
> @@ -836,7 +835,7 @@ static struct common_params
>               if (common_parse_options(argc, argv, &params->common))
>                       continue;
>  
> -             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:",
> +             c = getopt_long(argc, argv, 
> "a: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. */
> @@ -858,10 +857,6 @@ static struct common_params
>                       if (!trace_output)
>                               trace_output = "timerlat_trace.txt";
>  
> -                     break;
> -             case 'C':
> -                     params->common.cgroup = 1;
> -                     params->common.cgroup_name = parse_optional_arg(argc, 
> argv);
>                       break;
>               case 'b':
>                       params->common.hist.bucket_size = 
> get_llong_from_str(optarg);
> diff --git a/tools/tracing/rtla/src/timerlat_top.c 
> b/tools/tracing/rtla/src/timerlat_top.c
> index 9774c26b27ff..6329c3a489aa 100644
> --- a/tools/tracing/rtla/src/timerlat_top.c
> +++ b/tools/tracing/rtla/src/timerlat_top.c
> @@ -566,7 +566,6 @@ static struct common_params
>       while (1) {
>               static struct option long_options[] = {
>                       {"auto",                required_argument,      0, 'a'},
> -                     {"cgroup",              optional_argument,      0, 'C'},
>                       {"debug",               no_argument,            0, 'D'},
>                       {"duration",            required_argument,      0, 'd'},
>                       {"event",               required_argument,      0, 'e'},
> @@ -600,7 +599,7 @@ static struct common_params
>               if (common_parse_options(argc, argv, &params->common))
>                       continue;
>  
> -             c = getopt_long(argc, argv, 
> "a:C::d:De:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:",
> +             c = getopt_long(argc, argv, 
> "a:d:De:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:",
>                                long_options, NULL);
>  
>               /* detect the end of the options. */
> @@ -637,10 +636,6 @@ static struct common_params
>                       /* set aa_only to avoid parsing the trace */
>                       params->common.aa_only = 1;
>                       break;
> -             case 'C':
> -                     params->common.cgroup = 1;
> -                     params->common.cgroup_name = optarg;
> -                     break;
>               case 'D':
>                       config_debug = 1;
>                       break;
> -- 
> 2.52.0
> 

Reviewed-by: Wander Lairson Costa <[email protected]>


Reply via email to