Commit c93c25fc authored by Costa Shulyupin's avatar Costa Shulyupin Committed by Tomas Glozar
Browse files

tools/rtla: Consolidate -e/--event option parsing



Each rtla tool duplicates parsing of -e/--event.

Migrate the option parsing from individual tools to the
common_parse_options().

Signed-off-by: default avatarCosta Shulyupin <costa.shul@redhat.com>
Link: https://lore.kernel.org/r/20251209100047.2692515-6-costa.shul@redhat.com


Signed-off-by: default avatarTomas Glozar <tglozar@redhat.com>
parent 76975581
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ static void set_signals(struct common_params *params)
 */
int common_parse_options(int argc, char **argv, struct common_params *common)
{
	struct trace_events *tevent;
	int saved_state = optind;
	int c;

@@ -61,11 +62,12 @@ int common_parse_options(int argc, char **argv, struct common_params *common)
		{"cgroup",              optional_argument,      0, 'C'},
		{"debug",               no_argument,            0, 'D'},
		{"duration",            required_argument,      0, 'd'},
		{"event",               required_argument,      0, 'e'},
		{0, 0, 0, 0}
	};

	opterr = 0;
	c = getopt_long(argc, argv, "c:C::Dd:", long_options, NULL);
	c = getopt_long(argc, argv, "c:C::Dd:e:", long_options, NULL);
	opterr = 1;

	switch (c) {
@@ -86,6 +88,15 @@ int common_parse_options(int argc, char **argv, struct common_params *common)
		if (!common->duration)
			fatal("Invalid -d duration");
		break;
	case 'e':
		tevent = trace_event_alloc(optarg);
		if (!tevent)
			fatal("Error alloc trace event");

		if (common->events)
			tevent->next = common->events;
		common->events = tevent;
		break;
	default:
		optind = saved_state;
		return 0;
+1 −13
Original line number Diff line number Diff line
@@ -463,7 +463,6 @@ static struct common_params
*osnoise_hist_parse_args(int argc, char *argv[])
{
	struct osnoise_params *params;
	struct trace_events *tevent;
	int retval;
	int c;
	char *trace_output = NULL;
@@ -493,7 +492,6 @@ static struct common_params
			{"stop",		required_argument,	0, 's'},
			{"stop-total",		required_argument,	0, 'S'},
			{"trace",		optional_argument,	0, 't'},
			{"event",		required_argument,	0, 'e'},
			{"threshold",		required_argument,	0, 'T'},
			{"no-header",		no_argument,		0, '0'},
			{"no-summary",		no_argument,		0, '1'},
@@ -511,7 +509,7 @@ static struct common_params
		if (common_parse_options(argc, argv, &params->common))
			continue;

		c = getopt_long(argc, argv, "a:b:e:E:hH:p:P:r:s:S:t::T:01234:5:6:7:",
		c = getopt_long(argc, argv, "a:b:E:hH:p:P:r:s:S:t::T:01234:5:6:7:",
				 long_options, NULL);

		/* detect the end of the options. */
@@ -537,16 +535,6 @@ static struct common_params
			    params->common.hist.bucket_size >= 1000000)
				fatal("Bucket size needs to be > 0 and <= 1000000");
			break;
		case 'e':
			tevent = trace_event_alloc(optarg);
			if (!tevent)
				fatal("Error alloc trace event");

			if (params->common.events)
				tevent->next = params->common.events;

			params->common.events = tevent;
			break;
		case 'E':
			params->common.hist.entries = get_llong_from_str(optarg);
			if (params->common.hist.entries < 10 ||
+1 −13
Original line number Diff line number Diff line
@@ -315,7 +315,6 @@ static void osnoise_top_usage(struct osnoise_params *params)
struct common_params *osnoise_top_parse_args(int argc, char **argv)
{
	struct osnoise_params *params;
	struct trace_events *tevent;
	int retval;
	int c;
	char *trace_output = NULL;
@@ -339,7 +338,6 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)
	while (1) {
		static struct option long_options[] = {
			{"auto",		required_argument,	0, 'a'},
			{"event",		required_argument,	0, 'e'},
			{"house-keeping",	required_argument,	0, 'H'},
			{"help",		no_argument,		0, 'h'},
			{"period",		required_argument,	0, 'p'},
@@ -362,7 +360,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:e:hH:p:P:qr:s:S:t::T:0:1:2:3:",
		c = getopt_long(argc, argv, "a:hH:p:P:qr:s:S:t::T:0:1:2:3:",
				 long_options, NULL);

		/* Detect the end of the options. */
@@ -381,16 +379,6 @@ struct common_params *osnoise_top_parse_args(int argc, char **argv)
			if (!trace_output)
				trace_output = "osnoise_trace.txt";

			break;
		case 'e':
			tevent = trace_event_alloc(optarg);
			if (!tevent)
				fatal("Error alloc trace event");

			if (params->common.events)
				tevent->next = params->common.events;
			params->common.events = tevent;

			break;
		case 'h':
		case '?':
+1 −13
Original line number Diff line number Diff line
@@ -761,7 +761,6 @@ static struct common_params
*timerlat_hist_parse_args(int argc, char *argv[])
{
	struct timerlat_params *params;
	struct trace_events *tevent;
	int auto_thresh;
	int retval;
	int c;
@@ -805,7 +804,6 @@ static struct common_params
			{"user-threads",	no_argument,		0, 'u'},
			{"kernel-threads",	no_argument,		0, 'k'},
			{"user-load",		no_argument,		0, 'U'},
			{"event",		required_argument,	0, 'e'},
			{"no-irq",		no_argument,		0, '0'},
			{"no-thread",		no_argument,		0, '1'},
			{"no-header",		no_argument,		0, '2'},
@@ -829,7 +827,7 @@ static struct common_params
		if (common_parse_options(argc, argv, &params->common))
			continue;

		c = getopt_long(argc, argv, "a:b:e:E:hH:i:knp:P:s:t::T:uU0123456:7:8:9\1\2:\3:",
		c = getopt_long(argc, argv, "a:b:E:hH:i:knp:P:s:t::T:uU0123456:7:8:9\1\2:\3:",
				 long_options, NULL);

		/* detect the end of the options. */
@@ -858,16 +856,6 @@ static struct common_params
			    params->common.hist.bucket_size >= 1000000)
				fatal("Bucket size needs to be > 0 and <= 1000000");
			break;
		case 'e':
			tevent = trace_event_alloc(optarg);
			if (!tevent)
				fatal("Error alloc trace event");

			if (params->common.events)
				tevent->next = params->common.events;

			params->common.events = tevent;
			break;
		case 'E':
			params->common.hist.entries = get_llong_from_str(optarg);
			if (params->common.hist.entries < 10 ||
+1 −12
Original line number Diff line number Diff line
@@ -533,7 +533,6 @@ static struct common_params
*timerlat_top_parse_args(int argc, char **argv)
{
	struct timerlat_params *params;
	struct trace_events *tevent;
	long long auto_thresh;
	int retval;
	int c;
@@ -561,7 +560,6 @@ static struct common_params
	while (1) {
		static struct option long_options[] = {
			{"auto",		required_argument,	0, 'a'},
			{"event",		required_argument,	0, 'e'},
			{"help",		no_argument,		0, 'h'},
			{"house-keeping",	required_argument,	0, 'H'},
			{"irq",			required_argument,	0, 'i'},
@@ -593,7 +591,7 @@ static struct common_params
		if (common_parse_options(argc, argv, &params->common))
			continue;

		c = getopt_long(argc, argv, "a:e:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:",
		c = getopt_long(argc, argv, "a:hH:i:knp:P:qs:t::T:uU0:1:2:345:6:7:",
				 long_options, NULL);

		/* detect the end of the options. */
@@ -630,15 +628,6 @@ static struct common_params
			/* set aa_only to avoid parsing the trace */
			params->common.aa_only = 1;
			break;
		case 'e':
			tevent = trace_event_alloc(optarg);
			if (!tevent)
				fatal("Error alloc trace event");

			if (params->common.events)
				tevent->next = params->common.events;
			params->common.events = tevent;
			break;
		case 'h':
		case '?':
			timerlat_top_usage();