Skip to content

Commit 4ffef95

Browse files
glemcorostedt
authored andcommitted
tools/rv: Allow rv list to filter for container
Add possibility to supply the container name to rv list: # rv list sched mon1 mon2 mon3 This lists only monitors in sched, without indentation. Supplying -h, any option (string starting with -) or more than 1 argument will still print the usage. Passing a non-existent container prints nothing and passing no container continues to print all monitors, showing indentation for nested monitors, reported after their container. Cc: Ingo Molnar <mingo@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Juri Lelli <juri.lelli@redhat.com> Link: https://lore.kernel.org/20250305140406.350227-10-gmonaco@redhat.com Signed-off-by: Gabriele Monaco <gmonaco@redhat.com> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 03abeaa commit 4ffef95

File tree

3 files changed

+53
-23
lines changed

3 files changed

+53
-23
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// SPDX-License-Identifier: GPL-2.0
2-
int ikm_list_monitors(void);
2+
int ikm_list_monitors(char *container);
33
int ikm_run_monitor(char *monitor, int argc, char **argv);

tools/verification/rv/src/in_kernel.c

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,25 @@ static char *ikm_read_desc(char *monitor_name)
180180
/*
181181
* ikm_fill_monitor_definition - fill monitor's definition
182182
*
183-
* Returns -1 on error, 0 otherwise.
183+
* Returns -1 on error, 1 if the monitor does not belong in the container, 0 otherwise.
184+
* container can be NULL
184185
*/
185-
static int ikm_fill_monitor_definition(char *name, struct monitor *ikm)
186+
static int ikm_fill_monitor_definition(char *name, struct monitor *ikm, char *container)
186187
{
187188
int enabled;
188189
char *desc, *nested_name;
189190

190191
nested_name = strstr(name, ":");
191192
if (nested_name) {
193+
/* it belongs in container if it starts with "container:" */
194+
if (container && strstr(name, container) != name)
195+
return 1;
192196
*nested_name = '/';
193197
++nested_name;
194198
ikm->nested = 1;
195199
} else {
200+
if (container)
201+
return 1;
196202
nested_name = name;
197203
ikm->nested = 0;
198204
}
@@ -328,12 +334,12 @@ static int ikm_has_id(char *monitor_name)
328334
*
329335
* Returns 0 on success, -1 otherwise.
330336
*/
331-
int ikm_list_monitors(void)
337+
int ikm_list_monitors(char *container)
332338
{
333339
char *available_monitors;
334340
struct monitor ikm = {0};
335341
char *curr, *next;
336-
int retval;
342+
int retval, list_monitor = 0;
337343

338344
available_monitors = tracefs_instance_file_read(NULL, "rv/available_monitors", NULL);
339345

@@ -347,17 +353,29 @@ int ikm_list_monitors(void)
347353
next = strstr(curr, "\n");
348354
*next = '\0';
349355

350-
retval = ikm_fill_monitor_definition(curr, &ikm);
351-
if (retval)
356+
retval = ikm_fill_monitor_definition(curr, &ikm, container);
357+
if (retval < 0)
352358
err_msg("ikm: error reading %d in kernel monitor, skipping\n", curr);
353359

354-
printf("%s%-*s %s %s\n", ikm.nested ? " - " : "",
355-
ikm.nested ? MAX_DA_NAME_LEN - 3 : MAX_DA_NAME_LEN,
356-
ikm.name, ikm.desc, ikm.enabled ? "[ON]" : "[OFF]");
360+
if (!retval) {
361+
int indent = ikm.nested && !container;
362+
363+
list_monitor = 1;
364+
printf("%s%-*s %s %s\n", indent ? " - " : "",
365+
indent ? MAX_DA_NAME_LEN - 3 : MAX_DA_NAME_LEN,
366+
ikm.name, ikm.desc, ikm.enabled ? "[ON]" : "[OFF]");
367+
}
357368
curr = ++next;
358369

359370
} while (strlen(curr));
360371

372+
if (!list_monitor) {
373+
if (container)
374+
printf("-- No monitor found in container %s --\n", container);
375+
else
376+
printf("-- No monitor found --\n");
377+
}
378+
361379
free(available_monitors);
362380

363381
return 0;

tools/verification/rv/src/rv.c

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,30 +41,42 @@ static void rv_list(int argc, char **argv)
4141
{
4242
static const char *const usage[] = {
4343
"",
44-
" usage: rv list [-h]",
44+
" usage: rv list [-h] [container]",
4545
"",
4646
" list all available monitors",
4747
"",
4848
" -h/--help: print this menu",
49+
"",
50+
" [container]: list only monitors in this container",
4951
NULL,
5052
};
51-
int i;
52-
53-
if (argc > 1) {
53+
int i, print_help = 0, retval = 0;
54+
char *container = NULL;
55+
56+
if (argc == 2) {
57+
if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
58+
print_help = 1;
59+
retval = 0;
60+
} else if (argv[1][0] == '-') {
61+
/* assume invalid option */
62+
print_help = 1;
63+
retval = 1;
64+
} else
65+
container = argv[1];
66+
} else if (argc > 2) {
67+
/* more than 2 is always usage */
68+
print_help = 1;
69+
retval = 1;
70+
}
71+
if (print_help) {
5472
fprintf(stderr, "rv version %s\n", VERSION);
55-
56-
/* more than 1 is always usage */
5773
for (i = 0; usage[i]; i++)
5874
fprintf(stderr, "%s\n", usage[i]);
59-
60-
/* but only -h is valid */
61-
if (!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help"))
62-
exit(0);
63-
else
64-
exit(1);
75+
exit(retval);
6576
}
6677

67-
ikm_list_monitors();
78+
ikm_list_monitors(container);
79+
6880
exit(0);
6981
}
7082

0 commit comments

Comments
 (0)