lttng list-triggers: handle all condition types
[lttng-tools.git] / src / bin / lttng / commands / list_triggers.c
index 3321aacd3f9443cb22d7d078e786940ceaae66d2..bb118e56a217f48c70aeb78a309d28f8c84259ea 100644 (file)
@@ -19,6 +19,7 @@
 /* For lttng_domain_type_str(). */
 #include "lttng/domain-internal.h"
 #include "../loglevel.h"
+#include <lttng/lttng.h>
 
 #ifdef LTTNG_EMBED_HELP
 static const char help_msg[] =
@@ -38,6 +39,81 @@ 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 domains have discontinuous log level
@@ -265,7 +341,7 @@ void print_event_rule_userspace_probe(const struct lttng_event_rule *event_rule)
                goto end;
        }
 
-       _MSG("    rule: %s (type: userspace probe, location: ", name);
+       _MSG("    rule: %s (type: userspace probe, ", name);
 
        userspace_probe_location_type =
                        lttng_userspace_probe_location_get_type(location);
@@ -280,12 +356,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();
        }
@@ -418,7 +504,6 @@ void print_condition_on_event(const struct lttng_condition *condition)
        const struct lttng_event_rule *event_rule;
        enum lttng_condition_status condition_status;
        unsigned int cap_desc_count, i;
-       uint64_t error_count;
 
        condition_status =
                lttng_condition_on_event_get_rule(condition, &event_rule);
@@ -431,9 +516,6 @@ void print_condition_on_event(const struct lttng_condition *condition)
                                        condition, &cap_desc_count);
        assert(condition_status == LTTNG_CONDITION_STATUS_OK);
 
-       error_count = lttng_condition_on_event_get_error_count(condition);
-       MSG("    tracer notifications discarded: %" PRIu64, error_count);
-
        if (cap_desc_count > 0) {
                MSG("    captures:");
 
@@ -450,11 +532,97 @@ void print_condition_on_event(const struct lttng_condition *condition)
 }
 
 static
