Lines Matching +full:static +full:- +full:trace +full:- +full:id

1 // SPDX-License-Identifier: GPL-2.0
3 * in kernel monitor support: allows rv to control in-kernel monitors.
15 #include <trace.h>
19 static int config_has_id;
20 static int config_is_container;
21 static int config_my_pid;
22 static int config_trace;
24 static char *config_initial_reactor;
25 static char *config_reactor;
28 * __ikm_read_enable - reads monitor's enable status
32 * Returns the current status, or -1 if the monitor does not exist,
35 static int __ikm_read_enable(char *monitor_name) in __ikm_read_enable()
45 return -1; in __ikm_read_enable()
51 * __ikm_find_monitor - find the full name of a possibly nested module
55 * Returns 1 if we found the monitor, -1 on error and 0 if it does not exist.
59 static int __ikm_find_monitor_name(char *monitor_name, char *out_name) in __ikm_find_monitor_name()
66 return -1; in __ikm_find_monitor_name()
74 for (; cursor > available_monitors; cursor--) in __ikm_find_monitor_name()
75 if (*(cursor-1) == '\n') in __ikm_find_monitor_name()
78 memcpy(out_name, cursor, end-cursor); in __ikm_find_monitor_name()
79 out_name[end-cursor] = '\0'; in __ikm_find_monitor_name()
96 * ikm_read_enable - reads monitor's enable status
98 * Returns the current status, or -1 on error.
100 static int ikm_read_enable(char *monitor_name) in ikm_read_enable()
107 return -1; in ikm_read_enable()
116 * ikm_write_enable - write to the monitor's enable file
118 * Return the number of bytes written, -1 on error.
120 static int ikm_write_enable(char *monitor_name, char *enable_disable) in ikm_write_enable()
131 return -1; in ikm_write_enable()
138 * ikm_enable - enable a monitor
140 * Returns -1 on failure. Success otherwise.
142 static int ikm_enable(char *monitor_name) in ikm_enable()
148 * ikm_disable - disable a monitor
150 * Returns -1 on failure. Success otherwise.
152 static int ikm_disable(char *monitor_name) in ikm_disable()
158 * ikm_read_desc - read monitors' description
163 static char *ikm_read_desc(char *monitor_name) in ikm_read_desc()
181 * ikm_fill_monitor_definition - fill monitor's definition
183 * Returns -1 on error, 1 if the monitor does not belong in the container, 0 otherwise.
186 static int ikm_fill_monitor_definition(char *name, struct monitor *ikm, char *container) in ikm_fill_monitor_definition()
198 ikm->nested = 1; in ikm_fill_monitor_definition()
203 ikm->nested = 0; in ikm_fill_monitor_definition()
209 return -1; in ikm_fill_monitor_definition()
215 return -1; in ikm_fill_monitor_definition()
218 strncpy(ikm->name, nested_name, MAX_DA_NAME_LEN); in ikm_fill_monitor_definition()
219 ikm->enabled = enabled; in ikm_fill_monitor_definition()
220 strncpy(ikm->desc, desc, MAX_DESCRIPTION); in ikm_fill_monitor_definition()
228 * ikm_write_reactor - switch the reactor to *reactor
230 * Return the number or characters written, -1 on error.
232 static int ikm_write_reactor(char *monitor_name, char *reactor) in ikm_write_reactor()
245 * ikm_read_reactor - read the reactors file
250 static char *ikm_read_reactor(char *monitor_name) in ikm_read_reactor()
266 * ikm_get_current_reactor - get the current enabled reactor
274 static char *ikm_get_current_reactor(char *monitor_name) in ikm_get_current_reactor()
309 static int ikm_has_id(char *monitor_name) in ikm_has_id()
319 return -1; in ikm_has_id()
322 /* print fmt: "%d: %s x %s -> %s %s", REC->id, ... */ in ikm_has_id()
323 has_id = !!strstr(format, "REC->id"); in ikm_has_id()
325 debug_msg("ikm: monitor %s has id: %s\n", monitor_name, has_id ? "yes" : "no"); in ikm_has_id()
333 * ikm_list_monitors - list all available monitors
335 * Returns 0 on success, -1 otherwise.
348 return -1; in ikm_list_monitors()
364 printf("%s%-*s %s %s\n", indent ? " - " : "", in ikm_list_monitors()
365 indent ? MAX_DA_NAME_LEN - 3 : MAX_DA_NAME_LEN, in ikm_list_monitors()
374 printf("-- No monitor found in container %s --\n", container); in ikm_list_monitors()
376 printf("-- No monitor found --\n"); in ikm_list_monitors()
384 static void ikm_print_header(struct trace_seq *s) in ikm_print_header()
386 trace_seq_printf(s, "%16s-%-8s %5s %5s ", "<TASK>", "PID", "[CPU]", "TYPE"); in ikm_print_header()
388 trace_seq_printf(s, "%8s ", "ID"); in ikm_print_header()
390 trace_seq_printf(s, "%24s x %-24s -> %-24s %s\n", in ikm_print_header()
396 trace_seq_printf(s, "%16s %-8s %5s %5s ", " | ", " | ", " | ", " | "); in ikm_print_header()
401 trace_seq_printf(s, "%24s %-24s %-24s %s\n", in ikm_print_header()
410 * ikm_event_handler - callback to handle event events
415 static int
423 unsigned long long id; in ikm_event_handler() local
428 missing_id = tep_get_field_val(s, trace_event, "id", record, &id, 1); in ikm_event_handler()
432 if (config_has_id && (config_my_pid == id)) in ikm_event_handler()
437 tep_print_event(trace_event->tep, s, record, "%16s-%-8d [%.3d] ", in ikm_event_handler()
441 tep_print_event(trace_event->tep, s, record, "%s ", TEP_PRINT_NAME); in ikm_event_handler()
447 /* placeholder if we are dealing with a mixed-type container*/ in ikm_event_handler()
450 trace_seq_printf(s, "%8llu ", id); in ikm_event_handler()
458 trace_seq_printf(s, "%24s x %-24s -> %-24s %s\n", in ikm_event_handler()
471 * ikm_error_handler - callback to handle error events
476 static int
480 unsigned long long pid, id; in ikm_error_handler() local
481 int cpu = record->cpu; in ikm_error_handler()
487 missing_id = tep_get_field_val(s, trace_event, "id", record, &id, 1); in ikm_error_handler()
491 if (config_has_id && config_my_pid == id) in ikm_error_handler()
499 tep_print_event(trace_event->tep, s, record, "%s ", TEP_PRINT_NAME); in ikm_error_handler()
505 /* placeholder if we are dealing with a mixed-type container*/ in ikm_error_handler()
508 trace_seq_printf(s, "%8llu ", id); in ikm_error_handler()
522 static int ikm_enable_trace_events(char *monitor_name, struct trace_instance *inst) in ikm_enable_trace_events()
528 retval = tracefs_event_enable(inst->inst, "rv", event); in ikm_enable_trace_events()
530 return -1; in ikm_enable_trace_events()
532 tep_register_event_handler(inst->tep, -1, "rv", event, in ikm_enable_trace_events()
536 retval = tracefs_event_enable(inst->inst, "rv", event); in ikm_enable_trace_events()
538 return -1; in ikm_enable_trace_events()
540 tep_register_event_handler(inst->tep, -1, "rv", event, in ikm_enable_trace_events()
543 /* set if at least 1 monitor has id in case of a container */ in ikm_enable_trace_events()
546 return -1; in ikm_enable_trace_events()
552 static int ikm_enable_trace_container(char *monitor_name, in ikm_enable_trace_container()
563 return -1; in ikm_enable_trace_container()
569 if (ep->d_type != DT_DIR || ep->d_name[0] == '.') in ikm_enable_trace_container()
571 retval = ikm_enable_trace_events(ep->d_name, inst); in ikm_enable_trace_container()
581 * ikm_setup_trace_instance - set up a tracing instance to collect data
583 * Create a trace instance, enable rv: events and enable the trace.
587 static struct trace_instance *ikm_setup_trace_instance(char *monitor_name) in ikm_setup_trace_instance()
598 err_msg("ikm: failed to allocate trace instance"); in ikm_setup_trace_instance()
614 tracefs_trace_on(inst->inst); in ikm_setup_trace_instance()
627 * ikm_destroy_trace_instance - destroy a previously created instance
629 static void ikm_destroy_trace_instance(struct trace_instance *inst) in ikm_destroy_trace_instance()
639 * ikm_usage_print_reactors - print all available reactors, one per line.
641 static void ikm_usage_print_reactors(void) in ikm_usage_print_reactors()
666 * ikm_usage - print usage
668 static void ikm_usage(int exit_val, char *monitor_name, const char *fmt, ...) in ikm_usage()
675 static const char *const usage[] = { in ikm_usage()
677 " -h/--help: print this menu and the reactor list", in ikm_usage()
678 " -r/--reactor 'reactor': enables the 'reactor'", in ikm_usage()
679 " -s/--self: when tracing (-t), also trace rv command", in ikm_usage()
680 " -t/--trace: trace monitor's event", in ikm_usage()
681 " -v/--verbose: print debug messages", in ikm_usage()
692 fprintf(stderr, "\n usage: rv mon %s [-h] [-q] [-r reactor] [-s] [-v]", monitor_name); in ikm_usage()
702 * parse_arguments - parse arguments and set config
704 static int parse_arguments(char *monitor_name, int argc, char **argv) in parse_arguments()
711 static struct option long_options[] = { in parse_arguments()
715 {"trace", no_argument, 0, 't'}, in parse_arguments()
726 if (c == -1) in parse_arguments()
767 * ikm_run_monitor - apply configs and run the monitor
770 * monitors were found, or -1 on error.
789 return -1; in ikm_run_monitor()
794 err_msg("ikm: monitor %s (in-kernel) is already enabled\n", nested_name); in ikm_run_monitor()
795 return -1; in ikm_run_monitor()
806 return -1; in ikm_run_monitor()
814 ikm_print_header(inst->seq); in ikm_run_monitor()
818 retval = tracefs_iterate_raw_events(inst->tep, in ikm_run_monitor()
819 inst->inst, in ikm_run_monitor()
825 err_msg("ikm: error reading trace buffer\n"); in ikm_run_monitor()
845 return -1; in ikm_run_monitor()