Rename lttng_event_rule_tracepoint_(set,get)_pattern to lttng_event_rule_tracepoint_...
[lttng-tools.git] / src / bin / lttng / commands / list_triggers.c
index 3b806e7ea2bd98b15ae78595c84849c4794f321d..d33ed1fc4adc140a440ddb5b36cdf761b60ffb44 100644 (file)
 #include "common/mi-lttng.h"
 /* For lttng_condition_type_str(). */
 #include "lttng/condition/condition-internal.h"
-#include "lttng/condition/on-event.h"
-#include "lttng/condition/on-event-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_syscall_emission_site_str() */
+#include "lttng/event-rule/syscall-internal.h"
 #include "../loglevel.h"
 #include <lttng/lttng.h>
 
@@ -39,6 +41,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
@@ -82,7 +159,7 @@ void print_event_rule_tracepoint(const struct lttng_event_rule *event_rule)
        unsigned int exclusions_count;
        int i;
 
-       event_rule_status = lttng_event_rule_tracepoint_get_pattern(
+       event_rule_status = lttng_event_rule_tracepoint_get_name_pattern(
                        event_rule, &pattern);
        assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_OK);
 
@@ -312,14 +389,20 @@ 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_syscall_emission_site_type emission_site_type;
 
        assert(lttng_event_rule_get_type(event_rule) == LTTNG_EVENT_RULE_TYPE_SYSCALL);
 
+       emission_site_type =
+               lttng_event_rule_syscall_get_emission_site_type(event_rule);
+
        event_rule_status = lttng_event_rule_syscall_get_pattern(
                        event_rule, &pattern);
        assert(event_rule_status == LTTNG_EVENT_RULE_STATUS_OK);
 
-       _MSG("    rule: %s (type: syscall", pattern);
+       _MSG("    rule: %s (type: syscall:%s", pattern,
+                       lttng_event_rule_syscall_emission_site_str(
+                                       emission_site_type));
 
        event_rule_status = lttng_event_rule_syscall_get_filter(
                        event_rule, &filter);
@@ -423,21 +506,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);
 
@@ -446,7 +529,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("      - ");
@@ -456,9 +539,10 @@ 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)
+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;
@@ -467,12 +551,19 @@ void print_action_errors(const struct lttng_trigger *trigger,
        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);
+       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);
@@ -539,11 +630,14 @@ 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_trigger *trigger,
-               const struct lttng_action *action)
+               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;
@@ -551,7 +645,7 @@ void print_one_action(const struct lttng_trigger *trigger,
        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:
@@ -687,7 +781,7 @@ void print_one_action(const struct lttng_trigger *trigger,
                                /* The default is 1 so print only when it is a
                                 * special case.
                                 */
-                               _MSG(", rate policy: after every %" PRIu64
+                               _MSG(", rate policy: every %" PRIu64
                                     " occurrences",
                                                policy_value);
                        }
@@ -709,7 +803,8 @@ void print_one_action(const struct lttng_trigger *trigger,
        }
 
        MSG("");
-       print_action_errors(trigger, action);
+       print_action_errors(trigger, action, action_path_indexes,
+                       action_path_length);
 
 end:
        return;
@@ -729,7 +824,9 @@ void print_trigger_errors(const struct lttng_trigger *trigger)
                        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);
 
@@ -810,52 +907,74 @@ void print_one_trigger(const struct lttng_trigger *trigger)
        const char *name;
        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("- name: %s", name);
-       MSG("  user id: %d", trigger_uid);
+       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(trigger, subaction);
+                       print_one_action(trigger, subaction, &action_path_index,
+                                       1);
                }
        } else {
                _MSG(" action:");
-               print_one_action(trigger, action);
+               print_one_action(trigger, action, NULL, 0);
        }
 
        print_trigger_errors(trigger);
+end:
+       return;
 }
 
 static
@@ -866,6 +985,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);
 
@@ -939,9 +1059,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 *.");
This page took 0.028109 seconds and 5 git commands to generate.