From 77878c17ea0ac9508c21899bd38da1f971d52f5f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Mon, 26 Feb 2024 15:56:27 -0500 Subject: [PATCH] lttng: enable-event: treat 'all' case as a regular pattern MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The cmd_enable_events function is essentially duplicated to handle the "all events" case, but it simply substitutes the event name for '*'. The case can be eliminated if we simply add '*' as one of the patterns to enable when the '--all' option is used. Signed-off-by: Jérémie Galarneau Change-Id: If4235c391c2ce38a67208184c97bbe0f5c40c97d --- src/bin/lttng/commands/enable_events.cpp | 297 +---------------------- 1 file changed, 8 insertions(+), 289 deletions(-) diff --git a/src/bin/lttng/commands/enable_events.cpp b/src/bin/lttng/commands/enable_events.cpp index 78cc0ea8b..c0d9e0166 100644 --- a/src/bin/lttng/commands/enable_events.cpp +++ b/src/bin/lttng/commands/enable_events.cpp @@ -512,292 +512,6 @@ int enable_events(const std::string& session_name, const event_rule_patterns& pa } } - if (opt_enable_all) { - /* Default setup for enable all */ - if (opt_kernel) { - ev->type = (lttng_event_type) opt_event_type; - strcpy(ev->name, "*"); - /* kernel loglevels not implemented */ - ev->loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; - } else { - ev->type = LTTNG_EVENT_TRACEPOINT; - strcpy(ev->name, "*"); - ev->loglevel_type = (lttng_loglevel_type) opt_loglevel_type; - if (opt_loglevel) { - int name_search_ret; - - LTTNG_ASSERT(opt_userspace || opt_jul || opt_log4j || opt_python); - - if (opt_userspace) { - enum lttng_loglevel loglevel; - - name_search_ret = - loglevel_name_to_value(opt_loglevel, &loglevel); - ev->loglevel = (int) loglevel; - } else if (opt_jul) { - enum lttng_loglevel_jul loglevel; - - name_search_ret = - loglevel_jul_name_to_value(opt_loglevel, &loglevel); - ev->loglevel = (int) loglevel; - } else if (opt_log4j) { - enum lttng_loglevel_log4j loglevel; - - name_search_ret = loglevel_log4j_name_to_value(opt_loglevel, - &loglevel); - ev->loglevel = (int) loglevel; - } else { - /* python domain. */ - enum lttng_loglevel_python loglevel; - - name_search_ret = loglevel_python_name_to_value( - opt_loglevel, &loglevel); - ev->loglevel = (int) loglevel; - } - - if (name_search_ret == -1) { - ERR("Unknown loglevel %s", opt_loglevel); - ret = -LTTNG_ERR_INVALID; - goto error; - } - } else { - LTTNG_ASSERT(opt_userspace || opt_jul || opt_log4j || opt_python); - if (opt_userspace) { - ev->loglevel = -1; - } else if (opt_jul) { - ev->loglevel = LTTNG_LOGLEVEL_JUL_ALL; - } else if (opt_log4j) { - ev->loglevel = LTTNG_LOGLEVEL_LOG4J_ALL; - } else if (opt_python) { - ev->loglevel = LTTNG_LOGLEVEL_PYTHON_DEBUG; - } - } - } - - if (opt_exclude) { - ret = create_exclusion_list_and_validate("*", opt_exclude, &exclusions); - if (ret) { - ret = CMD_ERROR; - goto error; - } - - ev->exclusion = 1; - warn_on_truncated_exclusion_names(&exclusions, &warn); - } - if (!opt_filter) { - ret = lttng_enable_event_with_exclusions( - handle, - ev, - channel_name, - nullptr, - lttng_dynamic_pointer_array_get_count(&exclusions), - (char **) exclusions.array.buffer.data); - if (ret < 0) { - switch (-ret) { - case LTTNG_ERR_KERN_EVENT_EXIST: - WARN("Kernel events already enabled (channel %s, session %s)", - print_channel_name(channel_name), - session_name.c_str()); - warn = 1; - break; - case LTTNG_ERR_TRACE_ALREADY_STARTED: - { - const char *msg = - "The command tried to enable an event in a new domain for a session that has already been started once."; - ERR("Events: %s (channel %s, session %s)", - msg, - print_channel_name(channel_name), - session_name.c_str()); - error = 1; - break; - } - default: - ERR("Events: %s (channel %s, session %s)", - lttng_strerror(ret), - ret == -LTTNG_ERR_NEED_CHANNEL_NAME ? - print_raw_channel_name(channel_name) : - print_channel_name(channel_name), - session_name.c_str()); - error = 1; - break; - } - goto end; - } - - switch (opt_event_type) { - case LTTNG_EVENT_TRACEPOINT: - if (opt_loglevel && dom.type != LTTNG_DOMAIN_KERNEL) { - char *exclusion_string = print_exclusions(&exclusions); - - if (!exclusion_string) { - PERROR("Cannot allocate exclusion_string"); - error = 1; - goto end; - } - MSG("All %s tracepoints%s are enabled in channel %s for loglevel %s", - lttng_domain_type_str(dom.type), - exclusion_string, - print_channel_name(channel_name), - opt_loglevel); - free(exclusion_string); - } else { - char *exclusion_string = print_exclusions(&exclusions); - - if (!exclusion_string) { - PERROR("Cannot allocate exclusion_string"); - error = 1; - goto end; - } - MSG("All %s tracepoints%s are enabled in channel %s", - lttng_domain_type_str(dom.type), - exclusion_string, - print_channel_name(channel_name)); - free(exclusion_string); - } - break; - case LTTNG_EVENT_SYSCALL: - if (opt_kernel) { - MSG("All %s system calls are enabled in channel %s", - lttng_domain_type_str(dom.type), - print_channel_name(channel_name)); - } - break; - case LTTNG_EVENT_ALL: - if (opt_loglevel && dom.type != LTTNG_DOMAIN_KERNEL) { - char *exclusion_string = print_exclusions(&exclusions); - - if (!exclusion_string) { - PERROR("Cannot allocate exclusion_string"); - error = 1; - goto end; - } - MSG("All %s events%s are enabled in channel %s for loglevel %s", - lttng_domain_type_str(dom.type), - exclusion_string, - print_channel_name(channel_name), - opt_loglevel); - free(exclusion_string); - } else { - char *exclusion_string = print_exclusions(&exclusions); - - if (!exclusion_string) { - PERROR("Cannot allocate exclusion_string"); - error = 1; - goto end; - } - MSG("All %s events%s are enabled in channel %s", - lttng_domain_type_str(dom.type), - exclusion_string, - print_channel_name(channel_name)); - free(exclusion_string); - } - break; - default: - /* - * We should not be here since lttng_enable_event should have - * failed on the event type. - */ - goto error; - } - } - - if (opt_filter) { - command_ret = lttng_enable_event_with_exclusions( - handle, - ev, - channel_name, - opt_filter, - lttng_dynamic_pointer_array_get_count(&exclusions), - (char **) exclusions.array.buffer.data); - if (command_ret < 0) { - switch (-command_ret) { - case LTTNG_ERR_FILTER_EXIST: - WARN("Filter on all events is already enabled" - " (channel %s, session %s)", - print_channel_name(channel_name), - session_name.c_str()); - warn = 1; - break; - case LTTNG_ERR_TRACE_ALREADY_STARTED: - { - const char *msg = - "The command tried to enable an event in a new domain for a session that has already been started once."; - ERR("All events: %s (channel %s, session %s, filter \'%s\')", - msg, - print_channel_name(channel_name), - session_name.c_str(), - opt_filter); - error = 1; - break; - } - default: - ERR("All events: %s (channel %s, session %s, filter \'%s\')", - lttng_strerror(command_ret), - command_ret == -LTTNG_ERR_NEED_CHANNEL_NAME ? - print_raw_channel_name(channel_name) : - print_channel_name(channel_name), - session_name.c_str(), - opt_filter); - error = 1; - break; - } - error_holder = command_ret; - } else { - ev->filter = 1; - MSG("Filter '%s' successfully set", opt_filter); - } - } - - if (lttng_opt_mi) { - /* The wildcard * is used for kernel and ust domain to - * represent ALL. We copy * in event name to force the wildcard use - * for kernel domain - * - * Note: this is strictly for semantic and printing while in - * machine interface mode. - */ - strcpy(ev->name, "*"); - - /* If we reach here the events are enabled */ - if (!error && !warn) { - ev->enabled = 1; - } else { - ev->enabled = 0; - success = 0; - } - ret = mi_lttng_event(writer.get(), ev, 1, handle->domain.type); - if (ret) { - ret = CMD_ERROR; - goto error; - } - - /* print exclusion */ - ret = mi_print_exclusion(&exclusions); - if (ret) { - ret = CMD_ERROR; - goto error; - } - - /* Success ? */ - ret = mi_lttng_writer_write_element_bool( - writer.get(), mi_lttng_element_command_success, success); - if (ret) { - ret = CMD_ERROR; - goto error; - } - - /* Close event element */ - ret = mi_lttng_writer_close_element(writer.get()); - if (ret) { - ret = CMD_ERROR; - goto error; - } - } - - goto end; - } - - /* Strip event list */ for (const auto& pattern : patterns) { /* Copy name and type of the event */ strncpy(ev->name, pattern.c_str(), LTTNG_SYMBOL_NAME_LEN); @@ -1283,7 +997,6 @@ int cmd_enable_events(int argc, const char **argv) const char *leftover = nullptr; int event_type = -1; event_rule_patterns patterns; - std::stringstream event_list_arg_stream(arg_event_list); auto pc = lttng::make_unique_wrapper( poptGetContext(nullptr, argc, argv, long_options, 0)); @@ -1410,8 +1123,14 @@ int cmd_enable_events(int argc, const char **argv) return CMD_ERROR; } - for (std::string line; std::getline(event_list_arg_stream, line, ',');) { - patterns.emplace_back(std::move(line)); + if (opt_enable_all) { + patterns.emplace_back("*"); + } else { + std::stringstream event_list_arg_stream(arg_event_list); + + for (std::string line; std::getline(event_list_arg_stream, line, ',');) { + patterns.emplace_back(std::move(line)); + } } leftover = poptGetArg(pc.get()); -- 2.34.1