-void print_one_action(const struct lttng_action *action)
+void print_action_errors(const struct lttng_trigger *trigger,
+               const struct lttng_action *action)
+{
+       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 =
+                       lttng_error_query_action_create(trigger, action);
+
+       assert(query);
+
+       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
+void print_one_action(const struct lttng_trigger *trigger,
+               const struct lttng_action *action)
 {
        enum lttng_action_type action_type;
        enum lttng_action_status action_status;
-       const struct lttng_firing_policy *policy = NULL;
+       const struct lttng_rate_policy *policy = NULL;
        const char *value;
 
        action_type = lttng_action_get_type(action);
@@ -464,10 +632,10 @@ void print_one_action(const struct lttng_action *action)
        case LTTNG_ACTION_TYPE_NOTIFY:
                _MSG("notify");
 
-               action_status = lttng_action_notify_get_firing_policy(
+               action_status = lttng_action_notify_get_rate_policy(
                                action, &policy);
                if (action_status != LTTNG_ACTION_STATUS_OK) {
-                       ERR("Failed to retrieve firing policy.");
+                       ERR("Failed to retrieve rate policy.");
                        goto end;
                }
                break;
@@ -477,10 +645,10 @@ void print_one_action(const struct lttng_action *action)
                assert(action_status == LTTNG_ACTION_STATUS_OK);
                _MSG("start session `%s`", value);
 
-               action_status = lttng_action_start_session_get_firing_policy(
+               action_status = lttng_action_start_session_get_rate_policy(
                                action, &policy);
                if (action_status != LTTNG_ACTION_STATUS_OK) {
-                       ERR("Failed to retrieve firing policy.");
+                       ERR("Failed to retrieve rate policy.");
                        goto end;
                }
                break;
@@ -490,10 +658,10 @@ void print_one_action(const struct lttng_action *action)
                assert(action_status == LTTNG_ACTION_STATUS_OK);
                _MSG("stop session `%s`", value);
 
-               action_status = lttng_action_stop_session_get_firing_policy(
+               action_status = lttng_action_stop_session_get_rate_policy(
                                action, &policy);
                if (action_status != LTTNG_ACTION_STATUS_OK) {
-                       ERR("Failed to retrieve firing policy.");
+                       ERR("Failed to retrieve rate policy.");
                        goto end;
                }
                break;
@@ -503,10 +671,10 @@ void print_one_action(const struct lttng_action *action)
                assert(action_status == LTTNG_ACTION_STATUS_OK);
                _MSG("rotate session `%s`", value);
 
-               action_status = lttng_action_rotate_session_get_firing_policy(
+               action_status = lttng_action_rotate_session_get_rate_policy(
                                action, &policy);
                if (action_status != LTTNG_ACTION_STATUS_OK) {
-                       ERR("Failed to retrieve firing policy.");
+                       ERR("Failed to retrieve rate policy.");
                        goto end;
                }
                break;
@@ -563,10 +731,10 @@ void print_one_action(const struct lttng_action *action)
                        }
                }
 
-               action_status = lttng_action_snapshot_session_get_firing_policy(
+               action_status = lttng_action_snapshot_session_get_rate_policy(
                                action, &policy);
                if (action_status != LTTNG_ACTION_STATUS_OK) {
-                       ERR("Failed to retrieve firing policy.");
+                       ERR("Failed to retrieve rate policy.");
                        goto end;
                }
                break;
@@ -576,37 +744,37 @@ void print_one_action(const struct lttng_action *action)
        }
 
        if (policy) {
-               enum lttng_firing_policy_type policy_type;
-               enum lttng_firing_policy_status policy_status;
+               enum lttng_rate_policy_type policy_type;
+               enum lttng_rate_policy_status policy_status;
                uint64_t policy_value = 0;
 
-               policy_type = lttng_firing_policy_get_type(policy);
+               policy_type = lttng_rate_policy_get_type(policy);
 
                switch (policy_type) {
-               case LTTNG_FIRING_POLICY_TYPE_EVERY_N:
-                       policy_status = lttng_firing_policy_every_n_get_interval(
+               case LTTNG_RATE_POLICY_TYPE_EVERY_N:
+                       policy_status = lttng_rate_policy_every_n_get_interval(
                                        policy, &policy_value);
-                       if (policy_status != LTTNG_FIRING_POLICY_STATUS_OK) {
-                               ERR("Failed to get action firing policy interval");
+                       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(", firing policy: after every %" PRIu64
+                               _MSG(", rate policy: after every %" PRIu64
                                     " occurrences",
                                                policy_value);
                        }
                        break;
-               case LTTNG_FIRING_POLICY_TYPE_ONCE_AFTER_N:
-                       policy_status = lttng_firing_policy_once_after_n_get_threshold(
+               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_FIRING_POLICY_STATUS_OK) {
-                               ERR("Failed to get action firing policy interval");
+                       if (policy_status != LTTNG_RATE_POLICY_STATUS_OK) {
+                               ERR("Failed to get action rate policy interval");
                                goto end;
                        }
-                       _MSG(", firing policy: once after %" PRIu64
+                       _MSG(", rate policy: once after %" PRIu64
                             " occurrences",
                                        policy_value);
                        break;
@@ -616,10 +784,96 @@ void print_one_action(const struct lttng_action *action)
        }
 
        MSG("");
+       print_action_errors(trigger, action);
+
 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);
+
+       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
 void print_one_trigger(const struct lttng_trigger *trigger)
 {
@@ -637,19 +891,29 @@ void print_one_trigger(const struct lttng_trigger *trigger)
        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);
+       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_SESSION_CONSUMED_SIZE:
+               print_condition_session_consumed_size(condition);
+               break;
+       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_ON_EVENT:
                print_condition_on_event(condition);
                break;
        default:
-               MSG("  (condition type not handled in %s)", __func__);
-               break;
+               abort();
        }
 
        action = lttng_trigger_get_const_action(trigger);
@@ -669,13 +933,14 @@ void print_one_trigger(const struct lttng_trigger *trigger)
                                                        action, i);
 
                        _MSG("    ");
-                       print_one_action(subaction);
+                       print_one_action(trigger, subaction);
                }
        } else {
                _MSG(" action:");
-               print_one_action(action);
+               print_one_action(trigger, action);
        }
 
+       print_trigger_errors(trigger);
 }
 
 static
This page took 0.030709 seconds and 4 git commands to generate.