X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Flist_triggers.c;h=929d9a46b442e01b26679906972253c0d9d50a85;hb=695f70446965aeac8b1118bb08d572630c96114d;hp=054b3fb725027c5c5b8fadfd5967db425c47e3ff;hpb=405f9e7db1cd7c023614ae249f0705fbb3da514c;p=lttng-tools.git diff --git a/src/bin/lttng/commands/list_triggers.c b/src/bin/lttng/commands/list_triggers.c index 054b3fb72..929d9a46b 100644 --- a/src/bin/lttng/commands/list_triggers.c +++ b/src/bin/lttng/commands/list_triggers.c @@ -14,8 +14,14 @@ #include "common/mi-lttng.h" /* For lttng_condition_type_str(). */ #include "lttng/condition/condition-internal.h" +#include "lttng/condition/event-rule-matches.h" +#include "lttng/condition/event-rule-matches-internal.h" /* For lttng_domain_type_str(). */ #include "lttng/domain-internal.h" +/* For lttng_event_rule_kernel_syscall_emission_site_str() */ +#include "lttng/event-rule/kernel-syscall-internal.h" +#include "../loglevel.h" +#include #ifdef LTTNG_EMBED_HELP static const char help_msg[] = @@ -23,6 +29,14 @@ static const char help_msg[] = ; #endif +typedef enum lttng_event_rule_status (*event_rule_logging_get_name_pattern)( + const struct lttng_event_rule *rule, const char **pattern); +typedef enum lttng_event_rule_status (*event_rule_logging_get_filter)( + const struct lttng_event_rule *rule, const char **expression); +typedef enum lttng_event_rule_status (*event_rule_logging_get_log_level_rule)( + const struct lttng_event_rule *rule, + const struct lttng_log_level_rule **log_level_rule); + enum { OPT_HELP, OPT_LIST_OPTIONS, @@ -35,29 +49,130 @@ struct argpar_opt_descr list_trigger_options[] = { ARGPAR_OPT_DESCR_SENTINEL, }; +static void print_condition_session_consumed_size( + const struct lttng_condition *condition) +{ + enum lttng_condition_status condition_status; + const char *session_name; + uint64_t threshold; + + condition_status = + lttng_condition_session_consumed_size_get_session_name( + condition, &session_name); + assert(condition_status == LTTNG_CONDITION_STATUS_OK); + + lttng_condition_session_consumed_size_get_threshold( + condition, &threshold); + assert(condition_status == LTTNG_CONDITION_STATUS_OK); + + MSG(" session name: %s", session_name); + MSG(" threshold: %" PRIu64 " bytes", threshold); +} + +static void print_condition_buffer_usage( + const struct lttng_condition *condition) +{ + enum lttng_condition_status condition_status; + const char *session_name, *channel_name; + enum lttng_domain_type domain_type; + uint64_t threshold; + + condition_status = lttng_condition_buffer_usage_get_session_name( + condition, &session_name); + assert(condition_status == LTTNG_CONDITION_STATUS_OK); + + condition_status = lttng_condition_buffer_usage_get_channel_name( + condition, &channel_name); + assert(condition_status == LTTNG_CONDITION_STATUS_OK); + + condition_status = lttng_condition_buffer_usage_get_domain_type( + condition, &domain_type); + assert(condition_status == LTTNG_CONDITION_STATUS_OK); + + MSG(" session name: %s", session_name); + MSG(" channel name: %s", channel_name); + MSG(" domain: %s", lttng_domain_type_str(domain_type)); + + condition_status = lttng_condition_buffer_usage_get_threshold( + condition, &threshold); + if (condition_status == LTTNG_CONDITION_STATUS_OK) { + MSG(" threshold (bytes): %" PRIu64, threshold); + } else { + double threshold_ratio; + + assert(condition_status == LTTNG_CONDITION_STATUS_UNSET); + + condition_status = + lttng_condition_buffer_usage_get_threshold_ratio( + condition, &threshold_ratio); + assert(condition_status == LTTNG_CONDITION_STATUS_OK); + + MSG(" threshold (ratio): %.2f", threshold_ratio); + } +} + +static void print_condition_session_rotation( + const struct lttng_condition *condition) +{ + enum lttng_condition_status condition_status; + const char *session_name; + + condition_status = lttng_condition_session_rotation_get_session_name( + condition, &session_name); + assert(condition_status == LTTNG_CONDITION_STATUS_OK); + + MSG(" session name: %s", session_name); +} + +/* + * Returns the human-readable log level name associated with a numerical value + * if there is one. The Log4j and JUL event rule have discontinuous log level + * values (a value can fall between two labels). In those cases, NULL is + * returned. + */ +static const char *get_pretty_loglevel_name( + enum lttng_event_rule_type event_rule_type, int loglevel) +{ + const char *name = NULL; + + switch (event_rule_type) { + case LTTNG_EVENT_RULE_TYPE_USER_TRACEPOINT: + name = loglevel_value_to_name(loglevel); + break; + case LTTNG_EVENT_RULE_TYPE_LOG4J_LOGGING: + name = loglevel_log4j_value_to_name(loglevel); + break; + case LTTNG_EVENT_RULE_TYPE_JUL_LOGGING: + name = loglevel_jul_value_to_name(loglevel); + break; + case LTTNG_EVENT_RULE_TYPE_PYTHON_LOGGING: + name = loglevel_python_value_to_name(loglevel); + break; + default: + break; + } + + return name; +} + static -void print_event_rule_tracepoint(const struct lttng_event_rule *event_rule) +void print_event_rule_user_tracepoint(const struct lttng_event_rule *event_rule) { enum lttng_event_rule_status event_rule_status; - enum lttng_domain_type domain_type; const char *pattern; const char *filter; int log_level; + const struct lttng_log_level_rule *log_level_rule = NULL; unsigned int exclusions_count; int i; - event_rule_status = lttng_event_rule_tracepoint_get_pattern( + event_rule_status = lttng_event_rule_user_tracepoint_get_name_pattern( event_rule, &pattern); assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_OK); - event_rule_status = lttng_event_rule_tracepoint_get_domain_type( - event_rule, &domain_type); - assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_OK); - - _MSG(" rule: %s (type: tracepoint, domain: %s", pattern, - lttng_domain_type_str(domain_type)); + _MSG(" rule: %s (type: user tracepoint", pattern); - event_rule_status = lttng_event_rule_tracepoint_get_filter( + event_rule_status = lttng_event_rule_user_tracepoint_get_filter( event_rule, &filter); if (event_rule_status == LTTNG_EVENT_RULE_STATUS_OK) { _MSG(", filter: %s", filter); @@ -65,28 +180,43 @@ void print_event_rule_tracepoint(const struct lttng_event_rule *event_rule) assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_UNSET); } - event_rule_status = lttng_event_rule_tracepoint_get_log_level( - event_rule, &log_level); + event_rule_status = lttng_event_rule_user_tracepoint_get_log_level_rule( + event_rule, &log_level_rule); if (event_rule_status == LTTNG_EVENT_RULE_STATUS_OK) { - enum lttng_loglevel_type log_level_type; + enum lttng_log_level_rule_status llr_status; const char *log_level_op; + const char *pretty_loglevel_name; + + switch (lttng_log_level_rule_get_type(log_level_rule)) { + case LTTNG_LOG_LEVEL_RULE_TYPE_EXACTLY: + log_level_op = "is"; + llr_status = lttng_log_level_rule_exactly_get_level( + log_level_rule, &log_level); + break; + case LTTNG_LOG_LEVEL_RULE_TYPE_AT_LEAST_AS_SEVERE_AS: + log_level_op = "at least"; + llr_status = lttng_log_level_rule_at_least_as_severe_as_get_level( + log_level_rule, &log_level); + break; + default: + abort(); + } - event_rule_status = lttng_event_rule_tracepoint_get_log_level_type( - event_rule, &log_level_type); - assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_OK); - assert(log_level_type == LTTNG_EVENT_LOGLEVEL_RANGE || - log_level_type == LTTNG_EVENT_LOGLEVEL_SINGLE); - - log_level_op = (log_level_type == LTTNG_EVENT_LOGLEVEL_RANGE ? "<=" : "=="); + assert(llr_status == LTTNG_LOG_LEVEL_RULE_STATUS_OK); - _MSG(", log level %s %s", log_level_op, - mi_lttng_loglevel_string( - log_level, domain_type)); + pretty_loglevel_name = get_pretty_loglevel_name( + LTTNG_EVENT_RULE_TYPE_USER_TRACEPOINT, log_level); + if (pretty_loglevel_name) { + _MSG(", log level %s %s", log_level_op, + pretty_loglevel_name); + } else { + _MSG(", log level %s %d", log_level_op, log_level); + } } else { assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_UNSET); } - event_rule_status = lttng_event_rule_tracepoint_get_exclusions_count( + event_rule_status = lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_count( event_rule, &exclusions_count); assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_OK); if (exclusions_count > 0) { @@ -94,7 +224,7 @@ void print_event_rule_tracepoint(const struct lttng_event_rule *event_rule) for (i = 0; i < exclusions_count; i++) { const char *exclusion; - event_rule_status = lttng_event_rule_tracepoint_get_exclusion_at_index( + event_rule_status = lttng_event_rule_user_tracepoint_get_name_pattern_exclusion_at_index( event_rule, i, &exclusion); assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_OK); @@ -105,6 +235,128 @@ void print_event_rule_tracepoint(const struct lttng_event_rule *event_rule) MSG(")"); } +static +void print_event_rule_kernel_tracepoint(const struct lttng_event_rule *event_rule) +{ + enum lttng_event_rule_status event_rule_status; + const char *pattern; + const char *filter; + + event_rule_status = lttng_event_rule_kernel_tracepoint_get_name_pattern( + event_rule, &pattern); + assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_OK); + + _MSG(" rule: %s (type: kernel tracepoint", pattern); + + event_rule_status = lttng_event_rule_kernel_tracepoint_get_filter( + event_rule, &filter); + if (event_rule_status == LTTNG_EVENT_RULE_STATUS_OK) { + _MSG(", filter: %s", filter); + } else { + assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_UNSET); + } + + MSG(")"); +} + +static +void print_event_rule_logging(const struct lttng_event_rule *event_rule) +{ + enum lttng_event_rule_status event_rule_status; + enum lttng_event_rule_type event_rule_type = lttng_event_rule_get_type(event_rule); + const char *pattern; + const char *filter; + int log_level; + const struct lttng_log_level_rule *log_level_rule = NULL; + const char *type_str = NULL; + + event_rule_logging_get_name_pattern logging_get_name_pattern; + event_rule_logging_get_filter logging_get_filter; + event_rule_logging_get_log_level_rule logging_get_log_level_rule; + + switch (event_rule_type) { + case LTTNG_EVENT_RULE_TYPE_JUL_LOGGING: + logging_get_name_pattern = + lttng_event_rule_jul_logging_get_name_pattern; + logging_get_filter = lttng_event_rule_jul_logging_get_filter; + logging_get_log_level_rule = + lttng_event_rule_jul_logging_get_log_level_rule; + type_str = "jul"; + break; + case LTTNG_EVENT_RULE_TYPE_LOG4J_LOGGING: + logging_get_name_pattern = + lttng_event_rule_log4j_logging_get_name_pattern; + logging_get_filter = lttng_event_rule_log4j_logging_get_filter; + logging_get_log_level_rule = + lttng_event_rule_log4j_logging_get_log_level_rule; + type_str = "log4j"; + break; + case LTTNG_EVENT_RULE_TYPE_PYTHON_LOGGING: + logging_get_name_pattern = + lttng_event_rule_python_logging_get_name_pattern; + logging_get_filter = lttng_event_rule_python_logging_get_filter; + logging_get_log_level_rule = + lttng_event_rule_python_logging_get_log_level_rule; + type_str = "python"; + break; + default: + abort(); + break; + } + + event_rule_status = logging_get_name_pattern( + event_rule, &pattern); + assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_OK); + + _MSG(" rule: %s (type: %s:logging", pattern, type_str); + + event_rule_status = logging_get_filter( + event_rule, &filter); + if (event_rule_status == LTTNG_EVENT_RULE_STATUS_OK) { + _MSG(", filter: %s", filter); + } else { + assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_UNSET); + } + + event_rule_status = logging_get_log_level_rule( + event_rule, &log_level_rule); + if (event_rule_status == LTTNG_EVENT_RULE_STATUS_OK) { + enum lttng_log_level_rule_status llr_status; + const char *log_level_op; + const char *pretty_loglevel_name; + + switch (lttng_log_level_rule_get_type(log_level_rule)) { + case LTTNG_LOG_LEVEL_RULE_TYPE_EXACTLY: + log_level_op = "is"; + llr_status = lttng_log_level_rule_exactly_get_level( + log_level_rule, &log_level); + break; + case LTTNG_LOG_LEVEL_RULE_TYPE_AT_LEAST_AS_SEVERE_AS: + log_level_op = "at least"; + llr_status = lttng_log_level_rule_at_least_as_severe_as_get_level( + log_level_rule, &log_level); + break; + default: + abort(); + } + + assert(llr_status == LTTNG_LOG_LEVEL_RULE_STATUS_OK); + + pretty_loglevel_name = get_pretty_loglevel_name( + event_rule_type, log_level); + if (pretty_loglevel_name) { + _MSG(", log level %s %s", log_level_op, + pretty_loglevel_name); + } else { + _MSG(", log level %s %d", log_level_op, log_level); + } + } else { + assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_UNSET); + } + + MSG(")"); +} + static void print_kernel_probe_location( const struct lttng_kernel_probe_location *location) { @@ -166,22 +418,22 @@ void print_event_rule_kernel_probe(const struct lttng_event_rule *event_rule) const char *name; const struct lttng_kernel_probe_location *location; - assert(lttng_event_rule_get_type(event_rule) == LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE); + assert(lttng_event_rule_get_type(event_rule) == LTTNG_EVENT_RULE_TYPE_KERNEL_KPROBE); - event_rule_status = lttng_event_rule_kernel_probe_get_event_name(event_rule, &name); + event_rule_status = lttng_event_rule_kernel_kprobe_get_event_name(event_rule, &name); if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) { ERR("Failed to get kprobe event rule's name."); goto end; } - event_rule_status = lttng_event_rule_kernel_probe_get_location( + event_rule_status = lttng_event_rule_kernel_kprobe_get_location( event_rule, &location); if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) { ERR("Failed to get kprobe event rule's location."); goto end; } - _MSG(" rule: %s (type: probe, location: ", name); + _MSG(" rule: %s (type: kernel:kprobe, location: ", name); print_kernel_probe_location(location); @@ -199,23 +451,23 @@ void print_event_rule_userspace_probe(const struct lttng_event_rule *event_rule) const struct lttng_userspace_probe_location *location; enum lttng_userspace_probe_location_type userspace_probe_location_type; - assert(lttng_event_rule_get_type(event_rule) == LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE); + assert(lttng_event_rule_get_type(event_rule) == LTTNG_EVENT_RULE_TYPE_KERNEL_UPROBE); - event_rule_status = lttng_event_rule_userspace_probe_get_event_name( + event_rule_status = lttng_event_rule_kernel_uprobe_get_event_name( event_rule, &name); if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) { ERR("Failed to get uprobe event rule's name."); goto end; } - event_rule_status = lttng_event_rule_userspace_probe_get_location( + event_rule_status = lttng_event_rule_kernel_uprobe_get_location( event_rule, &location); if (event_rule_status != LTTNG_EVENT_RULE_STATUS_OK) { ERR("Failed to get uprobe event rule's location."); goto end; } - _MSG(" rule: %s (type: userspace probe, location: ", name); + _MSG(" rule: %s (type: kernel:uprobe, ", name); userspace_probe_location_type = lttng_userspace_probe_location_get_type(location); @@ -230,12 +482,22 @@ void print_event_rule_userspace_probe(const struct lttng_event_rule *event_rule) function_name = lttng_userspace_probe_location_function_get_function_name( location); - _MSG("%s:%s", binary_path, function_name); + _MSG("location type: ELF, location: %s:%s", binary_path, function_name); break; } case LTTNG_USERSPACE_PROBE_LOCATION_TYPE_TRACEPOINT: - _MSG("SDT not implemented yet"); + { + const char *binary_path, *provider_name, *probe_name; + + binary_path = lttng_userspace_probe_location_tracepoint_get_binary_path( + location); + provider_name = lttng_userspace_probe_location_tracepoint_get_provider_name( + location); + probe_name = lttng_userspace_probe_location_tracepoint_get_probe_name( + location); + _MSG("location type: SDT, location: %s:%s:%s", binary_path, provider_name, probe_name); break; + } default: abort(); } @@ -251,16 +513,22 @@ void print_event_rule_syscall(const struct lttng_event_rule *event_rule) { const char *pattern, *filter; enum lttng_event_rule_status event_rule_status; + enum lttng_event_rule_kernel_syscall_emission_site emission_site; + + assert(lttng_event_rule_get_type(event_rule) == LTTNG_EVENT_RULE_TYPE_KERNEL_SYSCALL); - assert(lttng_event_rule_get_type(event_rule) == LTTNG_EVENT_RULE_TYPE_SYSCALL); + emission_site = + lttng_event_rule_kernel_syscall_get_emission_site(event_rule); - event_rule_status = lttng_event_rule_syscall_get_pattern( + event_rule_status = lttng_event_rule_kernel_syscall_get_name_pattern( event_rule, &pattern); assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_OK); - _MSG(" rule: %s (type: syscall", pattern); + _MSG(" rule: %s (type: kernel:syscall:%s", pattern, + lttng_event_rule_kernel_syscall_emission_site_str( + emission_site)); - event_rule_status = lttng_event_rule_syscall_get_filter( + event_rule_status = lttng_event_rule_kernel_syscall_get_filter( event_rule, &filter); if (event_rule_status == LTTNG_EVENT_RULE_STATUS_OK) { _MSG(", filter: %s", filter); @@ -278,16 +546,24 @@ void print_event_rule(const struct lttng_event_rule *event_rule) lttng_event_rule_get_type(event_rule); switch (event_rule_type) { - case LTTNG_EVENT_RULE_TYPE_TRACEPOINT: - print_event_rule_tracepoint(event_rule); + case LTTNG_EVENT_RULE_TYPE_USER_TRACEPOINT: + print_event_rule_user_tracepoint(event_rule); break; - case LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE: + case LTTNG_EVENT_RULE_TYPE_KERNEL_TRACEPOINT: + print_event_rule_kernel_tracepoint(event_rule); + break; + case LTTNG_EVENT_RULE_TYPE_JUL_LOGGING: + case LTTNG_EVENT_RULE_TYPE_LOG4J_LOGGING: + case LTTNG_EVENT_RULE_TYPE_PYTHON_LOGGING: + print_event_rule_logging(event_rule); + break; + case LTTNG_EVENT_RULE_TYPE_KERNEL_KPROBE: print_event_rule_kernel_probe(event_rule); break; - case LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE: + case LTTNG_EVENT_RULE_TYPE_KERNEL_UPROBE: print_event_rule_userspace_probe(event_rule); break; - case LTTNG_EVENT_RULE_TYPE_SYSCALL: + case LTTNG_EVENT_RULE_TYPE_KERNEL_SYSCALL: print_event_rule_syscall(event_rule); break; default: @@ -362,21 +638,21 @@ void print_one_event_expr(const struct lttng_event_expr *event_expr) } } -static -void print_condition_on_event(const struct lttng_condition *condition) +static void print_condition_event_rule_matches( + const struct lttng_condition *condition) { const struct lttng_event_rule *event_rule; enum lttng_condition_status condition_status; unsigned int cap_desc_count, i; - condition_status = - lttng_condition_on_event_get_rule(condition, &event_rule); + condition_status = lttng_condition_event_rule_matches_get_rule( + condition, &event_rule); assert(condition_status == LTTNG_CONDITION_STATUS_OK); print_event_rule(event_rule); condition_status = - lttng_condition_on_event_get_capture_descriptor_count( + lttng_condition_event_rule_matches_get_capture_descriptor_count( condition, &cap_desc_count); assert(condition_status == LTTNG_CONDITION_STATUS_OK); @@ -385,7 +661,7 @@ void print_condition_on_event(const struct lttng_condition *condition) for (i = 0; i < cap_desc_count; i++) { const struct lttng_event_expr *cap_desc = - lttng_condition_on_event_get_capture_descriptor_at_index( + lttng_condition_event_rule_matches_get_capture_descriptor_at_index( condition, i); _MSG(" - "); @@ -395,37 +671,163 @@ void print_condition_on_event(const struct lttng_condition *condition) } } +static void print_action_errors(const struct lttng_trigger *trigger, + const struct lttng_action *action, + const uint64_t *action_path_indexes, + size_t action_path_length) +{ + unsigned int i, count, printed_errors_count = 0; + enum lttng_error_code error_query_ret; + enum lttng_error_query_results_status results_status; + struct lttng_error_query_results *results = NULL; + const char *trigger_name; + uid_t trigger_uid; + enum lttng_trigger_status trigger_status; + struct lttng_error_query *query; + struct lttng_action_path *action_path = lttng_action_path_create( + action_path_indexes, action_path_length); + + assert(action_path); + + query = lttng_error_query_action_create(trigger, action_path); + assert(query); + + trigger_status = lttng_trigger_get_name(trigger, &trigger_name); + /* + * Anonymous triggers are not listed; this would be an internal error. + */ + assert(trigger_status == LTTNG_TRIGGER_STATUS_OK); + + trigger_status = lttng_trigger_get_owner_uid(trigger, &trigger_uid); + assert(trigger_status == LTTNG_TRIGGER_STATUS_OK); + + error_query_ret = lttng_error_query_execute( + query, lttng_session_daemon_command_endpoint, &results); + if (error_query_ret != LTTNG_OK) { + ERR("Failed to query errors of trigger '%s' (owner uid: %d): %s", + trigger_name, (int) trigger_uid, + lttng_strerror(-error_query_ret)); + goto end; + } + + results_status = lttng_error_query_results_get_count(results, &count); + assert(results_status == LTTNG_ERROR_QUERY_RESULTS_STATUS_OK); + + _MSG(" errors:"); + + for (i = 0; i < count; i++) { + const struct lttng_error_query_result *result; + enum lttng_error_query_result_status result_status; + const char *result_name; + const char *result_description; + uint64_t result_value; + + results_status = lttng_error_query_results_get_result( + results, &result, i); + assert(results_status == LTTNG_ERROR_QUERY_RESULTS_STATUS_OK); + + result_status = lttng_error_query_result_get_name( + result, &result_name); + assert(result_status == LTTNG_ERROR_QUERY_RESULT_STATUS_OK); + result_status = lttng_error_query_result_get_description( + result, &result_description); + assert(result_status == LTTNG_ERROR_QUERY_RESULT_STATUS_OK); + + if (lttng_error_query_result_get_type(result) == + LTTNG_ERROR_QUERY_RESULT_TYPE_COUNTER) { + result_status = lttng_error_query_result_counter_get_value( + result, &result_value); + assert(result_status == + LTTNG_ERROR_QUERY_RESULT_STATUS_OK); + if (result_value == 0) { + continue; + } + + MSG(""); + _MSG(" %s: %" PRIu64, result_name, + result_value); + printed_errors_count++; + } else { + _MSG(" Unknown error query result type for result '%s' (%s)", + result_name, result_description); + continue; + } + } + + if (printed_errors_count == 0) { + _MSG(" none"); + } + +end: + MSG(""); + lttng_error_query_destroy(query); + lttng_error_query_results_destroy(results); + lttng_action_path_destroy(action_path); +} + static -void print_one_action(const struct lttng_action *action) +void print_one_action(const struct lttng_trigger *trigger, + const struct lttng_action *action, + const uint64_t *action_path_indexes, + size_t action_path_length) { enum lttng_action_type action_type; enum lttng_action_status action_status; + const struct lttng_rate_policy *policy = NULL; const char *value; action_type = lttng_action_get_type(action); - assert(action_type != LTTNG_ACTION_TYPE_GROUP); + assert(action_type != LTTNG_ACTION_TYPE_LIST); switch (action_type) { case LTTNG_ACTION_TYPE_NOTIFY: - MSG("notify"); + _MSG("notify"); + + action_status = lttng_action_notify_get_rate_policy( + action, &policy); + if (action_status != LTTNG_ACTION_STATUS_OK) { + ERR("Failed to retrieve rate policy."); + goto end; + } break; case LTTNG_ACTION_TYPE_START_SESSION: action_status = lttng_action_start_session_get_session_name( action, &value); assert(action_status == LTTNG_ACTION_STATUS_OK); - MSG("start session `%s`", value); + _MSG("start session `%s`", value); + + action_status = lttng_action_start_session_get_rate_policy( + action, &policy); + if (action_status != LTTNG_ACTION_STATUS_OK) { + ERR("Failed to retrieve rate policy."); + goto end; + } break; case LTTNG_ACTION_TYPE_STOP_SESSION: action_status = lttng_action_stop_session_get_session_name( action, &value); assert(action_status == LTTNG_ACTION_STATUS_OK); - MSG("stop session `%s`", value); + _MSG("stop session `%s`", value); + + action_status = lttng_action_stop_session_get_rate_policy( + action, &policy); + if (action_status != LTTNG_ACTION_STATUS_OK) { + ERR("Failed to retrieve rate policy."); + goto end; + } break; case LTTNG_ACTION_TYPE_ROTATE_SESSION: action_status = lttng_action_rotate_session_get_session_name( action, &value); assert(action_status == LTTNG_ACTION_STATUS_OK); - MSG("rotate session `%s`", value); + _MSG("rotate session `%s`", value); + + action_status = lttng_action_rotate_session_get_rate_policy( + action, &policy); + if (action_status != LTTNG_ACTION_STATUS_OK) { + ERR("Failed to retrieve rate policy."); + goto end; + } break; case LTTNG_ACTION_TYPE_SNAPSHOT_SESSION: { @@ -480,13 +882,150 @@ void print_one_action(const struct lttng_action *action) } } - MSG(""); + action_status = lttng_action_snapshot_session_get_rate_policy( + action, &policy); + if (action_status != LTTNG_ACTION_STATUS_OK) { + ERR("Failed to retrieve rate policy."); + goto end; + } break; } - default: abort(); } + + if (policy) { + enum lttng_rate_policy_type policy_type; + enum lttng_rate_policy_status policy_status; + uint64_t policy_value = 0; + + policy_type = lttng_rate_policy_get_type(policy); + + switch (policy_type) { + case LTTNG_RATE_POLICY_TYPE_EVERY_N: + policy_status = lttng_rate_policy_every_n_get_interval( + policy, &policy_value); + if (policy_status != LTTNG_RATE_POLICY_STATUS_OK) { + ERR("Failed to get action rate policy interval"); + goto end; + } + if (policy_value > 1) { + /* The default is 1 so print only when it is a + * special case. + */ + _MSG(", rate policy: every %" PRIu64 + " occurrences", + policy_value); + } + break; + case LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N: + policy_status = lttng_rate_policy_once_after_n_get_threshold( + policy, &policy_value); + if (policy_status != LTTNG_RATE_POLICY_STATUS_OK) { + ERR("Failed to get action rate policy interval"); + goto end; + } + _MSG(", rate policy: once after %" PRIu64 + " occurrences", + policy_value); + break; + default: + abort(); + } + } + + MSG(""); + print_action_errors(trigger, action, action_path_indexes, + action_path_length); + +end: + return; +} + +static +void print_trigger_errors(const struct lttng_trigger *trigger) +{ + unsigned int i, count, printed_errors_count = 0; + enum lttng_error_code error_query_ret; + enum lttng_error_query_results_status results_status; + struct lttng_error_query_results *results = NULL; + enum lttng_trigger_status trigger_status; + const char *trigger_name; + uid_t trigger_uid; + struct lttng_error_query *query = + lttng_error_query_trigger_create(trigger); + + assert(query); + /* + * Anonymous triggers are not listed; this would be an internal error. + */ + trigger_status = lttng_trigger_get_name(trigger, &trigger_name); + assert(trigger_status == LTTNG_TRIGGER_STATUS_OK); + + trigger_status = lttng_trigger_get_owner_uid(trigger, &trigger_uid); + assert(trigger_status == LTTNG_TRIGGER_STATUS_OK); + + error_query_ret = lttng_error_query_execute( + query, lttng_session_daemon_command_endpoint, &results); + if (error_query_ret != LTTNG_OK) { + ERR("Failed to query errors of trigger '%s' (owner uid: %d): %s", + trigger_name, (int) trigger_uid, + lttng_strerror(-error_query_ret)); + goto end; + } + + results_status = lttng_error_query_results_get_count(results, &count); + assert(results_status == LTTNG_ERROR_QUERY_RESULTS_STATUS_OK); + + _MSG(" errors:"); + + for (i = 0; i < count; i++) { + const struct lttng_error_query_result *result; + enum lttng_error_query_result_status result_status; + const char *result_name; + const char *result_description; + uint64_t result_value; + + results_status = lttng_error_query_results_get_result( + results, &result, i); + assert(results_status == LTTNG_ERROR_QUERY_RESULTS_STATUS_OK); + + result_status = lttng_error_query_result_get_name( + result, &result_name); + assert(result_status == LTTNG_ERROR_QUERY_RESULT_STATUS_OK); + result_status = lttng_error_query_result_get_description( + result, &result_description); + assert(result_status == LTTNG_ERROR_QUERY_RESULT_STATUS_OK); + + if (lttng_error_query_result_get_type(result) == + LTTNG_ERROR_QUERY_RESULT_TYPE_COUNTER) { + result_status = lttng_error_query_result_counter_get_value( + result, &result_value); + assert(result_status == + LTTNG_ERROR_QUERY_RESULT_STATUS_OK); + if (result_value == 0) { + continue; + } + + MSG(""); + _MSG(" %s: %" PRIu64, result_name, + result_value); + printed_errors_count++; + } else { + _MSG(" Unknown error query result type for result '%s' (%s)", + result_name, result_description); + continue; + } + } + + if (printed_errors_count == 0) { + _MSG(" none"); + } + +end: + MSG(""); + lttng_error_query_destroy(query); + lttng_error_query_results_destroy(results); } static @@ -498,75 +1037,74 @@ void print_one_trigger(const struct lttng_trigger *trigger) enum lttng_action_type action_type; enum lttng_trigger_status trigger_status; const char *name; - enum lttng_trigger_firing_policy firing_policy_type; - uint64_t threshold; uid_t trigger_uid; + /* + * Anonymous triggers are not listed since they can't be specified nor + * referenced through the CLI. + */ trigger_status = lttng_trigger_get_name(trigger, &name); + if (trigger_status == LTTNG_TRIGGER_STATUS_UNSET) { + goto end; + } + assert(trigger_status == LTTNG_TRIGGER_STATUS_OK); trigger_status = lttng_trigger_get_owner_uid(trigger, &trigger_uid); assert(trigger_status == LTTNG_TRIGGER_STATUS_OK); - MSG("- id: %s", name); - MSG(" user id: %d", trigger_uid); - - trigger_status = lttng_trigger_get_firing_policy( - trigger, &firing_policy_type, &threshold); - if (trigger_status != LTTNG_TRIGGER_STATUS_OK) { - ERR("Failed to get trigger's policy."); - goto end; - } - - switch (firing_policy_type) { - case LTTNG_TRIGGER_FIRING_POLICY_EVERY_N: - if (threshold > 1) { - MSG(" firing policy: after every %" PRIu64 " occurences", threshold); - } - break; - case LTTNG_TRIGGER_FIRING_POLICY_ONCE_AFTER_N: - MSG(" firing policy: once after %" PRIu64 " occurences", threshold); - break; - default: - abort(); - } + MSG("- name: %s", name); + MSG(" owner uid: %d", trigger_uid); condition = lttng_trigger_get_const_condition(trigger); condition_type = lttng_condition_get_type(condition); MSG(" condition: %s", lttng_condition_type_str(condition_type)); switch (condition_type) { - case LTTNG_CONDITION_TYPE_ON_EVENT: - print_condition_on_event(condition); + case LTTNG_CONDITION_TYPE_SESSION_CONSUMED_SIZE: + print_condition_session_consumed_size(condition); break; - default: - MSG(" (condition type not handled in %s)", __func__); + case LTTNG_CONDITION_TYPE_BUFFER_USAGE_HIGH: + case LTTNG_CONDITION_TYPE_BUFFER_USAGE_LOW: + print_condition_buffer_usage(condition); + break; + case LTTNG_CONDITION_TYPE_SESSION_ROTATION_ONGOING: + case LTTNG_CONDITION_TYPE_SESSION_ROTATION_COMPLETED: + print_condition_session_rotation(condition); break; + case LTTNG_CONDITION_TYPE_EVENT_RULE_MATCHES: + print_condition_event_rule_matches(condition); + break; + default: + abort(); } action = lttng_trigger_get_const_action(trigger); action_type = lttng_action_get_type(action); - if (action_type == LTTNG_ACTION_TYPE_GROUP) { + if (action_type == LTTNG_ACTION_TYPE_LIST) { unsigned int count, i; enum lttng_action_status action_status; MSG(" actions:"); - action_status = lttng_action_group_get_count(action, &count); + action_status = lttng_action_list_get_count(action, &count); assert(action_status == LTTNG_ACTION_STATUS_OK); for (i = 0; i < count; i++) { + const uint64_t action_path_index = i; const struct lttng_action *subaction = - lttng_action_group_get_at_index( + lttng_action_list_get_at_index( action, i); _MSG(" "); - print_one_action(subaction); + print_one_action(trigger, subaction, &action_path_index, + 1); } } else { _MSG(" action:"); - print_one_action(action); + print_one_action(trigger, action, NULL, 0); } + print_trigger_errors(trigger); end: return; } @@ -579,6 +1117,7 @@ int compare_triggers_by_name(const void *a, const void *b) const char *name_a, *name_b; enum lttng_trigger_status trigger_status; + /* Anonymous triggers are not reachable here. */ trigger_status = lttng_trigger_get_name(trigger_a, &name_a); assert(trigger_status == LTTNG_TRIGGER_STATUS_OK); @@ -652,9 +1191,24 @@ int cmd_list_triggers(int argc, const char **argv) } for (i = 0; i < num_triggers; i++) { - const int add_ret = lttng_dynamic_pointer_array_add_pointer( - &sorted_triggers, - (void *) lttng_triggers_get_at_index(triggers, i)); + int add_ret; + const char *unused_name; + const struct lttng_trigger *trigger = + lttng_triggers_get_at_index(triggers, i); + + trigger_status = lttng_trigger_get_name(trigger, &unused_name); + switch (trigger_status) { + case LTTNG_TRIGGER_STATUS_OK: + break; + case LTTNG_TRIGGER_STATUS_UNSET: + /* Don't list anonymous triggers. */ + continue; + default: + abort(); + } + + add_ret = lttng_dynamic_pointer_array_add_pointer( + &sorted_triggers, (void *) trigger); if (add_ret) { ERR("Failed to allocate array of struct lttng_trigger *.");