Rename firing policy to rate policy
[lttng-tools.git] / src / bin / lttng / commands / list_triggers.c
index 024dc50bcceec1601a3573c532e3220306b367ba..d208f4ff68cb66b71fe4db70b36498ed19379991 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"
 /* For lttng_domain_type_str(). */
 #include "lttng/domain-internal.h"
+#include "../loglevel.h"
 
 #ifdef LTTNG_EMBED_HELP
 static const char help_msg[] =
@@ -35,6 +38,37 @@ struct argpar_opt_descr list_trigger_options[] = {
        ARGPAR_OPT_DESCR_SENTINEL,
 };
 
+/*
+ * 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
+ * values (a value can fall between two labels). In those cases, NULL is
+ * returned.
+ */
+static const char *get_pretty_loglevel_name(
+               enum lttng_domain_type domain, int loglevel)
+{
+       const char *name = NULL;
+
+       switch (domain) {
+       case LTTNG_DOMAIN_UST:
+               name = loglevel_value_to_name(loglevel);
+               break;
+       case LTTNG_DOMAIN_LOG4J:
+               name = loglevel_log4j_value_to_name(loglevel);
+               break;
+       case LTTNG_DOMAIN_JUL:
+               name = loglevel_jul_value_to_name(loglevel);
+               break;
+       case LTTNG_DOMAIN_PYTHON:
+               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)
 {
@@ -43,6 +77,7 @@ void print_event_rule_tracepoint(const struct lttng_event_rule *event_rule)
        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;
 
@@ -65,23 +100,38 @@ 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_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(
+                               domain_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);
        }
@@ -168,7 +218,7 @@ void print_event_rule_kernel_probe(const struct lttng_event_rule *event_rule)
 
        assert(lttng_event_rule_get_type(event_rule) == LTTNG_EVENT_RULE_TYPE_KERNEL_PROBE);
 
-       event_rule_status = lttng_event_rule_kernel_probe_get_name(event_rule, &name);
+       event_rule_status = lttng_event_rule_kernel_probe_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;
@@ -201,7 +251,8 @@ void print_event_rule_userspace_probe(const struct lttng_event_rule *event_rule)
 
        assert(lttng_event_rule_get_type(event_rule) == LTTNG_EVENT_RULE_TYPE_USERSPACE_PROBE);
 
-       event_rule_status = lttng_event_rule_userspace_probe_get_name(event_rule, &name);
+       event_rule_status = lttng_event_rule_userspace_probe_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;
@@ -367,6 +418,7 @@ 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);
@@ -379,6 +431,9 @@ 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:");
 
@@ -399,6 +454,7 @@ void print_one_action(const struct lttng_action *action)
 {
        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);
@@ -406,25 +462,53 @@ void print_one_action(const struct lttng_action *action)
 
        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:
        {
@@ -479,13 +563,61 @@ 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: after 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("");
+end:
+       return;
 }
 
 static
@@ -497,8 +629,6 @@ 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;
 
        trigger_status = lttng_trigger_get_name(trigger, &name);
@@ -510,26 +640,6 @@ void print_one_trigger(const struct lttng_trigger *trigger)
        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();
-       }
-
        condition = lttng_trigger_get_const_condition(trigger);
        condition_type = lttng_condition_get_type(condition);
        MSG("  condition: %s", lttng_condition_type_str(condition_type));
@@ -566,8 +676,6 @@ void print_one_trigger(const struct lttng_trigger *trigger)
                print_one_action(action);
        }
 
-end:
-       return;
 }
 
 static
This page took 0.026024 seconds and 4 git commands to generate.