mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 10:09:10 +02:00
tools/rtla: Add common_parse_options()
Each rtla tool duplicates parsing of many common options. This creates maintenance overhead and risks inconsistencies when updating these options. Add common_parse_options() to centralize parsing of options used across all tools. Common options to be migrated in future patches. Changes since v1: - restore opterr Signed-off-by: Costa Shulyupin <costa.shul@redhat.com> Link: https://lore.kernel.org/r/20251209100047.2692515-1-costa.shul@redhat.com Signed-off-by: Tomas Glozar <tglozar@redhat.com>
This commit is contained in:
parent
26e1a9bd4d
commit
850cd24cb6
|
|
@ -6,6 +6,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <getopt.h>
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
struct trace_instance *trace_inst;
|
struct trace_instance *trace_inst;
|
||||||
|
|
@ -38,6 +39,40 @@ static void set_signals(struct common_params *params)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* common_parse_options - parse common command line options
|
||||||
|
*
|
||||||
|
* @argc: argument count
|
||||||
|
* @argv: argument vector
|
||||||
|
* @common: common parameters structure
|
||||||
|
*
|
||||||
|
* Parse command line options that are common to all rtla tools.
|
||||||
|
*
|
||||||
|
* Returns: non zero if a common option was parsed, or 0
|
||||||
|
* if the option should be handled by tool-specific parsing.
|
||||||
|
*/
|
||||||
|
int common_parse_options(int argc, char **argv, struct common_params *common)
|
||||||
|
{
|
||||||
|
int saved_state = optind;
|
||||||
|
int c;
|
||||||
|
|
||||||
|
static struct option long_options[] = {
|
||||||
|
{0, 0, 0, 0}
|
||||||
|
};
|
||||||
|
|
||||||
|
opterr = 0;
|
||||||
|
c = getopt_long(argc, argv, "", long_options, NULL);
|
||||||
|
opterr = 1;
|
||||||
|
|
||||||
|
switch (c) {
|
||||||
|
default:
|
||||||
|
optind = saved_state;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* common_apply_config - apply common configs to the initialized tool
|
* common_apply_config - apply common configs to the initialized tool
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -156,6 +156,7 @@ int osnoise_set_stop_us(struct osnoise_context *context, long long stop_us);
|
||||||
int osnoise_set_stop_total_us(struct osnoise_context *context,
|
int osnoise_set_stop_total_us(struct osnoise_context *context,
|
||||||
long long stop_total_us);
|
long long stop_total_us);
|
||||||
|
|
||||||
|
int common_parse_options(int argc, char **argv, struct common_params *common);
|
||||||
int common_apply_config(struct osnoise_tool *tool, struct common_params *params);
|
int common_apply_config(struct osnoise_tool *tool, struct common_params *params);
|
||||||
int top_main_loop(struct osnoise_tool *tool);
|
int top_main_loop(struct osnoise_tool *tool);
|
||||||
int hist_main_loop(struct osnoise_tool *tool);
|
int hist_main_loop(struct osnoise_tool *tool);
|
||||||
|
|
|
||||||
|
|
@ -512,6 +512,9 @@ static struct common_params
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (common_parse_options(argc, argv, ¶ms->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:C::b:d:e:E:DhH:p:P:r:s:S:t::T:01234:5:6:7:",
|
||||||
long_options, NULL);
|
long_options, NULL);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -363,6 +363,9 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (common_parse_options(argc, argv, ¶ms->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:C::d:De:hH:p:P:qr:s:S:t::T:0:1:2:3:",
|
||||||
long_options, NULL);
|
long_options, NULL);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -830,6 +830,9 @@ static struct common_params
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (common_parse_options(argc, argv, ¶ms->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:C::b:d:e:E:DhH:i:knp:P:s:t::T:uU0123456:7:8:9\1\2:\3:",
|
||||||
long_options, NULL);
|
long_options, NULL);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -594,6 +594,9 @@ static struct common_params
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (common_parse_options(argc, argv, ¶ms->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:C::d:De:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:",
|
||||||
long_options, NULL);
|
long_options, NULL);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user