Lines Matching full:instance
164 static inline int is_top_instance(struct buffer_instance *instance) in is_top_instance() argument
166 return instance == &top_instance; in is_top_instance()
174 static void init_instance(struct buffer_instance *instance) in init_instance() argument
176 instance->event_next = &instance->events; in init_instance()
196 struct buffer_instance *instance; member
301 * add_instance - add a buffer instance to the internal list
302 * @instance: The buffer instance to add
304 void add_instance(struct buffer_instance *instance, int cpu_count) in add_instance() argument
306 init_instance(instance); in add_instance()
307 instance->next = buffer_instances; in add_instance()
309 first_instance = instance; in add_instance()
310 buffer_instances = instance; in add_instance()
311 instance->cpu_count = cpu_count; in add_instance()
315 static void instance_reset_file_save(struct buffer_instance *instance, char *file, int prio) in instance_reset_file_save() argument
319 path = tracefs_instance_get_file(instance->tracefs, file); in instance_reset_file_save()
325 static void test_set_event_pid(struct buffer_instance *instance) in test_set_event_pid() argument
341 if (!instance->have_set_event_pid && have_set_event_pid) { in test_set_event_pid()
342 instance->have_set_event_pid = 1; in test_set_event_pid()
343 instance_reset_file_save(instance, "set_event_pid", in test_set_event_pid()
346 if (!instance->have_event_fork && have_event_fork) { in test_set_event_pid()
347 instance->have_event_fork = 1; in test_set_event_pid()
348 instance_reset_file_save(instance, "options/event-fork", in test_set_event_pid()
351 if (!instance->have_func_fork && have_func_fork) { in test_set_event_pid()
352 instance->have_func_fork = 1; in test_set_event_pid()
353 instance_reset_file_save(instance, "options/function-fork", in test_set_event_pid()
359 * allocate_instance - allocate a new buffer instance,
361 * @name: The name of the instance (instance will point to this)
363 * Returns a newly allocated instance. In case of an error or if the
364 * instance does not exist in the ftrace system, NULL is returned.
368 struct buffer_instance *instance; in allocate_instance() local
370 instance = calloc(1, sizeof(*instance)); in allocate_instance()
371 if (!instance) in allocate_instance()
374 instance->name = strdup(name); in allocate_instance()
376 instance->tracefs = tracefs_instance_create(name); in allocate_instance()
377 if (!instance->tracefs) in allocate_instance()
381 return instance; in allocate_instance()
384 if (instance) { in allocate_instance()
385 free(instance->name); in allocate_instance()
386 tracefs_instance_free(instance->tracefs); in allocate_instance()
387 free(instance); in allocate_instance()
422 struct buffer_instance *instance; in __add_all_instances() local
436 instance = allocate_instance(name); in __add_all_instances()
437 if (!instance) in __add_all_instances()
438 die("Failed to create instance"); in __add_all_instances()
439 add_instance(instance, local_cpu_count); in __add_all_instances()
471 void tracecmd_stat_cpu_instance(struct buffer_instance *instance, in tracecmd_stat_cpu_instance() argument
485 path = tracefs_instance_get_file(instance->tracefs, file); in tracecmd_stat_cpu_instance()
509 static void add_event(struct buffer_instance *instance, struct event_list *event) in add_event() argument
511 *instance->event_next = event; in add_event()
512 instance->event_next = &event->next; in add_event()
516 static void reset_event_list(struct buffer_instance *instance) in reset_event_list() argument
518 instance->events = NULL; in reset_event_list()
519 init_instance(instance); in reset_event_list()
522 static char *get_temp_file(struct buffer_instance *instance, int cpu) in get_temp_file() argument
524 const char *output_file = instance->output_file; in get_temp_file()
529 name = tracefs_instance_get_name(instance->tracefs); in get_temp_file()
571 static void delete_temp_file(struct buffer_instance *instance, int cpu) in delete_temp_file() argument
573 const char *output_file = instance->output_file; in delete_temp_file()
577 name = tracefs_instance_get_name(instance->tracefs); in delete_temp_file()
585 static int kill_thread_instance(int start, struct buffer_instance *instance) in kill_thread_instance() argument
590 for (i = 0; i < instance->cpu_count; i++) { in kill_thread_instance()
593 delete_temp_file(instance, i); in kill_thread_instance()
606 struct buffer_instance *instance; in kill_threads() local
612 for_all_instances(instance) in kill_threads()
613 i = kill_thread_instance(i, instance); in kill_threads()
636 static int delete_thread_instance(int start, struct buffer_instance *instance) in delete_thread_instance() argument
641 for (i = 0; i < instance->cpu_count; i++) { in delete_thread_instance()
644 delete_temp_file(instance, i); in delete_thread_instance()
651 delete_temp_file(instance, i); in delete_thread_instance()
658 struct buffer_instance *instance; in delete_thread_data() local
661 for_all_instances(instance) in delete_thread_data()
662 i = delete_thread_instance(i, instance); in delete_thread_data()
664 * Top instance temp files are still created even if it in delete_thread_data()
690 struct buffer_instance *instance) in host_tsync_complete() argument
696 ret = tracecmd_tsync_with_guest_stop(instance->tsync); in host_tsync_complete()
698 fd = open(instance->output_file, O_RDWR); in host_tsync_complete()
700 die("error opening %s", instance->output_file); in host_tsync_complete()
708 tracecmd_write_guest_time_shift(handle, instance->tsync); in host_tsync_complete()
713 tracecmd_tsync_free(instance->tsync); in host_tsync_complete()
714 instance->tsync = NULL; in host_tsync_complete()
719 struct buffer_instance *instance; in tell_guests_to_stop() local
722 for_all_instances(instance) { in tell_guests_to_stop()
723 if (is_guest(instance)) in tell_guests_to_stop()
724 tracecmd_msg_send_close_msg(instance->msg_handle); in tell_guests_to_stop()
727 for_all_instances(instance) { in tell_guests_to_stop()
728 if (is_guest(instance)) in tell_guests_to_stop()
729 host_tsync_complete(ctx, instance); in tell_guests_to_stop()
733 for_all_instances(instance) { in tell_guests_to_stop()
734 if (is_guest(instance)) { in tell_guests_to_stop()
735 tracecmd_msg_wait_close_resp(instance->msg_handle); in tell_guests_to_stop()
736 tracecmd_msg_handle_close(instance->msg_handle); in tell_guests_to_stop()
776 static int create_recorder(struct buffer_instance *instance, int cpu,
781 struct buffer_instance *instance; in flush_threads() local
785 for_all_instances(instance) { in flush_threads()
786 for (i = 0; i < instance->cpu_count; i++) { in flush_threads()
788 ret = create_recorder(instance, i, TRACE_TYPE_EXTRACT, NULL); in flush_threads()
833 static int set_ftrace(struct buffer_instance *instance, int set, int use_proc) in set_ftrace() argument
838 path = tracefs_instance_get_file(instance->tracefs, "options/function-trace"); in set_ftrace()
864 static void __clear_trace(struct buffer_instance *instance) in __clear_trace() argument
869 if (is_guest(instance)) in __clear_trace()
873 path = tracefs_instance_get_file(instance->tracefs, "trace"); in __clear_trace()
884 struct buffer_instance *instance; in clear_trace_instances() local
886 for_all_instances(instance) in clear_trace_instances()
887 __clear_trace(instance); in clear_trace_instances()
890 static void reset_max_latency(struct buffer_instance *instance) in reset_max_latency() argument
892 tracefs_instance_file_write(instance->tracefs, in reset_max_latency()
896 static int add_filter_pid(struct buffer_instance *instance, int pid, int exclude) in add_filter_pid() argument
901 for (p = instance->filter_pids; p; p = p->next) { in add_filter_pid()
911 p->next = instance->filter_pids; in add_filter_pid()
914 instance->filter_pids = p; in add_filter_pid()
915 instance->nr_filter_pids++; in add_filter_pid()
917 instance->len_filter_pids += sprintf(buf, "%d", pid); in add_filter_pid()
924 struct buffer_instance *instance; in add_filter_pid_all() local
926 for_all_instances(instance) in add_filter_pid_all()
927 add_filter_pid(instance, pid, exclude); in add_filter_pid_all()
930 static void reset_save_ftrace_pid(struct buffer_instance *instance) in reset_save_ftrace_pid() argument
934 if (!tracefs_file_exists(instance->tracefs, "set_ftrace_pid")) in reset_save_ftrace_pid()
937 path = tracefs_instance_get_file(instance->tracefs, "set_ftrace_pid"); in reset_save_ftrace_pid()
946 static void update_ftrace_pid(struct buffer_instance *instance, in update_ftrace_pid() argument
953 if (!tracefs_file_exists(instance->tracefs, "set_ftrace_pid")) in update_ftrace_pid()
956 path = tracefs_instance_get_file(instance->tracefs, "set_ftrace_pid"); in update_ftrace_pid()
982 struct buffer_instance *instance; in update_ftrace_pids() local
988 for_all_instances(instance) { in update_ftrace_pids()
990 reset_save_ftrace_pid(instance); in update_ftrace_pids()
992 for (pid = instance->filter_pids; pid; pid = pid->next) { in update_ftrace_pids()
996 update_ftrace_pid(instance, buf, rst); in update_ftrace_pids()
1006 static void update_event_filters(struct buffer_instance *instance);
1007 static void update_pid_event_filters(struct buffer_instance *instance);
1073 static char *make_pid_filter(struct buffer_instance *instance, in make_pid_filter() argument
1083 if (instance->have_set_event_pid) in make_pid_filter()
1086 if (!instance->filter_pids) in make_pid_filter()
1089 for (p = instance->filter_pids; p; p = p->next) { in make_pid_filter()
1123 static int get_pid_addr_maps(struct buffer_instance *instance, int pid) in get_pid_addr_maps() argument
1125 struct pid_addr_maps *maps = instance->pid_maps; in get_pid_addr_maps()
1160 maps->next = instance->pid_maps; in get_pid_addr_maps()
1161 instance->pid_maps = maps; in get_pid_addr_maps()
1202 if (instance->pid_maps != maps) { in get_pid_addr_maps()
1203 m = instance->pid_maps; in get_pid_addr_maps()
1212 instance->pid_maps = maps->next; in get_pid_addr_maps()
1225 struct buffer_instance *instance; in get_filter_pid_maps() local
1228 for_all_instances(instance) { in get_filter_pid_maps()
1229 if (!instance->get_procmap) in get_filter_pid_maps()
1231 for (p = instance->filter_pids; p; p = p->next) { in get_filter_pid_maps()
1234 get_pid_addr_maps(instance, p->pid); in get_filter_pid_maps()
1241 struct buffer_instance *instance; in update_task_filter() local
1252 for_all_instances(instance) { in update_task_filter()
1253 if (!instance->filter_pids) in update_task_filter()
1255 if (instance->common_pid_filter) in update_task_filter()
1256 free(instance->common_pid_filter); in update_task_filter()
1257 instance->common_pid_filter = make_pid_filter(instance, NULL, in update_task_filter()
1261 for_all_instances(instance) in update_task_filter()
1262 update_pid_event_filters(instance); in update_task_filter()
1311 static int trace_wait_for_processes(struct buffer_instance *instance) { in trace_wait_for_processes() argument
1318 pidfds = malloc(sizeof(int) * instance->nr_process_pids); in trace_wait_for_processes()
1322 for (pid = instance->process_pids; in trace_wait_for_processes()
1323 pid && instance->nr_process_pids; in trace_wait_for_processes()
1326 instance->nr_process_pids--; in trace_wait_for_processes()
1333 instance->nr_process_pids--; in trace_wait_for_processes()
1341 instance->nr_process_pids--; in trace_wait_for_processes()
1358 static void add_event_pid(struct buffer_instance *instance, const char *buf) in add_event_pid() argument
1360 tracefs_instance_file_write(instance->tracefs, "set_event_pid", buf); in add_event_pid()
1404 static void update_sched_events(struct buffer_instance *instance, int pid) in update_sched_events() argument
1411 append_sched_event(instance->sched_switch_event, "next_pid", pid); in update_sched_events()
1412 append_sched_event(instance->sched_wakeup_event, "pid", pid); in update_sched_events()
1413 append_sched_event(instance->sched_wakeup_new_event, "pid", pid); in update_sched_events()
1416 static int open_instance_fd(struct buffer_instance *instance,
1421 struct buffer_instance *instance; in add_new_filter_child_pid() local
1425 for_all_instances(instance) { in add_new_filter_child_pid()
1426 if (!instance->ptrace_child || !instance->filter_pids) in add_new_filter_child_pid()
1428 for (fpid = instance->filter_pids; fpid; fpid = fpid->next) { in add_new_filter_child_pid()
1435 add_filter_pid(instance, child, 0); in add_new_filter_child_pid()
1437 update_ftrace_pid(instance, buf, 0); in add_new_filter_child_pid()
1439 instance->common_pid_filter = append_pid_filter(instance->common_pid_filter, in add_new_filter_child_pid()
1441 if (instance->have_set_event_pid) { in add_new_filter_child_pid()
1442 add_event_pid(instance, buf); in add_new_filter_child_pid()
1444 update_sched_events(instance, pid); in add_new_filter_child_pid()
1445 update_event_filters(instance); in add_new_filter_child_pid()
1451 static void ptrace_attach(struct buffer_instance *instance, int pid) in ptrace_attach() argument
1461 if (instance) in ptrace_attach()
1462 add_filter_pid(instance, pid, 0); in ptrace_attach()
1477 struct buffer_instance *instance; in get_intance_fpid() local
1480 for_all_instances(instance) { in get_intance_fpid()
1481 for (fpid = instance->filter_pids; fpid; fpid = fpid->next) { in get_intance_fpid()
1488 return instance; in get_intance_fpid()
1496 struct buffer_instance *instance; in ptrace_wait() local
1512 for_all_instances(instance) in ptrace_wait()
1513 nr_pids += instance->nr_filter_pids; in ptrace_wait()
1520 for_all_instances(instance) { in ptrace_wait()
1521 if (!instance->ptrace_child && !instance->get_procmap) in ptrace_wait()
1524 for (fpid = instance->filter_pids; fpid && i < nr_pids; fpid = fpid->next) { in ptrace_wait()
1562 instance = get_intance_fpid(pid); in ptrace_wait()
1563 if (instance && instance->get_procmap) in ptrace_wait()
1564 get_pid_addr_maps(instance, pid); in ptrace_wait()
1594 static inline void ptrace_attach(struct buffer_instance *instance, int pid) { } in ptrace_attach() argument
1682 set_plugin_instance(struct buffer_instance *instance, const char *name) in set_plugin_instance() argument
1689 if (is_guest(instance)) in set_plugin_instance()
1692 path = tracefs_instance_get_file(instance->tracefs, "current_tracer"); in set_plugin_instance()
1718 /* First try instance file, then top level */ in set_plugin_instance()
1719 path = tracefs_instance_get_file(instance->tracefs, "options/func_stack_trace"); in set_plugin_instance()
1742 struct buffer_instance *instance; in set_plugin() local
1744 for_all_instances(instance) in set_plugin()
1745 set_plugin_instance(instance, name); in set_plugin()
1748 static void save_option(struct buffer_instance *instance, const char *option) in save_option() argument
1755 opt->next = instance->options; in save_option()
1756 instance->options = opt; in save_option()
1760 static int set_option(struct buffer_instance *instance, const char *option) in set_option() argument
1765 path = tracefs_instance_get_file(instance->tracefs, "trace_options"); in set_option()
1780 static void disable_func_stack_trace_instance(struct buffer_instance *instance) in disable_func_stack_trace_instance() argument
1789 if (is_guest(instance)) in disable_func_stack_trace_instance()
1792 path = tracefs_instance_get_file(instance->tracefs, "current_tracer"); in disable_func_stack_trace_instance()
1798 content = tracefs_instance_file_read(instance->tracefs, in disable_func_stack_trace_instance()
1804 set_option(instance, "nofunc_stack_trace"); in disable_func_stack_trace_instance()
1811 struct buffer_instance *instance; in disable_func_stack_trace() local
1813 for_all_instances(instance) in disable_func_stack_trace()
1814 disable_func_stack_trace_instance(instance); in disable_func_stack_trace()
1817 static void add_reset_options(struct buffer_instance *instance) in add_reset_options() argument
1829 path = tracefs_instance_get_file(instance->tracefs, "trace_options"); in add_reset_options()
1832 for (opt = instance->options; opt; opt = opt->next) { in add_reset_options()
1898 struct buffer_instance *instance; in set_options() local
1902 for_all_instances(instance) { in set_options()
1903 add_reset_options(instance); in set_options()
1904 while (instance->options) { in set_options()
1905 opt = instance->options; in set_options()
1906 instance->options = opt->next; in set_options()
1907 ret = set_option(instance, opt->option); in set_options()
1949 static int trace_check_file_exists(struct buffer_instance *instance, char *file) in trace_check_file_exists() argument
1955 path = tracefs_instance_get_file(instance->tracefs, file); in trace_check_file_exists()
2013 reset_events_instance(struct buffer_instance *instance) in reset_events_instance() argument
2022 if (is_guest(instance)) in reset_events_instance()
2026 /* old way only had top instance */ in reset_events_instance()
2027 if (!is_top_instance(instance)) in reset_events_instance()
2034 path = tracefs_instance_get_file(instance->tracefs, "events/enable"); in reset_events_instance()
2042 path = tracefs_instance_get_file(instance->tracefs, "events/*/filter"); in reset_events_instance()
2062 struct buffer_instance *instance; in reset_events() local
2064 for_all_instances(instance) in reset_events()
2065 reset_events_instance(instance); in reset_events()
2404 static int open_instance_fd(struct buffer_instance *instance, in open_instance_fd() argument
2410 path = tracefs_instance_get_file(instance->tracefs, file); in open_instance_fd()
2414 if (is_top_instance(instance)) in open_instance_fd()
2422 static int open_tracing_on(struct buffer_instance *instance) in open_tracing_on() argument
2424 int fd = instance->tracing_on_fd; in open_tracing_on()
2430 fd = open_instance_fd(instance, "tracing_on", O_RDWR | O_CLOEXEC); in open_tracing_on()
2434 instance->tracing_on_fd = fd; in open_tracing_on()
2439 static void write_tracing_on(struct buffer_instance *instance, int on) in write_tracing_on() argument
2444 if (is_guest(instance)) in write_tracing_on()
2447 fd = open_tracing_on(instance); in write_tracing_on()
2460 static int read_tracing_on(struct buffer_instance *instance) in read_tracing_on() argument
2466 if (is_guest(instance)) in read_tracing_on()
2469 fd = open_tracing_on(instance); in read_tracing_on()
2484 struct buffer_instance *instance; in reset_max_latency_instance() local
2486 for_all_instances(instance) in reset_max_latency_instance()
2487 reset_max_latency(instance); in reset_max_latency_instance()
2492 struct buffer_instance *instance; in tracecmd_enable_tracing() local
2496 for_all_instances(instance) in tracecmd_enable_tracing()
2497 write_tracing_on(instance, 1); in tracecmd_enable_tracing()
2505 struct buffer_instance *instance; in tracecmd_disable_tracing() local
2507 for_all_instances(instance) in tracecmd_disable_tracing()
2508 write_tracing_on(instance, 0); in tracecmd_disable_tracing()
2513 struct buffer_instance *instance; in tracecmd_disable_all_tracing() local
2525 for_all_instances(instance) in tracecmd_disable_all_tracing()
2526 update_ftrace_pid(instance, "", 1); in tracecmd_disable_all_tracing()
2532 update_sched_event(struct buffer_instance *instance, in update_sched_event() argument
2538 event->pid_filter = make_pid_filter(instance, event->pid_filter, field); in update_sched_event()
2541 static void update_event_filters(struct buffer_instance *instance) in update_event_filters() argument
2549 if (instance->common_pid_filter) in update_event_filters()
2550 common_len = strlen(instance->common_pid_filter); in update_event_filters()
2552 for (event = instance->events; event; event = event->next) { in update_event_filters()
2557 if (!instance->common_pid_filter) in update_event_filters()
2572 event->filter, instance->common_pid_filter, in update_event_filters()
2582 event->filter, instance->common_pid_filter); in update_event_filters()
2586 if (!instance->common_pid_filter) in update_event_filters()
2597 instance->common_pid_filter, event->pid_filter); in update_event_filters()
2599 event_filter = instance->common_pid_filter; in update_event_filters()
2609 static void update_pid_filters(struct buffer_instance *instance) in update_pid_filters() argument
2618 if (is_guest(instance)) in update_pid_filters()
2621 fd = open_instance_fd(instance, "set_event_pid", in update_pid_filters()
2626 len = instance->len_filter_pids + instance->nr_filter_pids; in update_pid_filters()
2633 for (p = instance->filter_pids; p; p = p->next) { in update_pid_filters()
2657 static void update_pid_event_filters(struct buffer_instance *instance) in update_pid_event_filters() argument
2659 if (instance->have_set_event_pid) in update_pid_event_filters()
2660 return update_pid_filters(instance); in update_pid_event_filters()
2666 update_sched_event(instance, instance->sched_switch_event, "next_pid"); in update_pid_event_filters()
2667 update_sched_event(instance, instance->sched_wakeup_event, "pid"); in update_pid_event_filters()
2668 update_sched_event(instance, instance->sched_wakeup_new_event, "pid"); in update_pid_event_filters()
2670 update_event_filters(instance); in update_pid_event_filters()
2675 static char *alloc_mask_from_hex(struct buffer_instance *instance, const char *str) in alloc_mask_from_hex() argument
2681 int bytes = (instance->cpu_count + 7) / 8; in alloc_mask_from_hex()
2682 int last = instance->cpu_count % 8; in alloc_mask_from_hex()
2709 static void set_mask(struct buffer_instance *instance) in set_mask() argument
2716 if (is_guest(instance)) in set_mask()
2719 if (!instance->cpumask) in set_mask()
2722 path = tracefs_instance_get_file(instance->tracefs, "tracing_cpumask"); in set_mask()
2737 write(fd, instance->cpumask, strlen(instance->cpumask)); in set_mask()
2742 free(instance->cpumask); in set_mask()
2743 instance->cpumask = NULL; in set_mask()
2746 static void enable_events(struct buffer_instance *instance) in enable_events() argument
2750 if (is_guest(instance)) in enable_events()
2753 for (event = instance->events; event; event = event->next) { in enable_events()
2759 for (event = instance->events; event; event = event->next) { in enable_events()
2770 static void set_clock(struct common_record_context *ctx, struct buffer_instance *instance) in set_clock() argument
2777 if (is_guest(instance)) in set_clock()
2780 if (instance->clock) in set_clock()
2781 clock = instance->clock; in set_clock()
2789 content = tracefs_instance_file_read(instance->tracefs, in set_clock()
2801 path = tracefs_instance_get_file(instance->tracefs, "trace_clock"); in set_clock()
2807 tracefs_instance_file_write(instance->tracefs, in set_clock()
2811 static void set_max_graph_depth(struct buffer_instance *instance, char *max_graph_depth) in set_max_graph_depth() argument
2816 if (is_guest(instance)) in set_max_graph_depth()
2819 path = tracefs_instance_get_file(instance->tracefs, "max_graph_depth"); in set_max_graph_depth()
2822 ret = tracefs_instance_file_write(instance->tracefs, "max_graph_depth", in set_max_graph_depth()
2846 * @instance: instance to use
2856 create_event(struct buffer_instance *instance, char *path, struct event_list *old_event) in create_event() argument
2868 add_event(instance, event); in create_event()
2870 if (event->filter || filter_task || instance->filter_pids) { in create_event()
2906 static void make_sched_event(struct buffer_instance *instance, in make_sched_event() argument
2930 *event = create_event(instance, path, sched); in make_sched_event()
2960 static int expand_event_files(struct buffer_instance *instance, in expand_event_files() argument
2963 struct event_list **save_event_tail = instance->event_next; in expand_event_files()
2976 path = tracefs_instance_get_file(instance->tracefs, p); in expand_event_files()
2991 event = create_event(instance, path, old_event); in expand_event_files()
2997 test_event(event, path, "sched/sched_switch", &instance->sched_switch_event, len); in expand_event_files()
2998 test_event(event, path, "sched/sched_wakeup_new", &instance->sched_wakeup_new_event, len); in expand_event_files()
2999 test_event(event, path, "sched/sched_wakeup", &instance->sched_wakeup_event, len); in expand_event_files()
3004 make_sched_event(instance, &instance->sched_switch_event, in expand_event_files()
3006 make_sched_event(instance, &instance->sched_wakeup_event, in expand_event_files()
3008 make_sched_event(instance, &instance->sched_wakeup_new_event, in expand_event_files()
3017 return save_event_tail == instance->event_next; in expand_event_files()
3020 static int expand_events_all(struct buffer_instance *instance, in expand_events_all() argument
3031 ret = expand_event_files(instance, name, event); in expand_events_all()
3037 static void expand_event(struct buffer_instance *instance, struct event_list *event) in expand_event() argument
3049 expand_event_files(instance, "*", event); in expand_event()
3063 ret = expand_events_all(instance, str, ptr, event); in expand_event()
3065 ret = expand_events_all(instance, str, "*", event); in expand_event()
3074 ret = expand_event_files(instance, str, event); in expand_event()
3075 ret &= expand_events_all(instance, "*", str, event); in expand_event()
3077 ret &= expand_events_all(instance, str, "*", event); in expand_event()
3086 static void expand_event_instance(struct buffer_instance *instance) in expand_event_instance() argument
3088 struct event_list *compressed_list = instance->events; in expand_event_instance()
3091 if (is_guest(instance)) in expand_event_instance()
3094 reset_event_list(instance); in expand_event_instance()
3099 expand_event(instance, event); in expand_event_instance()
3107 struct buffer_instance *instance; in expand_event_list() local
3112 for_all_instances(instance) in expand_event_list()
3113 expand_event_instance(instance); in expand_event_list()
3317 create_recorder_instance_pipe(struct buffer_instance *instance, in create_recorder_instance_pipe() argument
3324 path = tracefs_instance_get_dir(instance->tracefs); in create_recorder_instance_pipe()
3340 create_recorder_instance(struct buffer_instance *instance, const char *file, int cpu, in create_recorder_instance() argument
3347 if (is_guest(instance)) { in create_recorder_instance()
3351 if (instance->use_fifos) in create_recorder_instance()
3352 fd = instance->fds[cpu]; in create_recorder_instance()
3353 else if (is_network(instance)) { in create_recorder_instance()
3354 result = do_getaddrinfo(instance->name, in create_recorder_instance()
3355 instance->client_ports[cpu], in create_recorder_instance()
3356 instance->port_type); in create_recorder_instance()
3359 instance->name, in create_recorder_instance()
3360 instance->client_ports[cpu]); in create_recorder_instance()
3364 fd = trace_vsock_open(instance->cid, instance->client_ports[cpu]); in create_recorder_instance()
3369 if (instance->use_fifos) in create_recorder_instance()
3377 return create_recorder_instance_pipe(instance, cpu, brass); in create_recorder_instance()
3379 if (!tracefs_instance_get_name(instance->tracefs)) in create_recorder_instance()
3382 path = tracefs_instance_get_dir(instance->tracefs); in create_recorder_instance()
3395 static int create_recorder(struct buffer_instance *instance, int cpu, in create_recorder() argument
3418 instance->cpu_count = 0; in create_recorder()
3421 if ((instance->client_ports && !is_guest(instance)) || is_agent(instance)) { in create_recorder()
3426 if (is_agent(instance)) { in create_recorder()
3427 if (instance->use_fifos) in create_recorder()
3428 fd = instance->fds[cpu]; in create_recorder()
3431 fd = do_accept(instance->fds[cpu]); in create_recorder()
3432 if (instance->host && in create_recorder()
3433 !trace_net_cmp_connection_fd(fd, instance->host)) { in create_recorder()
3435 instance->host, cpu); in create_recorder()
3440 fd = connect_port(host, instance->client_ports[cpu], in create_recorder()
3441 instance->port_type); in create_recorder()
3445 if (tracefs_instance_get_name(instance->tracefs) && !is_agent(instance)) { in create_recorder()
3446 path = tracefs_instance_get_dir(instance->tracefs); in create_recorder()
3459 file = get_temp_file(instance, cpu); in create_recorder()
3460 recorder = create_recorder_instance(instance, file, cpu, brass); in create_recorder()
3496 struct buffer_instance *instance) in communicate_with_listener_v1() argument
3525 instance->port_type = USE_TCP; in communicate_with_listener_v1()
3529 if (instance->port_type == USE_TCP) { in communicate_with_listener_v1()
3562 instance->client_ports = client_ports; in communicate_with_listener_v1()
3677 static struct tracecmd_msg_handle *setup_network(struct buffer_instance *instance) in setup_network() argument
3680 enum port_type type = instance->port_type; in setup_network()
3725 communicate_with_listener_v3(msg_handle, &instance->client_ports); in setup_network()
3729 communicate_with_listener_v1(msg_handle, instance); in setup_network()
3766 setup_connection(struct buffer_instance *instance, struct common_record_context *ctx) in setup_connection() argument
3772 msg_handle = setup_network(instance); in setup_connection()
3786 ret = tracecmd_write_cpus(network_handle, instance->cpu_count); in setup_connection()
3817 instance->network_handle = network_handle; in setup_connection()
3882 guest->instance = tracefs_instance_create("map_guest_pids"); in start_mapping_vcpus()
3883 if (!guest->instance) in start_mapping_vcpus()
3899 tracefs_instance_file_write(guest->instance, "set_event_pid", pids); in start_mapping_vcpus()
3902 tracefs_instance_file_write(guest->instance, "events/kvm/kvm_entry/enable", "1"); in start_mapping_vcpus()
3958 static void stop_mapping_vcpus(struct buffer_instance *instance, in stop_mapping_vcpus() argument
3966 if (!guest->instance) in stop_mapping_vcpus()
3970 tmap.max_cpus = instance->cpu_count; in stop_mapping_vcpus()
3979 tracefs_instance_file_write(guest->instance, "events/kvm/kvm_entry/enable", "0"); in stop_mapping_vcpus()
3997 tracefs_iterate_raw_events(tep, guest->instance, NULL, 0, map_vcpus, &tmap); in stop_mapping_vcpus()
4014 tracefs_instance_destroy(guest->instance); in stop_mapping_vcpus()
4015 tracefs_instance_free(guest->instance); in stop_mapping_vcpus()
4019 struct buffer_instance *instance, in host_tsync() argument
4029 if (is_network(instance)) { in host_tsync()
4030 fd = connect_port(instance->name, tsync_port, in host_tsync()
4031 instance->port_type); in host_tsync()
4033 guest = trace_get_guest(instance->cid, NULL); in host_tsync()
4039 fd = trace_vsock_open(instance->cid, tsync_port); in host_tsync()
4042 instance->tsync = tracecmd_tsync_with_guest(top_instance.trace_id, in host_tsync()
4043 instance->tsync_loop_interval, in host_tsync()
4045 instance->cpu_count, in host_tsync()
4047 if (!is_network(instance)) in host_tsync()
4048 stop_mapping_vcpus(instance, guest); in host_tsync()
4050 if (!instance->tsync) in host_tsync()
4057 struct buffer_instance *instance) in connect_to_agent() argument
4070 nr_fifos = open_guest_fifos(instance->name, &fds); in connect_to_agent()
4074 if (ctx->instance->result) { in connect_to_agent()
4076 sd = connect_addr(ctx->instance->result); in connect_to_agent()
4079 instance->name, instance->port); in connect_to_agent()
4082 sd = trace_vsock_open(instance->cid, instance->port); in connect_to_agent()
4085 instance->cid, instance->port); in connect_to_agent()
4092 if (!instance->clock) in connect_to_agent()
4093 instance->clock = tracefs_get_clock(NULL); in connect_to_agent()
4095 if (instance->tsync_loop_interval >= 0) in connect_to_agent()
4096 tracecmd_tsync_proto_getall(&protos, instance->clock, role); in connect_to_agent()
4098 ret = tracecmd_msg_send_trace_req(msg_handle, instance->argc, in connect_to_agent()
4099 instance->argv, use_fifos, in connect_to_agent()
4110 &instance->trace_id, in connect_to_agent()
4118 instance->name); in connect_to_agent()
4119 instance->cpu_count = nr_cpus; in connect_to_agent()
4120 host_tsync(ctx, instance, tsync_port, tsync_protos_reply); in connect_to_agent()
4130 nr_fifos, instance->name, nr_cpus); in connect_to_agent()
4134 instance->fds = fds; in connect_to_agent()
4139 instance->client_ports = ports; in connect_to_agent()
4142 instance->use_fifos = use_fifos; in connect_to_agent()
4143 instance->cpu_count = nr_cpus; in connect_to_agent()
4146 instance->msg_handle = msg_handle; in connect_to_agent()
4149 static void setup_guest(struct buffer_instance *instance) in setup_guest() argument
4151 struct tracecmd_msg_handle *msg_handle = instance->msg_handle; in setup_guest()
4152 const char *output_file = instance->output_file; in setup_guest()
4157 file = trace_get_guest_file(output_file, instance->name); in setup_guest()
4161 free(instance->output_file); in setup_guest()
4162 instance->output_file = file; in setup_guest()
4174 static void setup_agent(struct buffer_instance *instance, in setup_agent() argument
4179 network_handle = create_net_output(ctx, instance->msg_handle); in setup_agent()
4182 tracecmd_write_cpus(network_handle, instance->cpu_count); in setup_agent()
4186 tracecmd_msg_finish_sending_data(instance->msg_handle); in setup_agent()
4187 instance->network_handle = network_handle; in setup_agent()
4192 struct buffer_instance *instance; in start_threads() local
4197 for_all_instances(instance) { in start_threads()
4199 if (is_guest(instance)) in start_threads()
4200 connect_to_agent(ctx, instance); in start_threads()
4201 total_cpu_count += instance->cpu_count; in start_threads()
4209 for_all_instances(instance) { in start_threads()
4213 if (is_agent(instance)) { in start_threads()
4214 setup_agent(instance, ctx); in start_threads()
4215 } else if (is_guest(instance)) { in start_threads()
4216 setup_guest(instance); in start_threads()
4218 instance->msg_handle = setup_connection(instance, ctx); in start_threads()
4219 if (!instance->msg_handle) in start_threads()
4223 for (x = 0; x < instance->cpu_count; x++) { in start_threads()
4229 pids[i].stream = trace_stream_init(instance, x, in start_threads()
4231 instance->cpu_count, in start_threads()
4239 pids[i].instance = instance; in start_threads()
4242 pid = pids[i++].pid = create_recorder(instance, x, type, brass); in start_threads()
4246 add_filter_pid(instance, pid, 1); in start_threads()
4263 struct buffer_instance *instance, in append_buffer() argument
4266 int cpu_count = instance->cpu_count; in append_buffer()
4274 * for each buffer instance as there are for the host, if there are in append_buffer()
4281 if (instance->cpu_count < local_cpu_count) in append_buffer()
4285 temp_files[i] = get_temp_file(instance, i); in append_buffer()
4286 if (i >= instance->cpu_count) in append_buffer()
4290 tracecmd_append_buffer_cpu_data(handle, tracefs_instance_get_name(instance->tracefs), in append_buffer()
4293 for (i = 0; i < instance->cpu_count; i++) { in append_buffer()
4294 if (i >= instance->cpu_count) in append_buffer()
4295 delete_temp_file(instance, i); in append_buffer()
4301 add_guest_info(struct tracecmd_output *handle, struct buffer_instance *instance) in add_guest_info() argument
4310 if (is_network(instance)) { in add_guest_info()
4311 name = instance->name; in add_guest_info()
4313 guest = trace_get_guest(instance->cid, NULL); in add_guest_info()
4322 size += instance->cpu_count * 2 * sizeof(int); /* cpu,pid pair */ in add_guest_info()
4331 memcpy(p, &instance->trace_id, sizeof(long long)); in add_guest_info()
4334 memcpy(p, &instance->cpu_count, sizeof(int)); in add_guest_info()
4336 for (i = 0; i < instance->cpu_count; i++) { in add_guest_info()
4338 if (!is_network(instance)) { in add_guest_info()
4353 add_pid_maps(struct tracecmd_output *handle, struct buffer_instance *instance) in add_pid_maps() argument
4355 struct pid_addr_maps *maps = instance->pid_maps; in add_pid_maps()
4382 add_trace_id(struct tracecmd_output *handle, struct buffer_instance *instance) in add_trace_id() argument
4385 sizeof(long long), &instance->trace_id); in add_trace_id()
4389 add_buffer_stat(struct tracecmd_output *handle, struct buffer_instance *instance) in add_buffer_stat() argument
4396 tracefs_instance_get_name(instance->tracefs)); in add_buffer_stat()
4401 for (i = 0; i < instance->cpu_count; i++) in add_buffer_stat()
4403 instance->s_save[i].len+1, in add_buffer_stat()
4404 instance->s_save[i].buffer); in add_buffer_stat()
4454 static void print_stat(struct buffer_instance *instance) in print_stat() argument
4461 if (!is_top_instance(instance)) in print_stat()
4463 tracefs_instance_get_name(instance->tracefs)); in print_stat()
4465 for (cpu = 0; cpu < instance->cpu_count; cpu++) in print_stat()
4466 trace_seq_do_printf(&instance->s_print[cpu]); in print_stat()
4471 struct buffer_instance *instance; in get_trace_clock() local
4473 for_all_instances(instance) { in get_trace_clock()
4474 if (is_guest(instance)) in get_trace_clock()
4480 return tracefs_get_clock(instance ? instance->tracefs : NULL); in get_trace_clock()
4482 return tracefs_instance_file_read(instance ? instance->tracefs : NULL, in get_trace_clock()
4519 static void write_guest_file(struct buffer_instance *instance) in write_guest_file() argument
4522 int cpu_count = instance->cpu_count; in write_guest_file()
4527 file = instance->output_file; in write_guest_file()
4535 if (instance->flags & BUFFER_FL_TSC2NSEC) in write_guest_file()
4543 temp_files[i] = get_temp_file(instance, i); in write_guest_file()
4591 struct buffer_instance *instance; in record_data() local
4597 for_all_instances(instance) { in record_data()
4598 if (is_guest(instance)) in record_data()
4599 write_guest_file(instance); in record_data()
4600 else if (host && instance->msg_handle) in record_data()
4601 finish_network(instance->msg_handle); in record_data()
4617 /* Allocate enough temp files to handle each instance */ in record_data()
4618 for_all_instances(instance) { in record_data()
4619 if (instance->msg_handle) in record_data()
4621 if (instance->cpu_count > max_cpu_count) in record_data()
4622 max_cpu_count = instance->cpu_count; in record_data()
4649 /* Only record the top instance under TRACECMD_OPTION_CPUSTAT*/ in record_data()
4660 for_each_instance(instance) { in record_data()
4661 int cpus = instance->cpu_count != local_cpu_count ? in record_data()
4662 instance->cpu_count : 0; in record_data()
4664 if (instance->msg_handle) in record_data()
4667 tracefs_instance_get_name(instance->tracefs), in record_data()
4669 add_buffer_stat(handle, instance); in record_data()
4676 for_all_instances(instance) { in record_data()
4677 add_pid_maps(handle, instance); in record_data()
4680 for_all_instances(instance) { in record_data()
4681 if (is_guest(instance)) in record_data()
4682 add_guest_info(handle, instance); in record_data()
4699 for_each_instance(instance) { in record_data()
4700 if (instance->msg_handle) in record_data()
4702 print_stat(instance); in record_data()
4703 append_buffer(handle, instance, temp_files); in record_data()
4719 static int filter_command(struct tracefs_instance *instance, const char *cmd) in filter_command() argument
4721 return tracefs_instance_file_append(instance, "set_ftrace_filter", cmd); in filter_command()
4724 static int write_func_filter(enum filter_type type, struct buffer_instance *instance, in write_func_filter() argument
4730 int (*filter_function)(struct tracefs_instance *instance, const char *filter, in write_func_filter()
4747 ret = filter_function(instance->tracefs, NULL, NULL, in write_func_filter()
4761 ret = filter_function(instance->tracefs, item->func, item->mod, in write_func_filter()
4767 ret = filter_function(instance->tracefs, NULL, NULL, 0); in write_func_filter()
4773 ret = filter_command(instance->tracefs, item->func); in write_func_filter()
4787 static int write_func_file(struct buffer_instance *instance, in write_func_file() argument
4799 path = tracefs_instance_get_file(instance->tracefs, file); in write_func_file()
4837 static int functions_filtered(struct buffer_instance *instance) in functions_filtered() argument
4843 path = tracefs_instance_get_file(instance->tracefs, "set_ftrace_filter"); in functions_filtered()
4847 if (is_top_instance(instance)) in functions_filtered()
4851 tracefs_instance_get_name(instance->tracefs)); in functions_filtered()
4867 static void set_funcs(struct buffer_instance *instance) in set_funcs() argument
4872 if (is_guest(instance)) in set_funcs()
4875 ret = write_func_filter(FUNC_FILTER, instance, &instance->filter_funcs); in set_funcs()
4879 /* graph tracing currently only works for top instance */ in set_funcs()
4880 if (is_top_instance(instance)) { in set_funcs()
4881 ret = write_func_file(instance, "set_graph_function", &graph_funcs); in set_funcs()
4884 if (instance->plugin && strcmp(instance->plugin, "function_graph") == 0) { in set_funcs()
4885 ret = write_func_file(instance, "set_graph_notrace", in set_funcs()
4886 &instance->notrace_funcs); in set_funcs()
4891 ret = write_func_filter(FUNC_NOTRACE, instance, in set_funcs()
4892 &instance->notrace_funcs); in set_funcs()
4897 write_func_filter(FUNC_NOTRACE, instance, &instance->notrace_funcs); in set_funcs()
4900 if (func_stack && is_top_instance(instance)) { in set_funcs()
4901 if (!functions_filtered(instance)) in set_funcs()
4903 save_option(instance, FUNC_STACK_TRACE); in set_funcs()
4940 struct tracefs_instance *instance) in find_time_stamp() argument
4944 if (!tracefs_iterate_raw_events(tep, instance, NULL, 0, find_ts, &ts)) in find_time_stamp()
5065 static void set_buffer_size_instance(struct buffer_instance *instance) in set_buffer_size_instance() argument
5067 int buffer_size = instance->buffer_size; in set_buffer_size_instance()
5073 if (is_guest(instance)) in set_buffer_size_instance()
5084 path = tracefs_instance_get_file(instance->tracefs, "buffer_size_kb"); in set_buffer_size_instance()
5101 struct buffer_instance *instance; in set_buffer_size() local
5103 for_all_instances(instance) in set_buffer_size()
5104 set_buffer_size_instance(instance); in set_buffer_size()
5138 static void clear_instance_triggers(struct buffer_instance *instance) in clear_instance_triggers() argument
5147 path = tracefs_instance_get_file(instance->tracefs, "events"); in clear_instance_triggers()
5227 static void clear_instance_filters(struct buffer_instance *instance) in clear_instance_filters() argument
5235 path = tracefs_instance_get_file(instance->tracefs, "events"); in clear_instance_filters()
5260 struct buffer_instance *instance; in clear_filters() local
5262 for_all_instances(instance) in clear_filters()
5263 clear_instance_filters(instance); in clear_filters()
5268 struct buffer_instance *instance; in reset_clock() local
5270 for_all_instances(instance) in reset_clock()
5271 tracefs_instance_file_write(instance->tracefs, in reset_clock()
5277 struct buffer_instance *instance; in reset_cpu_mask() local
5290 for_all_instances(instance) in reset_cpu_mask()
5291 tracefs_instance_file_write(instance->tracefs, in reset_cpu_mask()
5297 struct buffer_instance *instance; in reset_event_pid() local
5299 for_all_instances(instance) in reset_event_pid()
5300 add_event_pid(instance, ""); in reset_event_pid()
5305 struct buffer_instance *instance; in clear_triggers() local
5307 for_all_instances(instance) in clear_triggers()
5308 clear_instance_triggers(instance); in clear_triggers()
5311 static void clear_instance_error_log(struct buffer_instance *instance) in clear_instance_error_log() argument
5315 if (!tracefs_file_exists(instance->tracefs, "error_log")) in clear_instance_error_log()
5318 file = tracefs_instance_get_file(instance->tracefs, "error_log"); in clear_instance_error_log()
5327 struct buffer_instance *instance; in clear_error_log() local
5329 for_all_instances(instance) in clear_error_log()
5330 clear_instance_error_log(instance); in clear_error_log()
5342 struct buffer_instance *instance; in clear_func_filters() local
5351 for_all_instances(instance) { in clear_func_filters()
5353 path = tracefs_instance_get_file(instance->tracefs, files[i]); in clear_func_filters()
5362 struct buffer_instance *instance; in make_instances() local
5364 for_each_instance(instance) { in make_instances()
5365 if (is_guest(instance)) in make_instances()
5367 if (instance->name && !instance->tracefs) { in make_instances()
5368 instance->tracefs = tracefs_instance_create(instance->name); in make_instances()
5370 if (instance->tracefs && !tracefs_instance_is_new(instance->tracefs)) in make_instances()
5371 instance->flags |= BUFFER_FL_KEEP; in make_instances()
5378 struct buffer_instance *instance; in tracecmd_remove_instances() local
5380 for_each_instance(instance) { in tracecmd_remove_instances()
5382 if (is_guest(instance) || (instance->flags & BUFFER_FL_KEEP)) in tracecmd_remove_instances()
5384 if (instance->tracing_on_fd > 0) { in tracecmd_remove_instances()
5385 close(instance->tracing_on_fd); in tracecmd_remove_instances()
5386 instance->tracing_on_fd = 0; in tracecmd_remove_instances()
5388 tracefs_instance_destroy(instance->tracefs); in tracecmd_remove_instances()
5439 static int __check_doing_something(struct buffer_instance *instance) in __check_doing_something() argument
5441 return is_guest(instance) || (instance->flags & BUFFER_FL_PROFILE) || in __check_doing_something()
5442 instance->plugin || instance->events || instance->get_procmap; in __check_doing_something()
5447 struct buffer_instance *instance; in check_doing_something() local
5449 for_all_instances(instance) { in check_doing_something()
5450 if (__check_doing_something(instance)) in check_doing_something()
5458 update_plugin_instance(struct buffer_instance *instance, in update_plugin_instance() argument
5461 const char *plugin = instance->plugin; in update_plugin_instance()
5463 if (is_guest(instance)) in update_plugin_instance()
5495 set_plugin_instance(instance, plugin); in update_plugin_instance()
5500 struct buffer_instance *instance; in update_plugins() local
5502 for_all_instances(instance) in update_plugins()
5503 update_plugin_instance(instance, type); in update_plugins()
5508 struct buffer_instance *instance; in allocate_seq() local
5510 for_all_instances(instance) { in allocate_seq()
5511 instance->s_save = malloc(sizeof(struct trace_seq) * instance->cpu_count); in allocate_seq()
5512 instance->s_print = malloc(sizeof(struct trace_seq) * instance->cpu_count); in allocate_seq()
5513 if (!instance->s_save || !instance->s_print) in allocate_seq()
5514 die("Failed to allocate instance info"); in allocate_seq()
5559 struct buffer_instance *instance; in record_stats() local
5564 for_all_instances(instance) { in record_stats()
5565 if (is_guest(instance)) in record_stats()
5568 s_save = instance->s_save; in record_stats()
5569 s_print = instance->s_print; in record_stats()
5570 for (cpu = 0; cpu < instance->cpu_count; cpu++) { in record_stats()
5574 tracecmd_stat_cpu_instance(instance, &s_save[cpu], cpu); in record_stats()
5582 struct buffer_instance *instance; in print_stats() local
5584 for_all_instances(instance) in print_stats()
5585 print_stat(instance); in print_stats()
5590 struct buffer_instance *instance; in destroy_stats() local
5593 for_all_instances(instance) { in destroy_stats()
5594 if (is_guest(instance)) in destroy_stats()
5597 for (cpu = 0; cpu < instance->cpu_count; cpu++) { in destroy_stats()
5598 trace_seq_destroy(&instance->s_save[cpu]); in destroy_stats()
5599 trace_seq_destroy(&instance->s_print[cpu]); in destroy_stats()
5657 static int test_stacktrace_trigger(struct buffer_instance *instance) in test_stacktrace_trigger() argument
5663 path = tracefs_instance_get_file(instance->tracefs, in test_stacktrace_trigger()
5685 profile_add_event(struct buffer_instance *instance, const char *event_str, int stack) in profile_add_event() argument
5700 if (!trace_check_file_exists(instance, buf)) in profile_add_event()
5704 for (event = instance->events; event; event = event->next) { in profile_add_event()
5717 add_event(instance, event); in profile_add_event()
5736 static void enable_profile(struct buffer_instance *instance) in enable_profile() argument
5757 if (!instance->plugin) { in enable_profile()
5758 if (trace_check_file_exists(instance, "max_graph_depth")) { in enable_profile()
5759 instance->plugin = "function_graph"; in enable_profile()
5760 set_max_graph_depth(instance, "1"); in enable_profile()
5766 if (test_stacktrace_trigger(instance)) in enable_profile()
5774 save_option(instance, "stacktrace"); in enable_profile()
5778 profile_add_event(instance, trigger_events[i], stacktrace); in enable_profile()
5781 profile_add_event(instance, events[i], 0); in enable_profile()
5785 create_hook_event(struct buffer_instance *instance, in create_hook_event() argument
5808 add_event(instance, event_list); in create_hook_event()
5815 static void add_hook(struct buffer_instance *instance, const char *arg) in add_hook() argument
5824 hook->instance = instance; in add_hook()
5829 event = create_hook_event(instance, hook->start_system, hook->start_event); in add_hook()
5830 create_hook_event(instance, hook->end_system, hook->end_event); in add_hook()
5838 void update_first_instance(struct buffer_instance *instance, int topt) in update_first_instance() argument
5840 if (topt || instance == &top_instance) in update_first_instance()
5886 struct buffer_instance *instance = &top_instance; in trace_stop() local
5902 instance = allocate_instance(optarg); in trace_stop()
5903 if (!instance) in trace_stop()
5904 die("Failed to create instance"); in trace_stop()
5905 add_instance(instance, local_cpu_count); in trace_stop()
5911 /* Force to use top instance */ in trace_stop()
5913 instance = &top_instance; in trace_stop()
5919 update_first_instance(instance, topt); in trace_stop()
5927 struct buffer_instance *instance = &top_instance; in trace_restart() local
5942 instance = allocate_instance(optarg); in trace_restart()
5943 if (!instance) in trace_restart()
5944 die("Failed to create instance"); in trace_restart()
5945 add_instance(instance, local_cpu_count); in trace_restart()
5951 /* Force to use top instance */ in trace_restart()
5953 instance = &top_instance; in trace_restart()
5960 update_first_instance(instance, topt); in trace_restart()
5969 struct buffer_instance *instance = &top_instance; in trace_reset() local
5994 instance->buffer_size = size; in trace_reset()
6000 instance = allocate_instance(optarg); in trace_reset()
6001 if (!instance) in trace_reset()
6002 die("Failed to create instance"); in trace_reset()
6003 add_instance(instance, local_cpu_count); in trace_reset()
6005 instance->flags |= BUFFER_FL_KEEP; in trace_reset()
6008 /* Force to use top instance */ in trace_reset()
6011 instance = &top_instance; in trace_reset()
6026 if (is_top_instance(instance)) in trace_reset()
6028 instance->flags &= ~BUFFER_FL_KEEP; in trace_reset()
6033 update_first_instance(instance, topt); in trace_reset()
6056 ctx->instance = &top_instance; in init_common_record_context()
6071 static void add_argv(struct buffer_instance *instance, char *arg, bool prepend) in add_argv() argument
6073 instance->argv = realloc(instance->argv, in add_argv()
6074 (instance->argc + 1) * sizeof(char *)); in add_argv()
6075 if (!instance->argv) in add_argv()
6076 die("Can not allocate instance args"); in add_argv()
6078 memmove(instance->argv + 1, instance->argv, in add_argv()
6079 instance->argc * sizeof(*instance->argv)); in add_argv()
6080 instance->argv[0] = arg; in add_argv()
6082 instance->argv[instance->argc] = arg; in add_argv()
6084 instance->argc++; in add_argv()
6087 static void add_arg(struct buffer_instance *instance, in add_arg() argument
6102 add_argv(instance, arg, false); in add_arg()
6107 add_argv(instance, arg, false); in add_arg()
6117 add_argv(instance, arg, false); in add_arg()
6122 add_argv(instance, arg, false); in add_arg()
6152 check_instance_die(struct buffer_instance *instance, char *param) in check_instance_die() argument
6154 if (instance->delete) in check_instance_die()
6155 die("Instance %s is marked for deletion, invalid option %s", in check_instance_die()
6156 tracefs_instance_get_name(instance->tracefs), param); in check_instance_die()
6159 static bool clock_is_supported(struct tracefs_instance *instance, const char *clock) in clock_is_supported() argument
6164 all_clocks = tracefs_instance_file_read(instance, "trace_clock", NULL); in clock_is_supported()
6263 struct buffer_instance *instance, *del_list = NULL; in parse_record_options() local
6315 * If the current instance is to record a guest, then save in parse_record_options()
6316 * all the arguments for this instance. in parse_record_options()
6318 if (c != 'B' && c != 'A' && c != OPT_name && is_guest(ctx->instance)) { in parse_record_options()
6319 add_arg(ctx->instance, c, opts, long_options, optarg); in parse_record_options()
6321 ctx->instance->flags |= BUFFER_FL_HAS_CLOCK; in parse_record_options()
6339 check_instance_die(ctx->instance, "-e"); in parse_record_options()
6346 add_event(ctx->instance, event); in parse_record_options()
6380 if (!ctx->instance) in parse_record_options()
6381 die("No instance defined for name option\n"); in parse_record_options()
6382 if (!is_guest(ctx->instance)) in parse_record_options()
6384 free(ctx->instance->name); in parse_record_options()
6385 ctx->instance->name = strdup(optarg); in parse_record_options()
6386 if (!ctx->instance->name) in parse_record_options()
6413 ctx->instance = allocate_instance(name); in parse_record_options()
6414 if (!ctx->instance) in parse_record_options()
6415 die("Failed to allocate instance"); in parse_record_options()
6418 ctx->instance->flags |= BUFFER_FL_NETWORK; in parse_record_options()
6419 ctx->instance->port_type = USE_TCP; in parse_record_options()
6422 ctx->instance->flags |= BUFFER_FL_GUEST; in parse_record_options()
6423 ctx->instance->result = result; in parse_record_options()
6424 ctx->instance->cid = cid; in parse_record_options()
6425 ctx->instance->port = port; in parse_record_options()
6426 ctx->instance->name = name; in parse_record_options()
6427 add_instance(ctx->instance, 0); in parse_record_options()
6432 test_set_event_pid(ctx->instance); in parse_record_options()
6440 check_instance_die(ctx->instance, "-P"); in parse_record_options()
6441 test_set_event_pid(ctx->instance); in parse_record_options()
6447 fpids_count += add_filter_pid(ctx->instance, in parse_record_options()
6450 ctx->instance->nr_process_pids++; in parse_record_options()
6452 ctx->instance->process_pids = ctx->instance->filter_pids; in parse_record_options()
6456 check_instance_die(ctx->instance, "-c"); in parse_record_options()
6457 test_set_event_pid(ctx->instance); in parse_record_options()
6459 if (!ctx->instance->have_event_fork) { in parse_record_options()
6464 ctx->instance->ptrace_child = 1; in parse_record_options()
6467 save_option(ctx->instance, "event-fork"); in parse_record_options()
6469 if (ctx->instance->have_func_fork) in parse_record_options()
6470 save_option(ctx->instance, "function-fork"); in parse_record_options()
6473 check_instance_die(ctx->instance, "-C"); in parse_record_options()
6479 ctx->instance->flags |= BUFFER_FL_TSC2NSEC; in parse_record_options()
6480 ctx->instance->clock = TSC_CLOCK; in parse_record_options()
6482 ctx->instance->clock = optarg; in parse_record_options()
6484 if (!clock_is_supported(NULL, ctx->instance->clock)) in parse_record_options()
6485 die("Clock %s is not supported", ctx->instance->clock); in parse_record_options()
6486 ctx->instance->clock = strdup(ctx->instance->clock); in parse_record_options()
6487 if (!ctx->instance->clock) in parse_record_options()
6489 ctx->instance->flags |= BUFFER_FL_HAS_CLOCK; in parse_record_options()
6490 if (!ctx->clock && !is_guest(ctx->instance)) in parse_record_options()
6491 ctx->clock = ctx->instance->clock; in parse_record_options()
6497 add_func(&ctx->instance->filter_funcs, in parse_record_options()
6498 ctx->instance->filter_mod, optarg); in parse_record_options()
6502 check_instance_die(ctx->instance, "-n"); in parse_record_options()
6503 add_func(&ctx->instance->notrace_funcs, in parse_record_options()
6504 ctx->instance->filter_mod, optarg); in parse_record_options()
6508 check_instance_die(ctx->instance, "-g"); in parse_record_options()
6509 add_func(&graph_funcs, ctx->instance->filter_mod, optarg); in parse_record_options()
6513 check_instance_die(ctx->instance, "-p"); in parse_record_options()
6514 if (ctx->instance->plugin) in parse_record_options()
6518 ctx->instance->plugin = plugin; in parse_record_options()
6563 check_instance_die(ctx->instance, "-O"); in parse_record_options()
6565 save_option(ctx->instance, option); in parse_record_options()
6568 check_instance_die(ctx->instance, "-T"); in parse_record_options()
6569 save_option(ctx->instance, "stacktrace"); in parse_record_options()
6573 check_instance_die(ctx->instance, "-H"); in parse_record_options()
6574 add_hook(ctx->instance, optarg); in parse_record_options()
6619 ctx->instance->port_type = USE_VSOCK; in parse_record_options()
6629 check_instance_die(ctx->instance, "-M"); in parse_record_options()
6630 ctx->instance->cpumask = alloc_mask_from_hex(ctx->instance, optarg); in parse_record_options()
6635 ctx->topt = 1; /* Extract top instance also */ in parse_record_options()
6637 ctx->instance->port_type = USE_TCP; in parse_record_options()
6640 check_instance_die(ctx->instance, "-b"); in parse_record_options()
6641 ctx->instance->buffer_size = atoi(optarg); in parse_record_options()
6644 ctx->instance = allocate_instance(optarg); in parse_record_options()
6645 if (!ctx->instance) in parse_record_options()
6646 die("Failed to create instance"); in parse_record_options()
6647 ctx->instance->delete = negative; in parse_record_options()
6649 if (ctx->instance->delete) { in parse_record_options()
6650 ctx->instance->next = del_list; in parse_record_options()
6651 del_list = ctx->instance; in parse_record_options()
6653 add_instance(ctx->instance, local_cpu_count); in parse_record_options()
6655 ctx->instance->flags |= BUFFER_FL_PROFILE; in parse_record_options()
6672 check_instance_die(ctx->instance, "--proc-map"); in parse_record_options()
6673 ctx->instance->get_procmap = 1; in parse_record_options()
6695 check_instance_die(ctx->instance, "--profile"); in parse_record_options()
6697 ctx->instance->flags |= BUFFER_FL_PROFILE; in parse_record_options()
6720 check_instance_die(ctx->instance, "--max-graph-depth"); in parse_record_options()
6721 free(ctx->instance->max_graph_depth); in parse_record_options()
6722 ctx->instance->max_graph_depth = strdup(optarg); in parse_record_options()
6723 if (!ctx->instance->max_graph_depth) in parse_record_options()
6737 check_instance_die(ctx->instance, "--module"); in parse_record_options()
6738 if (ctx->instance->filter_mod) in parse_record_options()
6739 add_func(&ctx->instance->filter_funcs, in parse_record_options()
6740 ctx->instance->filter_mod, "*"); in parse_record_options()
6741 ctx->instance->filter_mod = optarg; in parse_record_options()
6758 ctx->instance->flags |= BUFFER_FL_TSC2NSEC; in parse_record_options()
6803 struct buffer_instance *instance; in parse_record_options() local
6805 for_all_instances(instance) { in parse_record_options()
6806 if (is_guest(instance)) in parse_record_options()
6807 add_argv(instance, "--date", true); in parse_record_options()
6811 if (!ctx->filtered && ctx->instance->filter_mod) in parse_record_options()
6812 add_func(&ctx->instance->filter_funcs, in parse_record_options()
6813 ctx->instance->filter_mod, "*"); in parse_record_options()
6833 warning("--proc-map is ignored for top instance, " in parse_record_options()
6839 for_all_instances(instance) { in parse_record_options()
6840 if (instance->get_procmap && !instance->nr_filter_pids) { in parse_record_options()
6841 warning("--proc-map is ignored for instance %s, " in parse_record_options()
6843 tracefs_instance_get_name(instance->tracefs)); in parse_record_options()
6844 instance->get_procmap = 0; in parse_record_options()
6874 struct buffer_instance *instance; in finalize_record_trace() local
6889 for_all_instances(instance) { in finalize_record_trace()
6890 if (instance->flags & BUFFER_FL_KEEP) in finalize_record_trace()
6891 write_tracing_on(instance, in finalize_record_trace()
6892 instance->tracing_on_init_val); in finalize_record_trace()
6893 if (is_agent(instance)) { in finalize_record_trace()
6894 tracecmd_msg_send_close_resp_msg(instance->msg_handle); in finalize_record_trace()
6895 tracecmd_output_close(instance->network_handle); in finalize_record_trace()
6900 tracecmd_output_close(ctx->instance->network_handle); in finalize_record_trace()
6905 struct buffer_instance *instance; in has_local_instances() local
6907 for_all_instances(instance) { in has_local_instances()
6908 if (is_guest(instance)) in has_local_instances()
6910 if (host && instance->msg_handle) in has_local_instances()
6919 struct buffer_instance *instance; in set_tsync_params() local
6944 } else { /* Use the current clock of the first host instance */ in set_tsync_params()
6955 for_all_instances(instance) { in set_tsync_params()
6956 if (clock && !(instance->flags & BUFFER_FL_HAS_CLOCK)) { in set_tsync_params()
6958 if (is_guest(instance)) { in set_tsync_params()
6959 if (!instance->clock) { in set_tsync_params()
6960 instance->clock = strdup(clock); in set_tsync_params()
6961 if (!instance->clock) in set_tsync_params()
6962 die("Can not allocate instance clock"); in set_tsync_params()
6964 add_argv(instance, (char *)instance->clock, true); in set_tsync_params()
6965 add_argv(instance, "-C", true); in set_tsync_params()
6967 instance->flags |= BUFFER_FL_TSC2NSEC; in set_tsync_params()
6968 } else if (force_tsc && !instance->clock) { in set_tsync_params()
6969 instance->clock = strdup(clock); in set_tsync_params()
6970 if (!instance->clock) in set_tsync_params()
6971 die("Can not allocate instance clock"); in set_tsync_params()
6974 instance->tsync_loop_interval = ctx->tsync_loop_interval; in set_tsync_params()
6984 struct buffer_instance *instance; in record_trace() local
6996 update_first_instance(ctx->instance, ctx->topt); in record_trace()
7011 for_all_instances(instance) { in record_trace()
7012 instance->output_file = strdup(ctx->output); in record_trace()
7013 if (!instance->output_file) in record_trace()
7014 die("Failed to allocate output file name for instance"); in record_trace()
7015 if (!ctx->manual && instance->flags & BUFFER_FL_PROFILE) in record_trace()
7016 enable_profile(instance); in record_trace()
7018 instance->tracing_on_init_val = read_tracing_on(instance); in record_trace()
7020 if (instance->tracing_on_init_val < 0) in record_trace()
7021 instance->tracing_on_init_val = 1; in record_trace()
7029 if (!is_guest(ctx->instance)) in record_trace()
7030 fset = set_ftrace(ctx->instance, !ctx->disable, ctx->total_disable); in record_trace()
7034 for_all_instances(instance) in record_trace()
7035 set_clock(ctx, instance); in record_trace()
7043 for_all_instances(instance) { in record_trace()
7044 set_funcs(instance); in record_trace()
7045 set_mask(instance); in record_trace()
7049 for_all_instances(instance) in record_trace()
7050 enable_events(instance); in record_trace()
7058 for_all_instances(instance) { in record_trace()
7059 if (instance->max_graph_depth) { in record_trace()
7060 set_max_graph_depth(instance, instance->max_graph_depth); in record_trace()
7061 free(instance->max_graph_depth); in record_trace()
7062 instance->max_graph_depth = NULL; in record_trace()
7076 } else if (ctx->instance && is_agent(ctx->instance)) { in record_trace()
7079 tracecmd_msg_wait_close(ctx->instance->msg_handle); in record_trace()
7094 for_all_instances(instance) { in record_trace()
7095 for (pid = instance->filter_pids; pid; pid = pid->next) { in record_trace()
7096 if (!pid->exclude && instance->ptrace_child) { in record_trace()
7097 ptrace_attach(instance, pid->pid); in record_trace()
7105 for_all_instances(instance) { in record_trace()
7106 /* If an instance is not tracing individual processes in record_trace()
7110 if (!instance->nr_process_pids || in record_trace()
7111 trace_wait_for_processes(instance)) in record_trace()
7173 struct buffer_instance *instance; in trace_extract() local
7180 update_first_instance(ctx.instance, 1); in trace_extract()
7187 for_all_instances(instance) { in trace_extract()
7188 instance->output_file = strdup(ctx.output); in trace_extract()
7189 if (!instance->output_file) in trace_extract()
7190 die("Failed to allocate output file name for instance"); in trace_extract()
7192 if (!ctx.manual && instance->flags & BUFFER_FL_PROFILE) in trace_extract()
7193 enable_profile(ctx.instance); in trace_extract()
7195 instance->tracing_on_init_val = read_tracing_on(instance); in trace_extract()
7197 if (instance->tracing_on_init_val < 0) in trace_extract()
7198 instance->tracing_on_init_val = 1; in trace_extract()
7212 for_all_instances(instance) { in trace_extract()
7213 if (instance->max_graph_depth) { in trace_extract()
7214 set_max_graph_depth(instance, instance->max_graph_depth); in trace_extract()
7215 free(instance->max_graph_depth); in trace_extract()
7216 instance->max_graph_depth = NULL; in trace_extract()
7263 * If no instances were set, then enable profiling on the top instance. in trace_profile()
7311 ctx.instance->fds = fds; in trace_record_agent()
7312 ctx.instance->use_fifos = use_fifos; in trace_record_agent()
7313 ctx.instance->flags |= BUFFER_FL_AGENT; in trace_record_agent()
7314 ctx.instance->msg_handle = msg_handle; in trace_record_agent()
7315 ctx.instance->host = host; in trace_record_agent()