Rename firing policy to rate policy
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Thu, 15 Apr 2021 03:18:25 +0000 (23:18 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 18 Apr 2021 23:28:57 +0000 (19:28 -0400)
This is necessary since that now that the policy is moved to the actions
it is a bit weird to use the term "firing".

CLI change is done in a later patch.

Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Id6940a49cd0640a8fa7145dab5b805fcfa515f40

34 files changed:
.gitignore
configure.ac
include/Makefile.am
include/lttng/action/action-internal.h
include/lttng/action/notify-internal.h
include/lttng/action/notify.h
include/lttng/action/rate-policy-internal.h [new file with mode: 0644]
include/lttng/action/rate-policy.h [new file with mode: 0644]
include/lttng/action/rotate-session.h
include/lttng/action/snapshot-session.h
include/lttng/action/start-session.h
include/lttng/action/stop-session.h
include/lttng/lttng.h
src/bin/lttng/commands/add_trigger.c
src/bin/lttng/commands/list_triggers.c
src/common/Makefile.am
src/common/actions/action.c
src/common/actions/notify.c
src/common/actions/rate-policy.c [new file with mode: 0644]
src/common/actions/rotate-session.c
src/common/actions/snapshot-session.c
src/common/actions/start-session.c
src/common/actions/stop-session.c
tests/regression/Makefile.am
tests/regression/tools/trigger/Makefile.am
tests/regression/tools/trigger/firing-policy/Makefile.am [deleted file]
tests/regression/tools/trigger/firing-policy/test_ust_firing_policy [deleted file]
tests/regression/tools/trigger/rate-policy/Makefile.am [new file with mode: 0644]
tests/regression/tools/trigger/rate-policy/test_ust_rate_policy [new file with mode: 0755]
tests/regression/tools/trigger/test_list_triggers_cli
tests/unit/Makefile.am
tests/unit/test_action.c
tests/unit/test_firing_policy.c [deleted file]
tests/unit/test_rate_policy.c [new file with mode: 0644]

index fb4c020621d0cdf18a271164c5752ef2907748ef..4ee9dde72e1a167909c3190e7a36586a7603b4e7 100644 (file)
@@ -147,7 +147,7 @@ compile_commands.json
 /tests/unit/test_buffer_view
 /tests/unit/test_kernel_probe
 /tests/unit/test_event_expr_to_bytecode
-/tests/unit/test_firing_policy
+/tests/unit/test_rate_policy
 /tests/unit/test_log_level_rule
 /tests/utils/testapp/gen-ust-nevents-str/gen-ust-nevents-str
 /tests/utils/testapp/userspace-probe-elf-binary/userspace-probe-elf-binary
index 5a75c1efa532d71ff93b73569396d8468e37fb17..883e89f5c977affe7f59a160a7f92cb590671460 100644 (file)
@@ -1162,7 +1162,7 @@ AC_CONFIG_FILES([
        tests/regression/tools/relayd-grouping/Makefile
        tests/regression/tools/clear/Makefile
        tests/regression/tools/trigger/Makefile
-       tests/regression/tools/trigger/firing-policy/Makefile
+       tests/regression/tools/trigger/rate-policy/Makefile
        tests/regression/tools/trigger/start-stop/Makefile
        tests/regression/tools/trigger/utils/Makefile
        tests/regression/ust/Makefile
index a75f6c3d21a26b6e9515a8c226b952360200ab6d..94a421b0ab94147e69f19c2ccd9f1f9a737c8a00 100644 (file)
@@ -131,7 +131,7 @@ lttngactioninclude_HEADERS= \
        lttng/action/snapshot-session.h \
        lttng/action/start-session.h \
        lttng/action/stop-session.h \
-       lttng/action/firing-policy.h
+       lttng/action/rate-policy.h
 
 lttngconditioninclude_HEADERS= \
        lttng/condition/condition.h \
@@ -163,7 +163,7 @@ noinst_HEADERS = \
        lttng/action/snapshot-session-internal.h \
        lttng/action/start-session-internal.h \
        lttng/action/stop-session-internal.h \
-       lttng/action/firing-policy-internal.h \
+       lttng/action/rate-policy-internal.h \
        lttng/channel-internal.h \
        lttng/condition/buffer-usage-internal.h \
        lttng/condition/condition-internal.h \
index 1422a6dceed667050da6870928a6d02ecd0d2db2..12029e42f5d9ade44dde8f68eef6399eb2a48719 100644 (file)
@@ -18,7 +18,7 @@
 #include <sys/types.h>
 #include <urcu/ref.h>
 
-struct lttng_firing_policy;
+struct lttng_rate_policy;
 
 typedef bool (*action_validate_cb)(struct lttng_action *action);
 typedef void (*action_destroy_cb)(struct lttng_action *action);
@@ -29,7 +29,7 @@ typedef bool (*action_equal_cb)(const struct lttng_action *a,
 typedef ssize_t (*action_create_from_payload_cb)(
                struct lttng_payload_view *view,
                struct lttng_action **action);
-typedef const struct lttng_firing_policy *(*action_get_firing_policy_cb)(
+typedef const struct lttng_rate_policy *(*action_get_rate_policy_cb)(
                const struct lttng_action *action);
 
 struct lttng_action {
@@ -39,7 +39,7 @@ struct lttng_action {
        action_serialize_cb serialize;
        action_equal_cb equal;
        action_destroy_cb destroy;
-       action_get_firing_policy_cb get_firing_policy;
+       action_get_rate_policy_cb get_rate_policy;
 
        /* Internal use only. */
 
@@ -47,7 +47,7 @@ struct lttng_action {
        uint64_t execution_request_counter;
        /*
         * The number of time the action was actually executed.
-        * Action firing policy can impact on this number.
+        * Action rate policy can impact on this number.
         * */
        uint64_t execution_counter;
        /*
@@ -68,7 +68,7 @@ void lttng_action_init(struct lttng_action *action,
                action_serialize_cb serialize,
                action_equal_cb equal,
                action_destroy_cb destroy,
-               action_get_firing_policy_cb get_firing_policy);
+               action_get_rate_policy_cb get_rate_policy);
 
 LTTNG_HIDDEN
 bool lttng_action_validate(struct lttng_action *action);
index d727e6860119609eda2a370d6b0ccee6c1c88ec6..d15532a04a8aa21b0c0220f31e32e37d8a7bc10d 100644 (file)
@@ -13,7 +13,7 @@
 
 struct lttng_action_notify {
        struct lttng_action parent;
-       struct lttng_firing_policy *policy;
+       struct lttng_rate_policy *policy;
 };
 
 LTTNG_HIDDEN
index b41ba0378f625dd8fdf9bcaeb347dd568645510d..08574753ff4a14026e506fd1e98c6e58d34de000 100644 (file)
@@ -9,7 +9,7 @@
 #define LTTNG_ACTION_NOTIFY_H
 
 struct lttng_action;
-struct lttng_firing_policy;
+struct lttng_rate_policy;
 
 #ifdef __cplusplus
 extern "C" {
@@ -23,7 +23,7 @@ extern "C" {
  * must have subscribed to a condition equivalent to the one paired to this
  * notify action in a trigger.
  *
- * The default firing policy for a notify action is a "every 1" firing policy.
+ * The default rate policy for a notify action is a "every 1" rate policy.
  *
  * Returns a new action on success, NULL on failure. This action must be
  * destroyed using lttng_action_destroy().
@@ -31,25 +31,25 @@ extern "C" {
 extern struct lttng_action *lttng_action_notify_create(void);
 
 /*
- * Set the firing policy of a notify action.
+ * Set the rate policy of a notify action.
  *
  * Returns LTTNG_ACTION_STATUS_OK on success,
  * LTTNG_ACTION_STATUS_ERROR on internal error,
  * LTTNG_ACTION_STATUS_INVALID if invalid parameters are passed.
  */
-extern enum lttng_action_status lttng_action_notify_set_firing_policy(
+extern enum lttng_action_status lttng_action_notify_set_rate_policy(
                struct lttng_action *action,
-               const struct lttng_firing_policy *policy);
+               const struct lttng_rate_policy *policy);
 
 /*
- * Get the firing policy of a notify action.
+ * Get the rate policy of a notify action.
  *
  * Returns LTTNG_ACTION_STATUS_OK on success,
  * LTTNG_ACTION_STATUS_INVALID if invalid parameters are passed.
  */
-extern enum lttng_action_status lttng_action_notify_get_firing_policy(
+extern enum lttng_action_status lttng_action_notify_get_rate_policy(
                const struct lttng_action *action,
-               const struct lttng_firing_policy **policy);
+               const struct lttng_rate_policy **policy);
 
 #ifdef __cplusplus
 }
diff --git a/include/lttng/action/rate-policy-internal.h b/include/lttng/action/rate-policy-internal.h
new file mode 100644 (file)
index 0000000..03f6d97
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2021 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ */
+
+#ifndef LTTNG_RATE_POLICY_INTERNAL_H
+#define LTTNG_RATE_POLICY_INTERNAL_H
+
+#include <common/macros.h>
+#include <common/payload-view.h>
+#include <lttng/action/rate-policy.h>
+#include <stdbool.h>
+
+LTTNG_HIDDEN
+int lttng_rate_policy_serialize(struct lttng_rate_policy *rate_policy,
+               struct lttng_payload *buf);
+
+LTTNG_HIDDEN
+ssize_t lttng_rate_policy_create_from_payload(struct lttng_payload_view *view,
+               struct lttng_rate_policy **rate_policy);
+
+LTTNG_HIDDEN
+bool lttng_rate_policy_is_equal(const struct lttng_rate_policy *a,
+               const struct lttng_rate_policy *b);
+
+LTTNG_HIDDEN
+const char *lttng_rate_policy_type_string(
+               enum lttng_rate_policy_type rate_policy_type);
+
+LTTNG_HIDDEN
+struct lttng_rate_policy *lttng_rate_policy_copy(
+               const struct lttng_rate_policy *source);
+
+LTTNG_HIDDEN
+bool lttng_rate_policy_should_execute(
+               const struct lttng_rate_policy *policy, uint64_t counter);
+
+#endif /* LTTNG_RATE_POLICY */
diff --git a/include/lttng/action/rate-policy.h b/include/lttng/action/rate-policy.h
new file mode 100644 (file)
index 0000000..a3a288a
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2021 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ */
+
+#ifndef LTTNG_RATE_POLICY_H
+#define LTTNG_RATE_POLICY_H
+
+#include <inttypes.h>
+#include <sys/types.h>
+
+struct lttng_rate_policy;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+enum lttng_rate_policy_status {
+       LTTNG_RATE_POLICY_STATUS_OK = 0,
+       LTTNG_RATE_POLICY_STATUS_ERROR = -1,
+       LTTNG_RATE_POLICY_STATUS_UNKNOWN = -2,
+       LTTNG_RATE_POLICY_STATUS_INVALID = -3,
+       LTTNG_RATE_POLICY_STATUS_UNSET = -4,
+       LTTNG_RATE_POLICY_STATUS_UNSUPPORTED = -5,
+       LTTNG_RATE_POLICY_STATUS_PERMISSION_DENIED = -6,
+};
+
+enum lttng_rate_policy_type {
+       LTTNG_RATE_POLICY_TYPE_UNKNOWN = -1,
+       LTTNG_RATE_POLICY_TYPE_EVERY_N = 0,
+       LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N = 1,
+};
+
+/*
+ * Get the type of a rate policy.
+ */
+extern enum lttng_rate_policy_type lttng_rate_policy_get_type(
+               const struct lttng_rate_policy *policy);
+
+/*
+ * Create a rate_policy of type `every n`.
+ *
+ * A `every n` rate policy will carry the execution of an action only when the
+ * action was ready for execution for a multiple of N.
+ *
+ * Returns a rate_policy object on success, NULL on error.
+ * rate_policy objects must be destroyed using the lttng_rate_policy_destroy()
+ * function.
+ */
+extern struct lttng_rate_policy *lttng_rate_policy_every_n_create(
+               uint64_t interval);
+
+/*
+ * Get the interval of a every N rate policy.
+ *
+ * Returns LTTNG_RATE_POLICY_STATUS_OK and a sets the interval.
+ * on success, LTTNG_RATE_FIRING_POLICY_STATUS_INVALID if an invalid
+ * parameter is passed.
+ */
+extern enum lttng_rate_policy_status lttng_rate_policy_every_n_get_interval(
+               const struct lttng_rate_policy *policy, uint64_t *interval);
+
+/*
+ * Create a rate_policy of type `once after N`.
+ *
+ * A `once after N` rate policy will carry the execution of an action only when
+ * the action was ready for execution at least N times and will only be carried
+ * one time.
+ *
+ * Returns a rate_policy object on success, NULL on error.
+ * rate_policy objects must be destroyed using the lttng_rate_policy_destroy()
+ * function.
+ */
+extern struct lttng_rate_policy *lttng_rate_policy_once_after_n_create(
+               uint64_t threshold);
+
+/*
+ * Get the threshold of a once after N rate policy.
+ *
+ * Returns LTTNG_RATE_POLICY_STATUS_OK and sets the threshold.
+ * on success, LTTNG_RATE_POLICY_STATUS_INVALID if an invalid
+ * parameter is passed.
+ */
+extern enum lttng_rate_policy_status
+lttng_rate_policy_once_after_n_get_threshold(
+               const struct lttng_rate_policy *policy, uint64_t *threshold);
+
+/*
+ * Destroy (frees) a rate policy object.
+ */
+extern void lttng_rate_policy_destroy(struct lttng_rate_policy *policy);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LTTNG_rate_policy_H */
index b05cd8426c581cbc1d1616bbfb3f7b0b8844ab04..7fbcce98c5f4deca0bf0b9fefebc64b128aa6da0 100644 (file)
@@ -9,7 +9,7 @@
 #define LTTNG_ACTION_ROTATE_SESSION_H
 
 struct lttng_action;
-struct lttng_firing_policy;
+struct lttng_rate_policy;
 
 #ifdef __cplusplus
 extern "C" {
@@ -42,25 +42,25 @@ extern enum lttng_action_status lttng_action_rotate_session_get_session_name(
                const struct lttng_action *action, const char **session_name);
 
 /*
- * Set the firing policy of a rotate session action.
+ * Set the rate policy of a rotate session action.
  *
  * Returns LTTNG_ACTION_STATUS_OK on success,
  * LTTNG_ACTION_STATUS_ERROR on internal error,
  * LTTNG_ACTION_STATUS_INVALID if invalid parameters are passed.
  */
-extern enum lttng_action_status lttng_action_rotate_session_set_firing_policy(
+extern enum lttng_action_status lttng_action_rotate_session_set_rate_policy(
                struct lttng_action *action,
-               const struct lttng_firing_policy *policy);
+               const struct lttng_rate_policy *policy);
 
 /*
- * Get the firing policy of a rotate session action.
+ * Get the rate policy of a rotate session action.
  *
  * Returns LTTNG_ACTION_STATUS_OK on success,
  * LTTNG_ACTION_STATUS_INVALID if invalid parameters are passed.
  */
-extern enum lttng_action_status lttng_action_rotate_session_get_firing_policy(
+extern enum lttng_action_status lttng_action_rotate_session_get_rate_policy(
                const struct lttng_action *action,
-               const struct lttng_firing_policy **policy);
+               const struct lttng_rate_policy **policy);
 
 #ifdef __cplusplus
 }
index 71af0563afbc2a6c83e32236c51f03f68d1f0ce3..faa9b9fab8d8f56082e59946145647f0d047b530 100644 (file)
@@ -14,7 +14,7 @@ extern "C" {
 
 struct lttng_action;
 struct lttng_snapshot_output;
-struct lttng_firing_policy;
+struct lttng_rate_policy;
 
 /*
  * Create a newly allocated snapshot-session action object.
@@ -62,25 +62,25 @@ extern enum lttng_action_status lttng_action_snapshot_session_get_output(
                const struct lttng_snapshot_output **output);
 
 /*
- * Set the firing policy of a snapshot session action.
+ * Set the rate policy of a snapshot session action.
  *
  * Returns LTTNG_ACTION_STATUS_OK on success,
  * LTTNG_ACTION_STATUS_ERROR on internal error,
  * LTTNG_ACTION_STATUS_INVALID if invalid parameters are passed.
  */
-extern enum lttng_action_status lttng_action_snapshot_session_set_firing_policy(
+extern enum lttng_action_status lttng_action_snapshot_session_set_rate_policy(
                struct lttng_action *action,
-               const struct lttng_firing_policy *policy);
+               const struct lttng_rate_policy *policy);
 
 /*
- * Get the firing policy of a snapshot session action.
+ * Get the rate policy of a snapshot session action.
  *
  * Returns LTTNG_ACTION_STATUS_OK on success,
  * LTTNG_ACTION_STATUS_INVALID if invalid parameters are passed.
  */
-extern enum lttng_action_status lttng_action_snapshot_session_get_firing_policy(
+extern enum lttng_action_status lttng_action_snapshot_session_get_rate_policy(
                const struct lttng_action *action,
-               const struct lttng_firing_policy **policy);
+               const struct lttng_rate_policy **policy);
 
 #ifdef __cplusplus
 }
index dc54219ae50945bacb49485fc592d9ee4a0708b1..c63a7d278bd6a93a8d28421de5bd17614056449c 100644 (file)
@@ -9,7 +9,7 @@
 #define LTTNG_ACTION_START_SESSION_H
 
 struct lttng_action;
-struct lttng_firing_policy;
+struct lttng_rate_policy;
 
 #ifdef __cplusplus
 extern "C" {
@@ -42,25 +42,25 @@ extern enum lttng_action_status lttng_action_start_session_get_session_name(
                const struct lttng_action *action, const char **session_name);
 
 /*
- * Set the firing policy of a start session action.
+ * Set the rate policy of a start session action.
  *
  * Returns LTTNG_ACTION_STATUS_OK on success,
  * LTTNG_ACTION_STATUS_ERROR on internal error,
  * LTTNG_ACTION_STATUS_INVALID if invalid parameters are passed.
  */
-extern enum lttng_action_status lttng_action_start_session_set_firing_policy(
+extern enum lttng_action_status lttng_action_start_session_set_rate_policy(
                struct lttng_action *action,
-               const struct lttng_firing_policy *policy);
+               const struct lttng_rate_policy *policy);
 
 /*
- * Get the firing policy of a start session action.
+ * Get the rate policy of a start session action.
  *
  * Returns LTTNG_ACTION_STATUS_OK on success,
  * LTTNG_ACTION_STATUS_INVALID if invalid parameters are passed.
  */
-extern enum lttng_action_status lttng_action_start_session_get_firing_policy(
+extern enum lttng_action_status lttng_action_start_session_get_rate_policy(
                const struct lttng_action *action,
-               const struct lttng_firing_policy **policy);
+               const struct lttng_rate_policy **policy);
 
 #ifdef __cplusplus
 }
index f4f598f2d7c5138dab60341c94ac08384df80a3b..dbe6819e67577e6dc8105b51a00771058b1440b4 100644 (file)
@@ -9,7 +9,7 @@
 #define LTTNG_ACTION_STOP_SESSION_H
 
 struct lttng_action;
-struct lttng_firing_policy;
+struct lttng_rate_policy;
 
 #ifdef __cplusplus
 extern "C" {
@@ -42,25 +42,25 @@ extern enum lttng_action_status lttng_action_stop_session_get_session_name(
                const struct lttng_action *action, const char **session_name);
 
 /*
- * Set the firing policy of a stop session action.
+ * Set the rate policy of a stop session action.
  *
  * Returns LTTNG_ACTION_STATUS_OK on success,
  * LTTNG_ACTION_STATUS_ERROR on internal error,
  * LTTNG_ACTION_STATUS_INVALID if invalid parameters are passed.
  */
-extern enum lttng_action_status lttng_action_stop_session_set_firing_policy(
+extern enum lttng_action_status lttng_action_stop_session_set_rate_policy(
                struct lttng_action *action,
-               const struct lttng_firing_policy *policy);
+               const struct lttng_rate_policy *policy);
 
 /*
- * Get the firing policy of a stop session action.
+ * Get the rate policy of a stop session action.
  *
  * Returns LTTNG_ACTION_STATUS_OK on success,
  * LTTNG_ACTION_STATUS_INVALID if invalid parameters are passed.
  */
-extern enum lttng_action_status lttng_action_stop_session_get_firing_policy(
+extern enum lttng_action_status lttng_action_stop_session_get_rate_policy(
                const struct lttng_action *action,
-               const struct lttng_firing_policy **policy);
+               const struct lttng_rate_policy **policy);
 
 #ifdef __cplusplus
 }
index 9d15921770e8afd6b2cf9d5422f89d951e34049f..345d2b707aac224ef8c83270a7f4f0aa38fa8676 100644 (file)
@@ -17,9 +17,9 @@
 
 /* Include every LTTng ABI/API available. */
 #include <lttng/action/action.h>
-#include <lttng/action/firing-policy.h>
 #include <lttng/action/group.h>
 #include <lttng/action/notify.h>
+#include <lttng/action/rate-policy.h>
 #include <lttng/action/rotate-session.h>
 #include <lttng/action/snapshot-session.h>
 #include <lttng/action/start-session.h>
index 17e06445b49ca9f8d6b9a935beecd77c38ca05a8..27a666c5da97dba8c8ab900d336ef7229f5f0184 100644 (file)
@@ -1351,7 +1351,7 @@ struct lttng_action *handle_action_notify(int *argc, const char ***argv)
        char *error = NULL;
        char *fire_once_after_str = NULL;
        char *fire_every_str = NULL;
-       struct lttng_firing_policy *policy = NULL;
+       struct lttng_rate_policy *policy = NULL;
 
        state = argpar_state_create(*argc, *argv, notify_action_opt_descrs);
        if (!state) {
@@ -1444,7 +1444,7 @@ struct lttng_action *handle_action_notify(int *argc, const char ***argv)
                        goto error;
                }
 
-               policy = lttng_firing_policy_once_after_n_create(threshold);
+               policy = lttng_rate_policy_once_after_n_create(threshold);
                if (!policy) {
                        ERR("Failed to create policy once after `%s`.",
                                        fire_once_after_str);
@@ -1465,7 +1465,7 @@ struct lttng_action *handle_action_notify(int *argc, const char ***argv)
                        goto error;
                }
 
-               policy = lttng_firing_policy_every_n_create(interval);
+               policy = lttng_rate_policy_every_n_create(interval);
                if (!policy) {
                        ERR("Failed to create policy every `%s`.",
                                        fire_every_str);
@@ -1481,9 +1481,9 @@ struct lttng_action *handle_action_notify(int *argc, const char ***argv)
 
        if (policy) {
                enum lttng_action_status status;
-               status = lttng_action_notify_set_firing_policy(action, policy);
+               status = lttng_action_notify_set_rate_policy(action, policy);
                if (status != LTTNG_ACTION_STATUS_OK) {
-                       ERR("Failed to set firing policy");
+                       ERR("Failed to set rate policy");
                        goto error;
                }
        }
@@ -1497,7 +1497,7 @@ error:
 end:
        free(fire_once_after_str);
        free(fire_every_str);
-       lttng_firing_policy_destroy(policy);
+       lttng_rate_policy_destroy(policy);
        argpar_state_destroy(state);
        argpar_item_destroy(item);
        return action;
@@ -1505,7 +1505,7 @@ end:
 
 /*
  * Generic handler for a kind of action that takes a session name and an
- * optional firing policy.
+ * optional rate policy.
  */
 
 static struct lttng_action *handle_action_simple_session_with_policy(int *argc,
@@ -1513,9 +1513,9 @@ static struct lttng_action *handle_action_simple_session_with_policy(int *argc,
                struct lttng_action *(*create_action_cb)(void),
                enum lttng_action_status (*set_session_name_cb)(
                                struct lttng_action *, const char *),
-               enum lttng_action_status (*set_firing_policy_cb)(
+               enum lttng_action_status (*set_rate_policy_cb)(
                                struct lttng_action *,
-                               const struct lttng_firing_policy *),
+                               const struct lttng_rate_policy *),
                const char *action_name)
 {
        struct lttng_action *action = NULL;
@@ -1526,18 +1526,18 @@ static struct lttng_action *handle_action_simple_session_with_policy(int *argc,
        char *fire_every_str = NULL;
        char *error = NULL;
        enum lttng_action_status action_status;
-       struct lttng_firing_policy *policy = NULL;
+       struct lttng_rate_policy *policy = NULL;
 
        assert(set_session_name_cb);
-       assert(set_firing_policy_cb);
+       assert(set_rate_policy_cb);
 
-       const struct argpar_opt_descr firing_policy_opt_descrs[] = {
+       const struct argpar_opt_descr rate_policy_opt_descrs[] = {
                { OPT_FIRE_ONCE_AFTER, '\0', "fire-once-after", true },
                { OPT_FIRE_EVERY, '\0', "fire-every", true },
                ARGPAR_OPT_DESCR_SENTINEL
        };
        
-       state = argpar_state_create(*argc, *argv, firing_policy_opt_descrs);
+       state = argpar_state_create(*argc, *argv, rate_policy_opt_descrs);
        if (!state) {
                ERR("Failed to allocate an argpar state.");
                goto error;
@@ -1633,7 +1633,7 @@ static struct lttng_action *handle_action_simple_session_with_policy(int *argc,
                        goto error;
                }
 
-               policy = lttng_firing_policy_once_after_n_create(threshold);
+               policy = lttng_rate_policy_once_after_n_create(threshold);
                if (!policy) {
                        ERR("Failed to create policy once after `%s`.",
                                        fire_once_after_str);
@@ -1654,7 +1654,7 @@ static struct lttng_action *handle_action_simple_session_with_policy(int *argc,
                        goto error;
                }
 
-               policy = lttng_firing_policy_every_n_create(interval);
+               policy = lttng_rate_policy_every_n_create(interval);
                if (!policy) {
                        ERR("Failed to create policy every `%s`.",
                                        fire_every_str);
@@ -1676,9 +1676,9 @@ static struct lttng_action *handle_action_simple_session_with_policy(int *argc,
        }
 
        if (policy) {
-               action_status = set_firing_policy_cb(action, policy);
+               action_status = set_rate_policy_cb(action, policy);
                if (action_status != LTTNG_ACTION_STATUS_OK) {
-                       ERR("Failed to set firing policy");
+                       ERR("Failed to set rate policy");
                        goto error;
                }
        }
@@ -1690,7 +1690,7 @@ error:
        action = NULL;
        argpar_item_destroy(item);
 end:
-       lttng_firing_policy_destroy(policy);
+       lttng_rate_policy_destroy(policy);
        free(error);
        argpar_state_destroy(state);
        return action;
@@ -1703,7 +1703,7 @@ struct lttng_action *handle_action_start_session(int *argc,
        return handle_action_simple_session_with_policy(argc, argv,
                        lttng_action_start_session_create,
                        lttng_action_start_session_set_session_name,
-                       lttng_action_start_session_set_firing_policy, "start");
+                       lttng_action_start_session_set_rate_policy, "start");
 }
 
 static
@@ -1713,7 +1713,7 @@ struct lttng_action *handle_action_stop_session(int *argc,
        return handle_action_simple_session_with_policy(argc, argv,
                        lttng_action_stop_session_create,
                        lttng_action_stop_session_set_session_name,
-                       lttng_action_stop_session_set_firing_policy, "stop");
+                       lttng_action_stop_session_set_rate_policy, "stop");
 }
 
 static
@@ -1723,7 +1723,7 @@ struct lttng_action *handle_action_rotate_session(int *argc,
        return handle_action_simple_session_with_policy(argc, argv,
                lttng_action_rotate_session_create,
                lttng_action_rotate_session_set_session_name,
-               lttng_action_rotate_session_set_firing_policy,
+               lttng_action_rotate_session_set_rate_policy,
                "rotate");
 }
 
@@ -1758,7 +1758,7 @@ struct lttng_action *handle_action_snapshot_session(int *argc,
        char *fire_every_str = NULL;
        enum lttng_action_status action_status;
        struct lttng_snapshot_output *snapshot_output = NULL;
-       struct lttng_firing_policy *policy = NULL;
+       struct lttng_rate_policy *policy = NULL;
        int ret;
        unsigned int locations_specified = 0;
 
@@ -1910,7 +1910,7 @@ struct lttng_action *handle_action_snapshot_session(int *argc,
                }
        }
 
-       /* Any firing policy ? */
+       /* Any rate policy ? */
        if (fire_once_after_str && fire_every_str) {
                ERR("--fire-once and --fire-every are mutually exclusive.");
                goto error;
@@ -1931,7 +1931,7 @@ struct lttng_action *handle_action_snapshot_session(int *argc,
                        goto error;
                }
 
-               policy = lttng_firing_policy_once_after_n_create(threshold);
+               policy = lttng_rate_policy_once_after_n_create(threshold);
                if (!policy) {
                        ERR("Failed to create policy once after `%s`.",
                                        fire_once_after_str);
@@ -1952,7 +1952,7 @@ struct lttng_action *handle_action_snapshot_session(int *argc,
                        goto error;
                }
 
-               policy = lttng_firing_policy_every_n_create(interval);
+               policy = lttng_rate_policy_every_n_create(interval);
                if (!policy) {
                        ERR("Failed to create policy every `%s`.",
                                        fire_every_str);
@@ -2083,10 +2083,10 @@ struct lttng_action *handle_action_snapshot_session(int *argc,
 
        if (policy) {
                enum lttng_action_status status;
-               status = lttng_action_snapshot_session_set_firing_policy(
+               status = lttng_action_snapshot_session_set_rate_policy(
                                action, policy);
                if (status != LTTNG_ACTION_STATUS_OK) {
-                       ERR("Failed to set firing policy");
+                       ERR("Failed to set rate policy");
                        goto error;
                }
        }
@@ -2105,7 +2105,7 @@ end:
        free(data_url_arg);
        free(snapshot_output);
        free(max_size_arg);
-       lttng_firing_policy_destroy(policy);
+       lttng_rate_policy_destroy(policy);
        argpar_state_destroy(state);
        argpar_item_destroy(item);
        return action;
index 3321aacd3f9443cb22d7d078e786940ceaae66d2..d208f4ff68cb66b71fe4db70b36498ed19379991 100644 (file)
@@ -454,7 +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_firing_policy *policy = NULL;
+       const struct lttng_rate_policy *policy = NULL;
        const char *value;
 
        action_type = lttng_action_get_type(action);
@@ -464,10 +464,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 +477,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 +490,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 +503,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 +563,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 +576,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;
index f564d383522475239214146a03655bcf403b41a2..b90b8854c64f6a9cf80f488e9943b7b336d875d1 100644 (file)
@@ -41,7 +41,7 @@ libcommon_la_SOURCES = \
        actions/snapshot-session.c \
        actions/start-session.c \
        actions/stop-session.c \
-       actions/firing-policy.c \
+       actions/rate-policy.c \
        buffer-view.h buffer-view.c \
        common.h \
        conditions/buffer-usage.c \
index 07eefeeb050ab14877abcf2d55ac4b93e78d91b1..64864a6273ae1fabac87cd8e6fd813831335f9d0 100644 (file)
@@ -8,9 +8,9 @@
 #include <assert.h>
 #include <common/error.h>
 #include <lttng/action/action-internal.h>
-#include <lttng/action/firing-policy-internal.h>
 #include <lttng/action/group-internal.h>
 #include <lttng/action/notify-internal.h>
+#include <lttng/action/rate-policy-internal.h>
 #include <lttng/action/rotate-session-internal.h>
 #include <lttng/action/snapshot-session-internal.h>
 #include <lttng/action/start-session-internal.h>
@@ -51,7 +51,7 @@ void lttng_action_init(struct lttng_action *action,
                action_serialize_cb serialize,
                action_equal_cb equal,
                action_destroy_cb destroy,
-               action_get_firing_policy_cb get_firing_policy)
+               action_get_rate_policy_cb get_rate_policy)
 {
        urcu_ref_init(&action->ref);
        action->type = type;
@@ -59,7 +59,7 @@ void lttng_action_init(struct lttng_action *action,
        action->serialize = serialize;
        action->equal = equal;
        action->destroy = destroy;
-       action->get_firing_policy = get_firing_policy;
+       action->get_rate_policy = get_rate_policy;
 
        action->execution_request_counter = 0;
        action->execution_counter = 0;
@@ -271,21 +271,21 @@ void lttng_action_increase_execution_failure_count(struct lttng_action *action)
 LTTNG_HIDDEN
 bool lttng_action_should_execute(const struct lttng_action *action)
 {
-       const struct lttng_firing_policy *policy = NULL;
+       const struct lttng_rate_policy *policy = NULL;
        bool execute = false;
 
-       if (action->get_firing_policy == NULL) {
+       if (action->get_rate_policy == NULL) {
                execute = true;
                goto end;
        }
 
-       policy = action->get_firing_policy(action);
+       policy = action->get_rate_policy(action);
        if (policy == NULL) {
                execute = true;
                goto end;
        }
 
-       execute = lttng_firing_policy_should_execute(
+       execute = lttng_rate_policy_should_execute(
                        policy, action->execution_request_counter);
 end:
        return execute;
index 3ce1b00f901f332ecd58a7ee4f8db77c2b95329e..0ab88be44fe6397ab7351dc058a3057dfef2c8a2 100644 (file)
@@ -9,8 +9,8 @@
 #include <common/error.h>
 #include <common/macros.h>
 #include <lttng/action/action-internal.h>
-#include <lttng/action/firing-policy-internal.h>
 #include <lttng/action/notify-internal.h>
+#include <lttng/action/rate-policy-internal.h>
 
 #define IS_NOTIFY_ACTION(action) \
        (lttng_action_get_type(action) == LTTNG_ACTION_TYPE_NOTIFY)
@@ -36,7 +36,7 @@ void lttng_action_notify_destroy(struct lttng_action *action)
 {
        struct lttng_action_notify *notify_action;
        notify_action = action_notify_from_action(action);
-       lttng_firing_policy_destroy(notify_action->policy);
+       lttng_rate_policy_destroy(notify_action->policy);
        free(notify_action);
 }
 
@@ -55,8 +55,8 @@ int lttng_action_notify_serialize(struct lttng_action *action,
        DBG("Serializing notify action");
 
        notify_action = action_notify_from_action(action);
-       DBG("Serializing notify action firing policy");
-       ret = lttng_firing_policy_serialize(notify_action->policy, payload);
+       DBG("Serializing notify action rate policy");
+       ret = lttng_rate_policy_serialize(notify_action->policy, payload);
 
 end:
        return ret;
@@ -70,12 +70,11 @@ bool lttng_action_notify_is_equal(const struct lttng_action *a,
 
        _a = action_notify_from_action_const(a);
        _b = action_notify_from_action_const(b);
-       return lttng_firing_policy_is_equal(_a->policy, _b->policy);
+       return lttng_rate_policy_is_equal(_a->policy, _b->policy);
 }
 
-static const struct lttng_firing_policy *
-lttng_action_notify_internal_get_firing_policy(
-               const struct lttng_action *action)
+static const struct lttng_rate_policy *
+lttng_action_notify_internal_get_rate_policy(const struct lttng_action *action)
 {
        const struct lttng_action_notify *_action;
        _action = action_notify_from_action_const(action);
@@ -85,7 +84,7 @@ lttng_action_notify_internal_get_firing_policy(
 
 struct lttng_action *lttng_action_notify_create(void)
 {
-       struct lttng_firing_policy *policy = NULL;
+       struct lttng_rate_policy *policy = NULL;
        struct lttng_action_notify *notify = NULL;
        struct lttng_action *action = NULL;
 
@@ -95,7 +94,7 @@ struct lttng_action *lttng_action_notify_create(void)
        }
 
        /* Default policy. */
-       policy = lttng_firing_policy_every_n_create(1);
+       policy = lttng_rate_policy_every_n_create(1);
        if (!policy) {
                goto end;
        }
@@ -104,7 +103,7 @@ struct lttng_action *lttng_action_notify_create(void)
                        lttng_action_notify_serialize,
                        lttng_action_notify_is_equal,
                        lttng_action_notify_destroy,
-                       lttng_action_notify_internal_get_firing_policy);
+                       lttng_action_notify_internal_get_rate_policy);
 
        notify->policy = policy;
        policy = NULL;
@@ -114,7 +113,7 @@ struct lttng_action *lttng_action_notify_create(void)
 
 end:
        free(notify);
-       lttng_firing_policy_destroy(policy);
+       lttng_rate_policy_destroy(policy);
        return action;
 }
 
@@ -124,12 +123,12 @@ ssize_t lttng_action_notify_create_from_payload(
 {
        enum lttng_action_status status;
        ssize_t consumed_length;
-       struct lttng_firing_policy *firing_policy = NULL;
+       struct lttng_rate_policy *rate_policy = NULL;
        struct lttng_action *_action = NULL;
 
-       consumed_length = lttng_firing_policy_create_from_payload(
-                       view, &firing_policy);
-       if (!firing_policy) {
+       consumed_length = lttng_rate_policy_create_from_payload(
+                       view, &rate_policy);
+       if (!rate_policy) {
                consumed_length = -1;
                goto end;
        }
@@ -140,7 +139,7 @@ ssize_t lttng_action_notify_create_from_payload(
                goto end;
        }
 
-       status = lttng_action_notify_set_firing_policy(_action, firing_policy);
+       status = lttng_action_notify_set_rate_policy(_action, rate_policy);
        if (status != LTTNG_ACTION_STATUS_OK) {
                consumed_length = -1;
                goto end;
@@ -150,25 +149,25 @@ ssize_t lttng_action_notify_create_from_payload(
        _action = NULL;
 
 end:
-       lttng_firing_policy_destroy(firing_policy);
+       lttng_rate_policy_destroy(rate_policy);
        lttng_action_destroy(_action);
        return consumed_length;
 }
 
-enum lttng_action_status lttng_action_notify_set_firing_policy(
+enum lttng_action_status lttng_action_notify_set_rate_policy(
                struct lttng_action *action,
-               const struct lttng_firing_policy *policy)
+               const struct lttng_rate_policy *policy)
 {
        enum lttng_action_status status;
        struct lttng_action_notify *notify_action;
-       struct lttng_firing_policy *copy = NULL;
+       struct lttng_rate_policy *copy = NULL;
 
        if (!action || !policy || !IS_NOTIFY_ACTION(action)) {
                status = LTTNG_ACTION_STATUS_INVALID;
                goto end;
        }
 
-       copy = lttng_firing_policy_copy(policy);
+       copy = lttng_rate_policy_copy(policy);
        if (!copy) {
                status = LTTNG_ACTION_STATUS_ERROR;
                goto end;
@@ -176,8 +175,8 @@ enum lttng_action_status lttng_action_notify_set_firing_policy(
 
        notify_action = action_notify_from_action(action);
 
-       /* Free the previous firing policy .*/
-       lttng_firing_policy_destroy(notify_action->policy);
+       /* Free the previous rate policy .*/
+       lttng_rate_policy_destroy(notify_action->policy);
 
        /* Assign the policy. */
        notify_action->policy = copy;
@@ -185,13 +184,13 @@ enum lttng_action_status lttng_action_notify_set_firing_policy(
        copy = NULL;
 
 end:
-       lttng_firing_policy_destroy(copy);
+       lttng_rate_policy_destroy(copy);
        return status;
 }
 
-enum lttng_action_status lttng_action_notify_get_firing_policy(
+enum lttng_action_status lttng_action_notify_get_rate_policy(
                const struct lttng_action *action,
-               const struct lttng_firing_policy **policy)
+               const struct lttng_rate_policy **policy)
 {
        enum lttng_action_status status;
        const struct lttng_action_notify *notify_action;
diff --git a/src/common/actions/rate-policy.c b/src/common/actions/rate-policy.c
new file mode 100644 (file)
index 0000000..244fb70
--- /dev/null
@@ -0,0 +1,683 @@
+/*
+ * Copyright (C) 2021 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ */
+
+#include <assert.h>
+#include <common/buffer-view.h>
+#include <common/dynamic-buffer.h>
+#include <common/error.h>
+#include <common/macros.h>
+#include <common/payload-view.h>
+#include <common/payload.h>
+#include <limits.h>
+#include <lttng/action/rate-policy-internal.h>
+#include <lttng/action/rate-policy.h>
+#include <stdbool.h>
+#include <sys/types.h>
+
+#define IS_EVERY_N_RATE_POLICY(policy) \
+       (lttng_rate_policy_get_type(policy) == LTTNG_RATE_POLICY_TYPE_EVERY_N)
+
+#define IS_ONCE_AFTER_N_RATE_POLICY(policy)    \
+       (lttng_rate_policy_get_type(policy) == \
+                       LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N)
+
+typedef void (*rate_policy_destroy_cb)(struct lttng_rate_policy *rate_policy);
+typedef int (*rate_policy_serialize_cb)(struct lttng_rate_policy *rate_policy,
+               struct lttng_payload *payload);
+typedef bool (*rate_policy_equal_cb)(const struct lttng_rate_policy *a,
+               const struct lttng_rate_policy *b);
+typedef ssize_t (*rate_policy_create_from_payload_cb)(
+               struct lttng_payload_view *view,
+               struct lttng_rate_policy **rate_policy);
+typedef struct lttng_rate_policy *(*rate_policy_copy_cb)(
+               const struct lttng_rate_policy *source);
+
+struct lttng_rate_policy {
+       enum lttng_rate_policy_type type;
+       rate_policy_serialize_cb serialize;
+       rate_policy_equal_cb equal;
+       rate_policy_destroy_cb destroy;
+       rate_policy_copy_cb copy;
+};
+
+struct lttng_rate_policy_every_n {
+       struct lttng_rate_policy parent;
+       uint64_t interval;
+};
+
+struct lttng_rate_policy_once_after_n {
+       struct lttng_rate_policy parent;
+       uint64_t threshold;
+};
+
+struct lttng_rate_policy_comm {
+       /* enum lttng_rate_policy_type */
+       int8_t rate_policy_type;
+} LTTNG_PACKED;
+
+struct lttng_rate_policy_once_after_n_comm {
+       uint64_t threshold;
+} LTTNG_PACKED;
+
+struct lttng_rate_policy_every_n_comm {
+       uint64_t interval;
+} LTTNG_PACKED;
+
+/* Forward declaration. */
+static void lttng_rate_policy_init(struct lttng_rate_policy *rate_policy,
+               enum lttng_rate_policy_type type,
+               rate_policy_serialize_cb serialize,
+               rate_policy_equal_cb equal,
+               rate_policy_destroy_cb destroy,
+               rate_policy_copy_cb copy);
+
+/* Forward declaration. Every n */
+static bool lttng_rate_policy_every_n_should_execute(
+               const struct lttng_rate_policy *policy, uint64_t counter);
+
+/* Forward declaration. Once after N */
+static bool lttng_rate_policy_once_after_n_should_execute(
+               const struct lttng_rate_policy *policy, uint64_t counter);
+
+LTTNG_HIDDEN
+const char *lttng_rate_policy_type_string(
+               enum lttng_rate_policy_type rate_policy_type)
+{
+       switch (rate_policy_type) {
+       case LTTNG_RATE_POLICY_TYPE_EVERY_N:
+               return "EVERY-N";
+       case LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N:
+               return "ONCE-AFTER-N";
+       default:
+               return "???";
+       }
+}
+
+enum lttng_rate_policy_type lttng_rate_policy_get_type(
+               const struct lttng_rate_policy *policy)
+{
+       return policy ? policy->type : LTTNG_RATE_POLICY_TYPE_UNKNOWN;
+}
+
+LTTNG_HIDDEN
+void lttng_rate_policy_init(struct lttng_rate_policy *rate_policy,
+               enum lttng_rate_policy_type type,
+               rate_policy_serialize_cb serialize,
+               rate_policy_equal_cb equal,
+               rate_policy_destroy_cb destroy,
+               rate_policy_copy_cb copy)
+{
+       rate_policy->type = type;
+       rate_policy->serialize = serialize;
+       rate_policy->equal = equal;
+       rate_policy->destroy = destroy;
+       rate_policy->copy = copy;
+}
+
+void lttng_rate_policy_destroy(struct lttng_rate_policy *rate_policy)
+{
+       if (!rate_policy) {
+               return;
+       }
+
+       rate_policy->destroy(rate_policy);
+}
+
+LTTNG_HIDDEN
+int lttng_rate_policy_serialize(struct lttng_rate_policy *rate_policy,
+               struct lttng_payload *payload)
+{
+       int ret;
+       struct lttng_rate_policy_comm rate_policy_comm = {
+                       .rate_policy_type = (int8_t) rate_policy->type,
+       };
+
+       ret = lttng_dynamic_buffer_append(&payload->buffer, &rate_policy_comm,
+                       sizeof(rate_policy_comm));
+       if (ret) {
+               goto end;
+       }
+
+       ret = rate_policy->serialize(rate_policy, payload);
+       if (ret) {
+               goto end;
+       }
+end:
+       return ret;
+}
+
+static ssize_t lttng_rate_policy_once_after_n_create_from_payload(
+               struct lttng_payload_view *view,
+               struct lttng_rate_policy **rate_policy)
+{
+       ssize_t consumed_len = -1;
+       struct lttng_rate_policy *policy = NULL;
+       const struct lttng_rate_policy_once_after_n_comm *comm;
+       const struct lttng_payload_view comm_view =
+                       lttng_payload_view_from_view(view, 0, sizeof(*comm));
+
+       if (!view || !rate_policy) {
+               consumed_len = -1;
+               goto end;
+       }
+
+       if (!lttng_payload_view_is_valid(&comm_view)) {
+               /* Payload not large enough to contain the header. */
+               consumed_len = -1;
+               goto end;
+       }
+
+       comm = (const struct lttng_rate_policy_once_after_n_comm *)
+                              comm_view.buffer.data;
+
+       policy = lttng_rate_policy_once_after_n_create(comm->threshold);
+       if (policy == NULL) {
+               consumed_len = -1;
+               goto end;
+       }
+
+       *rate_policy = policy;
+       consumed_len = sizeof(*comm);
+
+end:
+       return consumed_len;
+}
+
+static ssize_t lttng_rate_policy_every_n_create_from_payload(
+               struct lttng_payload_view *view,
+               struct lttng_rate_policy **rate_policy)
+{
+       ssize_t consumed_len = -1;
+       struct lttng_rate_policy *policy = NULL;
+       const struct lttng_rate_policy_every_n_comm *comm;
+       const struct lttng_payload_view comm_view =
+                       lttng_payload_view_from_view(view, 0, sizeof(*comm));
+
+       if (!view || !rate_policy) {
+               consumed_len = -1;
+               goto end;
+       }
+
+       if (!lttng_payload_view_is_valid(&comm_view)) {
+               /* Payload not large enough to contain the header. */
+               consumed_len = -1;
+               goto end;
+       }
+
+       comm = (const struct lttng_rate_policy_every_n_comm *)
+                              comm_view.buffer.data;
+
+       policy = lttng_rate_policy_every_n_create(comm->interval);
+       if (policy == NULL) {
+               consumed_len = -1;
+               goto end;
+       }
+
+       *rate_policy = policy;
+       consumed_len = sizeof(*comm);
+
+end:
+       return consumed_len;
+}
+
+LTTNG_HIDDEN
+ssize_t lttng_rate_policy_create_from_payload(struct lttng_payload_view *view,
+               struct lttng_rate_policy **rate_policy)
+{
+       ssize_t consumed_len, specific_rate_policy_consumed_len;
+       rate_policy_create_from_payload_cb create_from_payload_cb;
+       const struct lttng_rate_policy_comm *rate_policy_comm;
+       const struct lttng_payload_view rate_policy_comm_view =
+                       lttng_payload_view_from_view(
+                                       view, 0, sizeof(*rate_policy_comm));
+
+       if (!view || !rate_policy) {
+               consumed_len = -1;
+               goto end;
+       }
+
+       if (!lttng_payload_view_is_valid(&rate_policy_comm_view)) {
+               /* Payload not large enough to contain the header. */
+               consumed_len = -1;
+               goto end;
+       }
+
+       rate_policy_comm = (const struct lttng_rate_policy_comm *)
+                                          rate_policy_comm_view.buffer.data;
+
+       DBG("Create rate_policy from payload: rate-policy-type=%s",
+                       lttng_rate_policy_type_string(
+                                       rate_policy_comm->rate_policy_type));
+
+       switch (rate_policy_comm->rate_policy_type) {
+       case LTTNG_RATE_POLICY_TYPE_EVERY_N:
+               create_from_payload_cb =
+                               lttng_rate_policy_every_n_create_from_payload;
+               break;
+       case LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N:
+               create_from_payload_cb =
+                               lttng_rate_policy_once_after_n_create_from_payload;
+               break;
+       default:
+               ERR("Failed to create rate-policy from payload, unhandled rate-policy type: rate-policy-type=%u (%s)",
+                               rate_policy_comm->rate_policy_type,
+                               lttng_rate_policy_type_string(
+                                               rate_policy_comm->rate_policy_type));
+               consumed_len = -1;
+               goto end;
+       }
+
+       {
+               /* Create buffer view for the rate_policy-type-specific data.
+                */
+               struct lttng_payload_view specific_rate_policy_view =
+                               lttng_payload_view_from_view(view,
+                                               sizeof(struct lttng_rate_policy_comm),
+                                               -1);
+
+               specific_rate_policy_consumed_len = create_from_payload_cb(
+                               &specific_rate_policy_view, rate_policy);
+       }
+       if (specific_rate_policy_consumed_len < 0) {
+               ERR("Failed to create specific rate_policy from buffer.");
+               consumed_len = -1;
+               goto end;
+       }
+
+       assert(*rate_policy);
+
+       consumed_len = sizeof(struct lttng_rate_policy_comm) +
+                       specific_rate_policy_consumed_len;
+
+end:
+       return consumed_len;
+}
+
+LTTNG_HIDDEN
+bool lttng_rate_policy_is_equal(const struct lttng_rate_policy *a,
+               const struct lttng_rate_policy *b)
+{
+       bool is_equal = false;
+
+       if (!a || !b) {
+               goto end;
+       }
+
+       if (a->type != b->type) {
+               goto end;
+       }
+
+       if (a == b) {
+               is_equal = true;
+               goto end;
+       }
+
+       assert(a->equal);
+       is_equal = a->equal(a, b);
+end:
+       return is_equal;
+}
+
+LTTNG_HIDDEN
+bool lttng_rate_policy_should_execute(
+               const struct lttng_rate_policy *policy, uint64_t counter)
+{
+       switch (policy->type) {
+       case LTTNG_RATE_POLICY_TYPE_EVERY_N:
+               return lttng_rate_policy_every_n_should_execute(
+                               policy, counter);
+       case LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N:
+               return lttng_rate_policy_once_after_n_should_execute(
+                               policy, counter);
+       default:
+               abort();
+               break;
+       }
+}
+
+/* Every N */
+static struct lttng_rate_policy_every_n *rate_policy_every_n_from_rate_policy(
+               struct lttng_rate_policy *policy)
+{
+       assert(policy);
+
+       return container_of(policy, struct lttng_rate_policy_every_n, parent);
+}
+
+static const struct lttng_rate_policy_every_n *
+rate_policy_every_n_from_rate_policy_const(
+               const struct lttng_rate_policy *policy)
+{
+       assert(policy);
+
+       return container_of(policy, struct lttng_rate_policy_every_n, parent);
+}
+
+static int lttng_rate_policy_every_n_serialize(
+               struct lttng_rate_policy *policy, struct lttng_payload *payload)
+{
+       int ret;
+
+       struct lttng_rate_policy_every_n *every_n_policy;
+       struct lttng_rate_policy_every_n_comm comm = {};
+
+       assert(policy);
+       assert(payload);
+
+       every_n_policy = rate_policy_every_n_from_rate_policy(policy);
+       comm.interval = every_n_policy->interval;
+
+       ret = lttng_dynamic_buffer_append(
+                       &payload->buffer, &comm, sizeof(comm));
+       return ret;
+}
+
+static bool lttng_rate_policy_every_n_is_equal(
+               const struct lttng_rate_policy *_a,
+               const struct lttng_rate_policy *_b)
+{
+       bool is_equal = false;
+       const struct lttng_rate_policy_every_n *a, *b;
+
+       a = rate_policy_every_n_from_rate_policy_const(_a);
+       b = rate_policy_every_n_from_rate_policy_const(_b);
+
+       if (a->interval != b->interval) {
+               goto end;
+       }
+
+       is_equal = true;
+
+end:
+       return is_equal;
+}
+
+static void lttng_rate_policy_every_n_destroy(struct lttng_rate_policy *policy)
+{
+       struct lttng_rate_policy_every_n *every_n_policy;
+
+       if (!policy) {
+               goto end;
+       }
+
+       every_n_policy = rate_policy_every_n_from_rate_policy(policy);
+
+       free(every_n_policy);
+
+end:
+       return;
+}
+
+static struct lttng_rate_policy *lttng_rate_policy_every_n_copy(
+               const struct lttng_rate_policy *source)
+{
+       struct lttng_rate_policy *copy = NULL;
+       const struct lttng_rate_policy_every_n *every_n_policy;
+
+       if (!source) {
+               goto end;
+       }
+
+       every_n_policy = rate_policy_every_n_from_rate_policy_const(source);
+       copy = lttng_rate_policy_every_n_create(every_n_policy->interval);
+
+end:
+       return copy;
+}
+
+struct lttng_rate_policy *lttng_rate_policy_every_n_create(uint64_t interval)
+{
+       struct lttng_rate_policy_every_n *policy = NULL;
+       struct lttng_rate_policy *_policy = NULL;
+
+       if (interval == 0) {
+               /*
+                * An interval of 0 is invalid since it would never be fired.
+                */
+               goto end;
+       }
+
+       policy = zmalloc(sizeof(struct lttng_rate_policy_every_n));
+       if (!policy) {
+               goto end;
+       }
+
+       lttng_rate_policy_init(&policy->parent, LTTNG_RATE_POLICY_TYPE_EVERY_N,
+                       lttng_rate_policy_every_n_serialize,
+                       lttng_rate_policy_every_n_is_equal,
+                       lttng_rate_policy_every_n_destroy,
+                       lttng_rate_policy_every_n_copy);
+
+       policy->interval = interval;
+
+       _policy = &policy->parent;
+       policy = NULL;
+
+end:
+       free(policy);
+       return _policy;
+}
+
+LTTNG_HIDDEN
+enum lttng_rate_policy_status lttng_rate_policy_every_n_get_interval(
+               const struct lttng_rate_policy *policy, uint64_t *interval)
+{
+       const struct lttng_rate_policy_every_n *every_n_policy;
+       enum lttng_rate_policy_status status;
+
+       if (!policy || !IS_EVERY_N_RATE_POLICY(policy) || !interval) {
+               status = LTTNG_RATE_POLICY_STATUS_INVALID;
+               goto end;
+       }
+
+       every_n_policy = rate_policy_every_n_from_rate_policy_const(policy);
+       *interval = every_n_policy->interval;
+       status = LTTNG_RATE_POLICY_STATUS_OK;
+end:
+
+       return status;
+}
+
+static bool lttng_rate_policy_every_n_should_execute(
+               const struct lttng_rate_policy *policy, uint64_t counter)
+{
+       const struct lttng_rate_policy_every_n *every_n_policy;
+       assert(policy);
+       bool execute = false;
+
+       every_n_policy = rate_policy_every_n_from_rate_policy_const(policy);
+
+       if (every_n_policy->interval == 0) {
+               abort();
+       }
+
+       execute = (counter % every_n_policy->interval) == 0;
+
+       DBG("Policy every N = %" PRIu64
+           ": execution %s. Execution count: %" PRIu64,
+                       every_n_policy->interval,
+                       execute ? "accepted" : "denied", counter);
+
+       return execute;
+}
+
+/* Once after N */
+
+static struct lttng_rate_policy_once_after_n *
+rate_policy_once_after_n_from_rate_policy(struct lttng_rate_policy *policy)
+{
+       assert(policy);
+
+       return container_of(
+                       policy, struct lttng_rate_policy_once_after_n, parent);
+}
+
+static const struct lttng_rate_policy_once_after_n *
+rate_policy_once_after_n_from_rate_policy_const(
+               const struct lttng_rate_policy *policy)
+{
+       assert(policy);
+
+       return container_of(
+                       policy, struct lttng_rate_policy_once_after_n, parent);
+}
+static int lttng_rate_policy_once_after_n_serialize(
+               struct lttng_rate_policy *policy, struct lttng_payload *payload)
+{
+       int ret;
+
+       struct lttng_rate_policy_once_after_n *once_after_n_policy;
+       struct lttng_rate_policy_once_after_n_comm comm = {};
+
+       assert(policy);
+       assert(payload);
+
+       once_after_n_policy = rate_policy_once_after_n_from_rate_policy(policy);
+       comm.threshold = once_after_n_policy->threshold;
+
+       ret = lttng_dynamic_buffer_append(
+                       &payload->buffer, &comm, sizeof(comm));
+       return ret;
+}
+
+static bool lttng_rate_policy_once_after_n_is_equal(
+               const struct lttng_rate_policy *_a,
+               const struct lttng_rate_policy *_b)
+{
+       bool is_equal = false;
+       const struct lttng_rate_policy_once_after_n *a, *b;
+
+       a = rate_policy_once_after_n_from_rate_policy_const(_a);
+       b = rate_policy_once_after_n_from_rate_policy_const(_b);
+
+       if (a->threshold != b->threshold) {
+               goto end;
+       }
+
+       is_equal = true;
+
+end:
+       return is_equal;
+}
+
+static void lttng_rate_policy_once_after_n_destroy(
+               struct lttng_rate_policy *policy)
+{
+       struct lttng_rate_policy_once_after_n *once_after_n_policy;
+
+       if (!policy) {
+               goto end;
+       }
+
+       once_after_n_policy = rate_policy_once_after_n_from_rate_policy(policy);
+
+       free(once_after_n_policy);
+
+end:
+       return;
+}
+
+static struct lttng_rate_policy *lttng_rate_policy_once_after_n_copy(
+               const struct lttng_rate_policy *source)
+{
+       struct lttng_rate_policy *copy = NULL;
+       const struct lttng_rate_policy_once_after_n *once_after_n_policy;
+
+       if (!source) {
+               goto end;
+       }
+
+       once_after_n_policy =
+                       rate_policy_once_after_n_from_rate_policy_const(source);
+       copy = lttng_rate_policy_once_after_n_create(
+                       once_after_n_policy->threshold);
+
+end:
+       return copy;
+}
+
+struct lttng_rate_policy *lttng_rate_policy_once_after_n_create(
+               uint64_t threshold)
+{
+       struct lttng_rate_policy_once_after_n *policy = NULL;
+       struct lttng_rate_policy *_policy = NULL;
+
+       if (threshold == 0) {
+               /* threshold is expected to be > 0 */
+               goto end;
+       }
+
+       policy = zmalloc(sizeof(struct lttng_rate_policy_once_after_n));
+       if (!policy) {
+               goto end;
+       }
+
+       lttng_rate_policy_init(&policy->parent,
+                       LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N,
+                       lttng_rate_policy_once_after_n_serialize,
+                       lttng_rate_policy_once_after_n_is_equal,
+                       lttng_rate_policy_once_after_n_destroy,
+                       lttng_rate_policy_once_after_n_copy);
+
+       policy->threshold = threshold;
+
+       _policy = &policy->parent;
+       policy = NULL;
+
+end:
+       free(policy);
+       return _policy;
+}
+
+LTTNG_HIDDEN
+enum lttng_rate_policy_status lttng_rate_policy_once_after_n_get_threshold(
+               const struct lttng_rate_policy *policy, uint64_t *threshold)
+{
+       const struct lttng_rate_policy_once_after_n *once_after_n_policy;
+       enum lttng_rate_policy_status status;
+
+       if (!policy || !IS_ONCE_AFTER_N_RATE_POLICY(policy) || !threshold) {
+               status = LTTNG_RATE_POLICY_STATUS_INVALID;
+               goto end;
+       }
+
+       once_after_n_policy =
+                       rate_policy_once_after_n_from_rate_policy_const(policy);
+       *threshold = once_after_n_policy->threshold;
+       status = LTTNG_RATE_POLICY_STATUS_OK;
+end:
+
+       return status;
+}
+
+LTTNG_HIDDEN
+struct lttng_rate_policy *lttng_rate_policy_copy(
+               const struct lttng_rate_policy *source)
+{
+       assert(source->copy);
+       return source->copy(source);
+}
+
+static bool lttng_rate_policy_once_after_n_should_execute(
+               const struct lttng_rate_policy *policy, uint64_t counter)
+{
+       const struct lttng_rate_policy_once_after_n *once_after_n_policy;
+       bool execute = false;
+       assert(policy);
+
+       once_after_n_policy =
+                       rate_policy_once_after_n_from_rate_policy_const(policy);
+
+       execute = counter == once_after_n_policy->threshold;
+
+       DBG("Policy once after N = %" PRIu64
+           ": execution %s. Execution count: %" PRIu64,
+                       once_after_n_policy->threshold,
+                       execute ? "accepted" : "denied", counter);
+
+       return counter == once_after_n_policy->threshold;
+}
index f2ac2d04dcc0e04fa587de24aefcc12c0cce1c65..3d5a61709b791be6a531eeee7c82b18f677e3737 100644 (file)
@@ -9,8 +9,8 @@
 #include <common/error.h>
 #include <common/macros.h>
 #include <lttng/action/action-internal.h>
-#include <lttng/action/firing-policy-internal.h>
-#include <lttng/action/firing-policy.h>
+#include <lttng/action/rate-policy-internal.h>
+#include <lttng/action/rate-policy.h>
 #include <lttng/action/rotate-session-internal.h>
 #include <lttng/action/rotate-session.h>
 
@@ -22,7 +22,7 @@ struct lttng_action_rotate_session {
 
        /* Owned by this. */
        char *session_name;
-       struct lttng_firing_policy *policy;
+       struct lttng_rate_policy *policy;
 };
 
 struct lttng_action_rotate_session_comm {
@@ -38,8 +38,8 @@ struct lttng_action_rotate_session_comm {
        char data[];
 } LTTNG_PACKED;
 
-static const struct lttng_firing_policy *
-lttng_action_rotate_session_internal_get_firing_policy(
+static const struct lttng_rate_policy *
+lttng_action_rotate_session_internal_get_rate_policy(
                const struct lttng_action *action);
 
 static struct lttng_action_rotate_session *action_rotate_session_from_action(
@@ -98,7 +98,7 @@ static bool lttng_action_rotate_session_is_equal(
                goto end;
        }
 
-       is_equal = lttng_firing_policy_is_equal(a->policy, b->policy);
+       is_equal = lttng_rate_policy_is_equal(a->policy, b->policy);
 end:
        return is_equal;
 }
@@ -137,7 +137,7 @@ static int lttng_action_rotate_session_serialize(
                goto end;
        }
 
-       ret = lttng_firing_policy_serialize(
+       ret = lttng_rate_policy_serialize(
                        action_rotate_session->policy, payload);
        if (ret) {
                ret = -1;
@@ -157,7 +157,7 @@ static void lttng_action_rotate_session_destroy(struct lttng_action *action)
 
        action_rotate_session = action_rotate_session_from_action(action);
 
-       lttng_firing_policy_destroy(action_rotate_session->policy);
+       lttng_rate_policy_destroy(action_rotate_session->policy);
        free(action_rotate_session->session_name);
        free(action_rotate_session);
 
@@ -174,7 +174,7 @@ ssize_t lttng_action_rotate_session_create_from_payload(
        const char *session_name;
        struct lttng_action *action;
        enum lttng_action_status status;
-       struct lttng_firing_policy *policy = NULL;
+       struct lttng_rate_policy *policy = NULL;
 
        action = lttng_action_rotate_session_create();
        if (!action) {
@@ -192,12 +192,12 @@ ssize_t lttng_action_rotate_session_create_from_payload(
        }
        consumed_len = sizeof(*comm) + comm->session_name_len;
 
-       /* Firing policy. */
+       /* Rate policy. */
        {
                struct lttng_payload_view policy_view =
                                lttng_payload_view_from_view(
                                                view, consumed_len, -1);
-               ret = lttng_firing_policy_create_from_payload(
+               ret = lttng_rate_policy_create_from_payload(
                                &policy_view, &policy);
                if (ret < 0) {
                        consumed_len = -1;
@@ -214,7 +214,7 @@ ssize_t lttng_action_rotate_session_create_from_payload(
        }
 
        assert(policy);
-       status = lttng_action_rotate_session_set_firing_policy(action, policy);
+       status = lttng_action_rotate_session_set_rate_policy(action, policy);
        if (status != LTTNG_ACTION_STATUS_OK) {
                consumed_len = -1;
                goto end;
@@ -224,7 +224,7 @@ ssize_t lttng_action_rotate_session_create_from_payload(
        action = NULL;
 
 end:
-       lttng_firing_policy_destroy(policy);
+       lttng_rate_policy_destroy(policy);
        lttng_action_rotate_session_destroy(action);
 
        return consumed_len;
@@ -233,11 +233,11 @@ end:
 struct lttng_action *lttng_action_rotate_session_create(void)
 {
        struct lttng_action *action = NULL;
-       struct lttng_firing_policy *policy = NULL;
+       struct lttng_rate_policy *policy = NULL;
        enum lttng_action_status status;
 
-       /* Create a every N = 1 firing policy. */
-       policy = lttng_firing_policy_every_n_create(1);
+       /* Create a every N = 1 rate policy. */
+       policy = lttng_rate_policy_every_n_create(1);
        if (!policy) {
                goto end;
        }
@@ -252,9 +252,9 @@ struct lttng_action *lttng_action_rotate_session_create(void)
                        lttng_action_rotate_session_serialize,
                        lttng_action_rotate_session_is_equal,
                        lttng_action_rotate_session_destroy,
-                       lttng_action_rotate_session_internal_get_firing_policy);
+                       lttng_action_rotate_session_internal_get_rate_policy);
 
-       status = lttng_action_rotate_session_set_firing_policy(action, policy);
+       status = lttng_action_rotate_session_set_rate_policy(action, policy);
        if (status != LTTNG_ACTION_STATUS_OK) {
                free(action);
                action = NULL;
@@ -262,7 +262,7 @@ struct lttng_action *lttng_action_rotate_session_create(void)
        }
 
 end:
-       lttng_firing_policy_destroy(policy);
+       lttng_rate_policy_destroy(policy);
        return action;
 }
 
@@ -313,20 +313,20 @@ end:
        return status;
 }
 
-enum lttng_action_status lttng_action_rotate_session_set_firing_policy(
+enum lttng_action_status lttng_action_rotate_session_set_rate_policy(
                struct lttng_action *action,
-               const struct lttng_firing_policy *policy)
+               const struct lttng_rate_policy *policy)
 {
        enum lttng_action_status status;
        struct lttng_action_rotate_session *rotate_session_action;
-       struct lttng_firing_policy *copy = NULL;
+       struct lttng_rate_policy *copy = NULL;
 
        if (!action || !policy || !IS_ROTATE_SESSION_ACTION(action)) {
                status = LTTNG_ACTION_STATUS_INVALID;
                goto end;
        }
 
-       copy = lttng_firing_policy_copy(policy);
+       copy = lttng_rate_policy_copy(policy);
        if (!copy) {
                status = LTTNG_ACTION_STATUS_ERROR;
                goto end;
@@ -334,8 +334,8 @@ enum lttng_action_status lttng_action_rotate_session_set_firing_policy(
 
        rotate_session_action = action_rotate_session_from_action(action);
 
-       /* Free the previous firing policy .*/
-       lttng_firing_policy_destroy(rotate_session_action->policy);
+       /* Free the previous rate policy .*/
+       lttng_rate_policy_destroy(rotate_session_action->policy);
 
        /* Assign the policy. */
        rotate_session_action->policy = copy;
@@ -343,13 +343,13 @@ enum lttng_action_status lttng_action_rotate_session_set_firing_policy(
        copy = NULL;
 
 end:
-       lttng_firing_policy_destroy(copy);
+       lttng_rate_policy_destroy(copy);
        return status;
 }
 
-enum lttng_action_status lttng_action_rotate_session_get_firing_policy(
+enum lttng_action_status lttng_action_rotate_session_get_rate_policy(
                const struct lttng_action *action,
-               const struct lttng_firing_policy **policy)
+               const struct lttng_rate_policy **policy)
 {
        enum lttng_action_status status;
        const struct lttng_action_rotate_session *rotate_session_action;
@@ -367,8 +367,8 @@ end:
        return status;
 }
 
-static const struct lttng_firing_policy *
-lttng_action_rotate_session_internal_get_firing_policy(
+static const struct lttng_rate_policy *
+lttng_action_rotate_session_internal_get_rate_policy(
                const struct lttng_action *action)
 {
        const struct lttng_action_rotate_session *_action;
index 5d01784958de3eed0bd07d1119d51b9c73204142..239cf5e73fded4ebd25bb3785a6d6dea8897a633 100644 (file)
@@ -13,8 +13,8 @@
 #include <common/snapshot.h>
 #include <inttypes.h>
 #include <lttng/action/action-internal.h>
-#include <lttng/action/firing-policy-internal.h>
-#include <lttng/action/firing-policy.h>
+#include <lttng/action/rate-policy-internal.h>
+#include <lttng/action/rate-policy.h>
 #include <lttng/action/snapshot-session-internal.h>
 #include <lttng/action/snapshot-session.h>
 #include <lttng/snapshot-internal.h>
@@ -36,14 +36,14 @@ struct lttng_action_snapshot_session {
         * Owned by this.
         */
        struct lttng_snapshot_output *output;
-       struct lttng_firing_policy *policy;
+       struct lttng_rate_policy *policy;
 };
 
 struct lttng_action_snapshot_session_comm {
        /* All string lengths include the trailing \0. */
        uint32_t session_name_len;
        uint32_t snapshot_output_len;
-       uint32_t firing_policy_len;
+       uint32_t rate_policy_len;
 
        /*
         * Variable data (all strings are null-terminated):
@@ -55,8 +55,8 @@ struct lttng_action_snapshot_session_comm {
        char data[];
 } LTTNG_PACKED;
 
-static const struct lttng_firing_policy *
-lttng_action_snapshot_session_internal_get_firing_policy(
+static const struct lttng_rate_policy *
+lttng_action_snapshot_session_internal_get_rate_policy(
                const struct lttng_action *action);
 
 static struct lttng_action_snapshot_session *
@@ -127,7 +127,7 @@ static bool lttng_action_snapshot_session_is_equal(
                goto end;
        }
 
-       is_equal = lttng_firing_policy_is_equal(a->policy, b->policy);
+       is_equal = lttng_rate_policy_is_equal(a->policy, b->policy);
 end:
        return is_equal;
 }
@@ -192,12 +192,12 @@ static int lttng_action_snapshot_session_serialize(
                                payload->buffer.size - size_before_output;
        }
 
-       /* Serialize the firing policy. */
+       /* Serialize the rate policy. */
        {
                const size_t size_before_output = payload->buffer.size;
                struct lttng_action_snapshot_session_comm *comm_in_payload;
 
-               ret = lttng_firing_policy_serialize(
+               ret = lttng_rate_policy_serialize(
                                action_snapshot_session->policy, payload);
                if (ret) {
                        ret = -1;
@@ -206,8 +206,8 @@ static int lttng_action_snapshot_session_serialize(
 
                comm_in_payload = (typeof(comm_in_payload))(
                                payload->buffer.data + size_before_comm);
-               /* Adjust firing policy length in header. */
-               comm_in_payload->firing_policy_len =
+               /* Adjust rate policy length in header. */
+               comm_in_payload->rate_policy_len =
                                payload->buffer.size - size_before_output;
        }
 
@@ -227,7 +227,7 @@ static void lttng_action_snapshot_session_destroy(struct lttng_action *action)
 
        free(action_snapshot_session->session_name);
        lttng_snapshot_output_destroy(action_snapshot_session->output);
-       lttng_firing_policy_destroy(action_snapshot_session->policy);
+       lttng_rate_policy_destroy(action_snapshot_session->policy);
        free(action_snapshot_session);
 
 end:
@@ -243,7 +243,7 @@ ssize_t lttng_action_snapshot_session_create_from_payload(
        struct lttng_action *action;
        enum lttng_action_status status;
        struct lttng_snapshot_output *snapshot_output = NULL;
-       struct lttng_firing_policy *policy = NULL;
+       struct lttng_rate_policy *policy = NULL;
        const struct lttng_action_snapshot_session_comm *comm;
        const struct lttng_payload_view snapshot_session_comm_view =
                        lttng_payload_view_from_view(
@@ -316,46 +316,46 @@ ssize_t lttng_action_snapshot_session_create_from_payload(
        variable_data += comm->snapshot_output_len;
        consumed_len += comm->snapshot_output_len;
 
-       /* Firing policy. */
-       if (comm->firing_policy_len <= 0) {
-               ERR("Firing policy should be present.");
+       /* Rate policy. */
+       if (comm->rate_policy_len <= 0) {
+               ERR("Rate policy should be present.");
                goto error;
        }
        {
-               ssize_t firing_policy_consumed_len;
+               ssize_t rate_policy_consumed_len;
                struct lttng_payload_view policy_view =
                                lttng_payload_view_from_view(view, consumed_len,
-                                               comm->firing_policy_len);
+                                               comm->rate_policy_len);
 
                if (!lttng_payload_view_is_valid(&policy_view)) {
-                       ERR("Failed to create buffer view for firing policy.");
+                       ERR("Failed to create buffer view for rate policy.");
                        goto error;
                }
 
-               firing_policy_consumed_len =
-                               lttng_firing_policy_create_from_payload(
+               rate_policy_consumed_len =
+                               lttng_rate_policy_create_from_payload(
                                                &policy_view, &policy);
-               if (firing_policy_consumed_len < 0) {
+               if (rate_policy_consumed_len < 0) {
                        goto error;
                }
 
-               if (firing_policy_consumed_len != comm->firing_policy_len) {
-                       ERR("Failed to deserialize firing policy object: "
+               if (rate_policy_consumed_len != comm->rate_policy_len) {
+                       ERR("Failed to deserialize rate policy object: "
                            "consumed-len: %zd, expected-len: %" PRIu32,
-                                       firing_policy_consumed_len,
-                                       comm->firing_policy_len);
+                                       rate_policy_consumed_len,
+                                       comm->rate_policy_len);
                        goto error;
                }
 
-               status = lttng_action_snapshot_session_set_firing_policy(
+               status = lttng_action_snapshot_session_set_rate_policy(
                                action, policy);
                if (status != LTTNG_ACTION_STATUS_OK) {
                        goto error;
                }
        }
 
-       variable_data += comm->firing_policy_len;
-       consumed_len += comm->firing_policy_len;
+       variable_data += comm->rate_policy_len;
+       consumed_len += comm->rate_policy_len;
 
        *p_action = action;
        action = NULL;
@@ -366,7 +366,7 @@ error:
        consumed_len = -1;
 
 end:
-       lttng_firing_policy_destroy(policy);
+       lttng_rate_policy_destroy(policy);
        lttng_action_snapshot_session_destroy(action);
        lttng_snapshot_output_destroy(snapshot_output);
 
@@ -376,11 +376,11 @@ end:
 struct lttng_action *lttng_action_snapshot_session_create(void)
 {
        struct lttng_action *action = NULL;
-       struct lttng_firing_policy *policy = NULL;
+       struct lttng_rate_policy *policy = NULL;
        enum lttng_action_status status;
 
-       /* Create a every N = 1 firing policy. */
-       policy = lttng_firing_policy_every_n_create(1);
+       /* Create a every N = 1 rate policy. */
+       policy = lttng_rate_policy_every_n_create(1);
        if (!policy) {
                goto end;
        }
@@ -395,10 +395,9 @@ struct lttng_action *lttng_action_snapshot_session_create(void)
                        lttng_action_snapshot_session_serialize,
                        lttng_action_snapshot_session_is_equal,
                        lttng_action_snapshot_session_destroy,
-                       lttng_action_snapshot_session_internal_get_firing_policy);
+                       lttng_action_snapshot_session_internal_get_rate_policy);
 
-       status = lttng_action_snapshot_session_set_firing_policy(
-                       action, policy);
+       status = lttng_action_snapshot_session_set_rate_policy(action, policy);
        if (status != LTTNG_ACTION_STATUS_OK) {
                free(action);
                action = NULL;
@@ -406,7 +405,7 @@ struct lttng_action *lttng_action_snapshot_session_create(void)
        }
 
 end:
-       lttng_firing_policy_destroy(policy);
+       lttng_rate_policy_destroy(policy);
        return action;
 }
 
@@ -510,20 +509,20 @@ end:
        return status;
 }
 
-enum lttng_action_status lttng_action_snapshot_session_set_firing_policy(
+enum lttng_action_status lttng_action_snapshot_session_set_rate_policy(
                struct lttng_action *action,
-               const struct lttng_firing_policy *policy)
+               const struct lttng_rate_policy *policy)
 {
        enum lttng_action_status status;
        struct lttng_action_snapshot_session *snapshot_session_action;
-       struct lttng_firing_policy *copy = NULL;
+       struct lttng_rate_policy *copy = NULL;
 
        if (!action || !policy || !IS_SNAPSHOT_SESSION_ACTION(action)) {
                status = LTTNG_ACTION_STATUS_INVALID;
                goto end;
        }
 
-       copy = lttng_firing_policy_copy(policy);
+       copy = lttng_rate_policy_copy(policy);
        if (!copy) {
                status = LTTNG_ACTION_STATUS_ERROR;
                goto end;
@@ -531,8 +530,8 @@ enum lttng_action_status lttng_action_snapshot_session_set_firing_policy(
 
        snapshot_session_action = action_snapshot_session_from_action(action);
 
-       /* Free the previous firing policy .*/
-       lttng_firing_policy_destroy(snapshot_session_action->policy);
+       /* Free the previous rate policy .*/
+       lttng_rate_policy_destroy(snapshot_session_action->policy);
 
        /* Assign the policy. */
        snapshot_session_action->policy = copy;
@@ -540,13 +539,13 @@ enum lttng_action_status lttng_action_snapshot_session_set_firing_policy(
        copy = NULL;
 
 end:
-       lttng_firing_policy_destroy(copy);
+       lttng_rate_policy_destroy(copy);
        return status;
 }
 
-enum lttng_action_status lttng_action_snapshot_session_get_firing_policy(
+enum lttng_action_status lttng_action_snapshot_session_get_rate_policy(
                const struct lttng_action *action,
-               const struct lttng_firing_policy **policy)
+               const struct lttng_rate_policy **policy)
 {
        enum lttng_action_status status;
        const struct lttng_action_snapshot_session *snapshot_session_action;
@@ -565,8 +564,8 @@ end:
        return status;
 }
 
-static const struct lttng_firing_policy *
-lttng_action_snapshot_session_internal_get_firing_policy(
+static const struct lttng_rate_policy *
+lttng_action_snapshot_session_internal_get_rate_policy(
                const struct lttng_action *action)
 {
        const struct lttng_action_snapshot_session *_action;
index 07aeaf779ef5bd1c84b8f18e47cb09e3dfc842ba..8ed8068dd2f902f1f1ce17d5298a16c8ed69ee6b 100644 (file)
@@ -9,8 +9,8 @@
 #include <common/error.h>
 #include <common/macros.h>
 #include <lttng/action/action-internal.h>
-#include <lttng/action/firing-policy-internal.h>
-#include <lttng/action/firing-policy.h>
+#include <lttng/action/rate-policy-internal.h>
+#include <lttng/action/rate-policy.h>
 #include <lttng/action/start-session-internal.h>
 #include <lttng/action/start-session.h>
 
@@ -22,7 +22,7 @@ struct lttng_action_start_session {
 
        /* Owned by this. */
        char *session_name;
-       struct lttng_firing_policy *policy;
+       struct lttng_rate_policy *policy;
 };
 
 struct lttng_action_start_session_comm {
@@ -38,8 +38,8 @@ struct lttng_action_start_session_comm {
        char data[];
 } LTTNG_PACKED;
 
-static const struct lttng_firing_policy *
-lttng_action_start_session_internal_get_firing_policy(
+static const struct lttng_rate_policy *
+lttng_action_start_session_internal_get_rate_policy(
                const struct lttng_action *action);
 
 static struct lttng_action_start_session *action_start_session_from_action(
@@ -98,7 +98,7 @@ static bool lttng_action_start_session_is_equal(
                goto end;
        }
 
-       is_equal = lttng_firing_policy_is_equal(a->policy, b->policy);
+       is_equal = lttng_rate_policy_is_equal(a->policy, b->policy);
 end:
        return is_equal;
 }
@@ -137,7 +137,7 @@ static int lttng_action_start_session_serialize(
                goto end;
        }
 
-       ret = lttng_firing_policy_serialize(
+       ret = lttng_rate_policy_serialize(
                        action_start_session->policy, payload);
        if (ret) {
                ret = -1;
@@ -159,7 +159,7 @@ static void lttng_action_start_session_destroy(struct lttng_action *action)
 
        action_start_session = action_start_session_from_action(action);
 
-       lttng_firing_policy_destroy(action_start_session->policy);
+       lttng_rate_policy_destroy(action_start_session->policy);
        free(action_start_session->session_name);
        free(action_start_session);
 
@@ -176,7 +176,7 @@ ssize_t lttng_action_start_session_create_from_payload(
        const char *session_name;
        struct lttng_action *action = NULL;
        enum lttng_action_status status;
-       struct lttng_firing_policy *policy = NULL;
+       struct lttng_rate_policy *policy = NULL;
 
        comm = (typeof(comm)) view->buffer.data;
        session_name = (const char *) &comm->data;
@@ -189,12 +189,12 @@ ssize_t lttng_action_start_session_create_from_payload(
        }
        consumed_len = sizeof(*comm) + comm->session_name_len;
 
-       /* Firing policy. */
+       /* Rate policy. */
        {
                struct lttng_payload_view policy_view =
                                lttng_payload_view_from_view(
                                                view, consumed_len, -1);
-               ret = lttng_firing_policy_create_from_payload(
+               ret = lttng_rate_policy_create_from_payload(
                                &policy_view, &policy);
                if (ret < 0) {
                        consumed_len = -1;
@@ -217,7 +217,7 @@ ssize_t lttng_action_start_session_create_from_payload(
        }
 
        assert(policy);
-       status = lttng_action_start_session_set_firing_policy(action, policy);
+       status = lttng_action_start_session_set_rate_policy(action, policy);
        if (status != LTTNG_ACTION_STATUS_OK) {
                consumed_len = -1;
                goto end;
@@ -227,7 +227,7 @@ ssize_t lttng_action_start_session_create_from_payload(
        action = NULL;
 
 end:
-       lttng_firing_policy_destroy(policy);
+       lttng_rate_policy_destroy(policy);
        lttng_action_start_session_destroy(action);
 
        return consumed_len;
@@ -236,11 +236,11 @@ end:
 struct lttng_action *lttng_action_start_session_create(void)
 {
        struct lttng_action *action = NULL;
-       struct lttng_firing_policy *policy = NULL;
+       struct lttng_rate_policy *policy = NULL;
        enum lttng_action_status status;
 
-       /* Create a every N = 1 firing policy. */
-       policy = lttng_firing_policy_every_n_create(1);
+       /* Create a every N = 1 rate policy. */
+       policy = lttng_rate_policy_every_n_create(1);
        if (!policy) {
                goto end;
        }
@@ -255,9 +255,9 @@ struct lttng_action *lttng_action_start_session_create(void)
                        lttng_action_start_session_serialize,
                        lttng_action_start_session_is_equal,
                        lttng_action_start_session_destroy,
-                       lttng_action_start_session_internal_get_firing_policy);
+                       lttng_action_start_session_internal_get_rate_policy);
 
-       status = lttng_action_start_session_set_firing_policy(action, policy);
+       status = lttng_action_start_session_set_rate_policy(action, policy);
        if (status != LTTNG_ACTION_STATUS_OK) {
                free(action);
                action = NULL;
@@ -265,7 +265,7 @@ struct lttng_action *lttng_action_start_session_create(void)
        }
 
 end:
-       lttng_firing_policy_destroy(policy);
+       lttng_rate_policy_destroy(policy);
        return action;
 }
 
@@ -316,20 +316,20 @@ end:
        return status;
 }
 
-enum lttng_action_status lttng_action_start_session_set_firing_policy(
+enum lttng_action_status lttng_action_start_session_set_rate_policy(
                struct lttng_action *action,
-               const struct lttng_firing_policy *policy)
+               const struct lttng_rate_policy *policy)
 {
        enum lttng_action_status status;
        struct lttng_action_start_session *start_session_action;
-       struct lttng_firing_policy *copy = NULL;
+       struct lttng_rate_policy *copy = NULL;
 
        if (!action || !policy || !IS_START_SESSION_ACTION(action)) {
                status = LTTNG_ACTION_STATUS_INVALID;
                goto end;
        }
 
-       copy = lttng_firing_policy_copy(policy);
+       copy = lttng_rate_policy_copy(policy);
        if (!copy) {
                status = LTTNG_ACTION_STATUS_ERROR;
                goto end;
@@ -337,8 +337,8 @@ enum lttng_action_status lttng_action_start_session_set_firing_policy(
 
        start_session_action = action_start_session_from_action(action);
 
-       /* Release the previous firing policy .*/
-       lttng_firing_policy_destroy(start_session_action->policy);
+       /* Release the previous rate policy .*/
+       lttng_rate_policy_destroy(start_session_action->policy);
 
        /* Assign the policy. */
        start_session_action->policy = copy;
@@ -346,13 +346,13 @@ enum lttng_action_status lttng_action_start_session_set_firing_policy(
        copy = NULL;
 
 end:
-       lttng_firing_policy_destroy(copy);
+       lttng_rate_policy_destroy(copy);
        return status;
 }
 
-enum lttng_action_status lttng_action_start_session_get_firing_policy(
+enum lttng_action_status lttng_action_start_session_get_rate_policy(
                const struct lttng_action *action,
-               const struct lttng_firing_policy **policy)
+               const struct lttng_rate_policy **policy)
 {
        enum lttng_action_status status;
        const struct lttng_action_start_session *start_session_action;
@@ -370,8 +370,8 @@ end:
        return status;
 }
 
-static const struct lttng_firing_policy *
-lttng_action_start_session_internal_get_firing_policy(
+static const struct lttng_rate_policy *
+lttng_action_start_session_internal_get_rate_policy(
                const struct lttng_action *action)
 {
        const struct lttng_action_start_session *_action;
index b3ff63188f2e05952dae5fdd5f7b93d591111a4d..9f74bf88496efe26309c6d187b28e847c78fbadb 100644 (file)
@@ -9,8 +9,8 @@
 #include <common/error.h>
 #include <common/macros.h>
 #include <lttng/action/action-internal.h>
-#include <lttng/action/firing-policy-internal.h>
-#include <lttng/action/firing-policy.h>
+#include <lttng/action/rate-policy-internal.h>
+#include <lttng/action/rate-policy.h>
 #include <lttng/action/stop-session-internal.h>
 #include <lttng/action/stop-session.h>
 
@@ -22,7 +22,7 @@ struct lttng_action_stop_session {
 
        /* Owned by this. */
        char *session_name;
-       struct lttng_firing_policy *policy;
+       struct lttng_rate_policy *policy;
 };
 
 struct lttng_action_stop_session_comm {
@@ -38,8 +38,8 @@ struct lttng_action_stop_session_comm {
        char data[];
 } LTTNG_PACKED;
 
-static const struct lttng_firing_policy *
-lttng_action_stop_session_internal_get_firing_policy(
+static const struct lttng_rate_policy *
+lttng_action_stop_session_internal_get_rate_policy(
                const struct lttng_action *action);
 
 static struct lttng_action_stop_session *action_stop_session_from_action(
@@ -98,7 +98,7 @@ static bool lttng_action_stop_session_is_equal(
                goto end;
        }
 
-       is_equal = lttng_firing_policy_is_equal(a->policy, b->policy);
+       is_equal = lttng_rate_policy_is_equal(a->policy, b->policy);
 end:
        return is_equal;
 }
@@ -138,8 +138,7 @@ static int lttng_action_stop_session_serialize(
                goto end;
        }
 
-       ret = lttng_firing_policy_serialize(
-                       action_stop_session->policy, payload);
+       ret = lttng_rate_policy_serialize(action_stop_session->policy, payload);
        if (ret) {
                ret = -1;
                goto end;
@@ -160,7 +159,7 @@ static void lttng_action_stop_session_destroy(struct lttng_action *action)
 
        action_stop_session = action_stop_session_from_action(action);
 
-       lttng_firing_policy_destroy(action_stop_session->policy);
+       lttng_rate_policy_destroy(action_stop_session->policy);
        free(action_stop_session->session_name);
        free(action_stop_session);
 
@@ -177,7 +176,7 @@ ssize_t lttng_action_stop_session_create_from_payload(
        const char *session_name;
        struct lttng_action *action = NULL;
        enum lttng_action_status status;
-       struct lttng_firing_policy *policy = NULL;
+       struct lttng_rate_policy *policy = NULL;
 
        comm = (typeof(comm)) view->buffer.data;
        session_name = (const char *) &comm->data;
@@ -190,12 +189,12 @@ ssize_t lttng_action_stop_session_create_from_payload(
        }
        consumed_len = sizeof(*comm) + comm->session_name_len;
 
-       /* Firing policy. */
+       /* Rate policy. */
        {
                struct lttng_payload_view policy_view =
                                lttng_payload_view_from_view(
                                                view, consumed_len, -1);
-               ret = lttng_firing_policy_create_from_payload(
+               ret = lttng_rate_policy_create_from_payload(
                                &policy_view, &policy);
                if (ret < 0) {
                        consumed_len = -1;
@@ -218,7 +217,7 @@ ssize_t lttng_action_stop_session_create_from_payload(
        }
 
        assert(policy);
-       status = lttng_action_stop_session_set_firing_policy(action, policy);
+       status = lttng_action_stop_session_set_rate_policy(action, policy);
        if (status != LTTNG_ACTION_STATUS_OK) {
                consumed_len = -1;
                goto end;
@@ -228,7 +227,7 @@ ssize_t lttng_action_stop_session_create_from_payload(
        action = NULL;
 
 end:
-       lttng_firing_policy_destroy(policy);
+       lttng_rate_policy_destroy(policy);
        lttng_action_stop_session_destroy(action);
 
        return consumed_len;
@@ -237,11 +236,11 @@ end:
 struct lttng_action *lttng_action_stop_session_create(void)
 {
        struct lttng_action *action = NULL;
-       struct lttng_firing_policy *policy = NULL;
+       struct lttng_rate_policy *policy = NULL;
        enum lttng_action_status status;
 
-       /* Create a every N = 1 firing policy. */
-       policy = lttng_firing_policy_every_n_create(1);
+       /* Create a every N = 1 rate policy. */
+       policy = lttng_rate_policy_every_n_create(1);
        if (!policy) {
                goto end;
        }
@@ -256,9 +255,9 @@ struct lttng_action *lttng_action_stop_session_create(void)
                        lttng_action_stop_session_serialize,
                        lttng_action_stop_session_is_equal,
                        lttng_action_stop_session_destroy,
-                       lttng_action_stop_session_internal_get_firing_policy);
+                       lttng_action_stop_session_internal_get_rate_policy);
 
-       status = lttng_action_stop_session_set_firing_policy(action, policy);
+       status = lttng_action_stop_session_set_rate_policy(action, policy);
        if (status != LTTNG_ACTION_STATUS_OK) {
                free(action);
                action = NULL;
@@ -266,7 +265,7 @@ struct lttng_action *lttng_action_stop_session_create(void)
        }
 
 end:
-       lttng_firing_policy_destroy(policy);
+       lttng_rate_policy_destroy(policy);
        return action;
 }
 
@@ -317,41 +316,41 @@ end:
        return status;
 }
 
-enum lttng_action_status lttng_action_stop_session_set_firing_policy(
+enum lttng_action_status lttng_action_stop_session_set_rate_policy(
                struct lttng_action *action,
-               const struct lttng_firing_policy *policy)
+               const struct lttng_rate_policy *policy)
 {
        enum lttng_action_status status;
        struct lttng_action_stop_session *stop_session_action;
-       struct lttng_firing_policy *copy = NULL;
+       struct lttng_rate_policy *copy = NULL;
 
        if (!action || !policy || !IS_STOP_SESSION_ACTION(action)) {
                status = LTTNG_ACTION_STATUS_INVALID;
                goto end;
        }
 
-       copy = lttng_firing_policy_copy(policy);
+       copy = lttng_rate_policy_copy(policy);
        if (!copy) {
                status = LTTNG_ACTION_STATUS_ERROR;
                goto end;
        }
        stop_session_action = action_stop_session_from_action(action);
 
-       /* Free the previous firing policy .*/
-       lttng_firing_policy_destroy(stop_session_action->policy);
+       /* Free the previous rate policy .*/
+       lttng_rate_policy_destroy(stop_session_action->policy);
 
        stop_session_action->policy = copy;
        status = LTTNG_ACTION_STATUS_OK;
        copy = NULL;
 
 end:
-       lttng_firing_policy_destroy(copy);
+       lttng_rate_policy_destroy(copy);
        return status;
 }
 
-enum lttng_action_status lttng_action_stop_session_get_firing_policy(
+enum lttng_action_status lttng_action_stop_session_get_rate_policy(
                const struct lttng_action *action,
-               const struct lttng_firing_policy **policy)
+               const struct lttng_rate_policy **policy)
 {
        enum lttng_action_status status;
        const struct lttng_action_stop_session *stop_session_action;
@@ -369,8 +368,8 @@ end:
        return status;
 }
 
-static const struct lttng_firing_policy *
-lttng_action_stop_session_internal_get_firing_policy(
+static const struct lttng_rate_policy *
+lttng_action_stop_session_internal_get_rate_policy(
                const struct lttng_action *action)
 {
        const struct lttng_action_stop_session *_action;
index c66f64d887801fa7d9e49e5ff6d1189fc4555d4e..cc110506f9a4fdc38891c74a7e6a07398ac9d252 100644 (file)
@@ -74,7 +74,7 @@ TESTS += ust/before-after/test_before_after \
        ust/rotation-destroy-flush/test_rotation_destroy_flush \
        tools/metadata/test_ust \
        tools/relayd-grouping/test_ust \
-       tools/trigger/firing-policy/test_ust_firing_policy
+       tools/trigger/rate-policy/test_ust_rate_policy
 
 if IS_LINUX
 TESTS += \
index 914634a0425667212fe0d22dd18190290212bac3..6cd4ef6601dc0f789c9137e30a75e6ca7199ba4e 100644 (file)
@@ -1,4 +1,4 @@
-SUBDIRS=utils start-stop firing-policy
+SUBDIRS=utils start-stop rate-policy
 
 noinst_SCRIPTS = test_add_trigger_cli \
        test_list_triggers_cli \
diff --git a/tests/regression/tools/trigger/firing-policy/Makefile.am b/tests/regression/tools/trigger/firing-policy/Makefile.am
deleted file mode 100644 (file)
index 14d84cb..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-# SPDX-License-Identifier: GPL-2.0-only
-
-noinst_SCRIPTS = test_ust_firing_policy
-
-EXTRA_DIST = test_ust_firing_policy
-
-all-local:
-       @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
-               for script in $(EXTRA_DIST); do \
-                       cp -f $(srcdir)/$$script $(builddir); \
-               done; \
-       fi
-
-clean-local:
-       @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
-               for script in $(EXTRA_DIST); do \
-                       rm -f $(builddir)/$$script; \
-               done; \
-       fi
diff --git a/tests/regression/tools/trigger/firing-policy/test_ust_firing_policy b/tests/regression/tools/trigger/firing-policy/test_ust_firing_policy
deleted file mode 100755 (executable)
index d92dacc..0000000
+++ /dev/null
@@ -1,226 +0,0 @@
-#!/bin/bash
-#
-# Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com>
-#
-# SPDX-License-Identifier: LGPL-2.1-only
-
-TEST_DESC="Triggers - Start and stop actions"
-
-CURDIR=$(dirname "$0")/
-TESTDIR=${CURDIR}/../../../..
-
-# shellcheck source=../../../../utils/utils.sh
-source "$TESTDIR/utils/utils.sh"
-
-TESTAPP_PATH="$TESTDIR/utils/testapp"
-GEN_UST_EVENTS_TESTAPP_NAME="gen-ust-events"
-GEN_UST_EVENTS_TESTAPP_BIN="$TESTAPP_PATH/$GEN_UST_EVENTS_TESTAPP_NAME/$GEN_UST_EVENTS_TESTAPP_NAME"
-NOTIFICATION_CLIENT_BIN="$CURDIR/../utils/notification-client"
-NUM_TESTS=19
-
-NR_ITER=10
-NR_USEC_WAIT=5
-
-function test_firing_policy_every_n()
-{
-       local SESSION_NAME="my_triggered_session"
-       local TRIGGER_NAME="trigger1"
-       local END_TRIGGER_NAME="end-trigger1"
-       local SYNC_AFTER_NOTIF_REGISTER_PATH
-
-       SYNC_AFTER_NOTIF_REGISTER_PATH=$(mktemp -u test-notif-register.XXXXXX)
-
-       diag "Every N firing policy"
-
-       # Add a trigger with a notify action with a policy to fire it every 5
-       # time the condition is met.
-       lttng_add_trigger_ok \
-               $TRIGGER_NAME \
-               --condition on-event -u "tp:tptest" \
-               --action notify \
-               --fire-every 5
-
-       # Add a trigger with a notify action for the tp:end event of the test
-       # application. This allow us to "delimit" the reception loop for the
-       # notification client ensuring that all events were hit and passed into
-       # the notification subsystem. 
-       lttng_add_trigger_ok \
-               $END_TRIGGER_NAME \
-               --condition on-event -u "tp:end" \
-               --action notify
-
-       for i in $(seq 1 4); do
-               diag "Iteration $i of 4"
-               ## Phase 1
-               # Hit the trigger condition 4 time and validate that no (0)
-               # notification for that condition was received.
-               $NOTIFICATION_CLIENT_BIN \
-                       --trigger $TRIGGER_NAME \
-                       --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH" \
-                       --count 0 \
-                       --end-trigger "$END_TRIGGER_NAME" &
-               notif_client_pid=$!
-               while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do
-                       sleep 0.5
-               done
-
-               $GEN_UST_EVENTS_TESTAPP_BIN -i 4 -w $NR_USEC_WAIT --emit-end-event > /dev/null 2>&1
-
-               # notification-client will exit once it receives the end-trigger notification.
-               # Validation of the number of received notification is done by the
-               # notification client. Here it validate that it received 0 notifications.
-               wait $notif_client_pid
-               test "$?" -eq "0"
-               ok $? "notification client exited successfully"
-
-               ## Phase 2 
-               # Hit the condition 1 time and validate that a notification is
-               # received.
-               rm -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}"
-               $NOTIFICATION_CLIENT_BIN \
-                       --trigger $TRIGGER_NAME \
-                       --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH" \
-                       --count 1 \
-                       --end-trigger "$END_TRIGGER_NAME" &
-               notif_client_pid=$!
-               while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do
-                       sleep 0.5
-               done
-
-               # Artificially produce the desired event-rule condition.
-               $GEN_UST_EVENTS_TESTAPP_BIN -i 1 -w $NR_USEC_WAIT --emit-end-event > /dev/null 2>&1
-
-               # notification-client will exit once it receives the end-trigger notification.
-               # Validation of the number of received notification is done by the
-               # notification client. Here it validate that it received 1 notifications.
-               wait $notif_client_pid
-               test "$?" -eq "0"
-               ok $? "notification client exited successfully"
-
-               rm -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}"
-       done
-
-       # Tearing down.
-       lttng_remove_trigger_ok $TRIGGER_NAME
-       lttng_remove_trigger_ok $END_TRIGGER_NAME
-
-       rm -f "$SYNC_AFTER_NOTIF_REGISTER_PATH"
-}
-
-function test_firing_policy_once_after_n()
-{
-       local SESSION_NAME="my_triggered_session"
-       local TRIGGER_NAME="trigger1"
-       local END_TRIGGER_NAME="end-trigger1"
-       local SYNC_AFTER_NOTIF_REGISTER_PATH
-
-       SYNC_AFTER_NOTIF_REGISTER_PATH=$(mktemp -u test-notif-register.XXXXXX)
-
-       diag "Once after N firing policy"
-
-       # Add a trigger with a notify action with a policy to fire it every 5
-       # time the condition is met.
-       lttng_add_trigger_ok \
-               $TRIGGER_NAME \
-               --condition on-event -u "tp:tptest" \
-               --action notify \
-               --fire-once-after 5
-
-       # Add a trigger with a notify action for the tp:end event of the test
-       # application. This allow us to "delimit" the reception loop for the
-       # notification client ensuring that all events were hit and passed into
-       # the notification subsystem. 
-       lttng_add_trigger_ok \
-               $END_TRIGGER_NAME \
-               --condition on-event -u "tp:end" \
-               --action notify
-
-       ## Phase 1
-       # Hit the trigger condition 4 time and validate that no (0)
-       # notification for that condition was received.
-       $NOTIFICATION_CLIENT_BIN \
-               --trigger $TRIGGER_NAME \
-               --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH" \
-               --count 0 \
-               --end-trigger "$END_TRIGGER_NAME" &
-       notif_client_pid=$!
-       while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do
-               sleep 0.5
-       done
-
-       # Artificially produce the desired event-rule condition.
-       $GEN_UST_EVENTS_TESTAPP_BIN -i 4 -w $NR_USEC_WAIT --emit-end-event > /dev/null 2>&1
-
-       # notification-client will exit once it receives the end-trigger notification.
-       # Validation of the number of received notification is done by the
-       # notification client. Here it validate that it received 0 notifications.
-       wait $notif_client_pid
-       test "$?" -eq "0"
-       ok $? "notification client exited successfully"
-
-       ## Phase 2 
-       # Hit the condition 1 time and validate that a notification is
-       # received.
-       rm -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}"
-       $NOTIFICATION_CLIENT_BIN \
-               --trigger $TRIGGER_NAME \
-               --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH" \
-               --count 1 \
-               --end-trigger "$END_TRIGGER_NAME" &
-       notif_client_pid=$!
-       while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do
-               sleep 0.5
-       done
-
-       # Artificially produce the desired event-rule condition.
-       $GEN_UST_EVENTS_TESTAPP_BIN -i 1 -w $NR_USEC_WAIT --emit-end-event > /dev/null 2>&1
-
-       # notification-client will exit once it receives the end-trigger notification.
-       # Validation of the number of received notification is done by the
-       # notification client. Here it validate that it received 1 notifications.
-       wait $notif_client_pid
-       test "$?" -eq "0"
-       ok $? "notification client exited successfully"
-
-       ## Phase 3
-       # Hit the condition N time and validate that no (0) notification is
-       # received.
-       rm -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}"
-       $NOTIFICATION_CLIENT_BIN \
-               --trigger $TRIGGER_NAME \
-               --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH" \
-               --count 0 \
-               --end-trigger "$END_TRIGGER_NAME" &
-       notif_client_pid=$!
-       while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do
-               sleep 0.5
-       done
-
-       # Artificially produce the desired event-rule condition.
-       $GEN_UST_EVENTS_TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --emit-end-event > /dev/null 2>&1
-
-       # notification-client will exit once it receives the end-trigger notification.
-       # Validation of the number of received notification is done by the
-       # notification client. Here it validate that it received 0 notifications.
-       wait $notif_client_pid
-       test "$?" -eq "0"
-       ok $? "notification client exited successfully"
-
-       # Tearing down.
-       lttng_remove_trigger_ok $TRIGGER_NAME
-       lttng_remove_trigger_ok $END_TRIGGER_NAME
-
-       rm -f "$SYNC_AFTER_NOTIF_REGISTER_PATH"
-}
-
- # MUST set TESTDIR before calling those functions
-plan_tests $NUM_TESTS
-
-print_test_banner "$TEST_DESC"
-
-start_lttng_sessiond_notap
-
-test_firing_policy_every_n
-test_firing_policy_once_after_n
-
-stop_lttng_sessiond_notap
diff --git a/tests/regression/tools/trigger/rate-policy/Makefile.am b/tests/regression/tools/trigger/rate-policy/Makefile.am
new file mode 100644 (file)
index 0000000..40ee3b7
--- /dev/null
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+noinst_SCRIPTS = test_ust_rate_policy
+
+EXTRA_DIST = test_ust_rate_policy
+
+all-local:
+       @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
+               for script in $(EXTRA_DIST); do \
+                       cp -f $(srcdir)/$$script $(builddir); \
+               done; \
+       fi
+
+clean-local:
+       @if [ x"$(srcdir)" != x"$(builddir)" ]; then \
+               for script in $(EXTRA_DIST); do \
+                       rm -f $(builddir)/$$script; \
+               done; \
+       fi
diff --git a/tests/regression/tools/trigger/rate-policy/test_ust_rate_policy b/tests/regression/tools/trigger/rate-policy/test_ust_rate_policy
new file mode 100755 (executable)
index 0000000..27d8130
--- /dev/null
@@ -0,0 +1,226 @@
+#!/bin/bash
+#
+# Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com>
+#
+# SPDX-License-Identifier: LGPL-2.1-only
+
+TEST_DESC="Triggers - rate policy notify"
+
+CURDIR=$(dirname "$0")/
+TESTDIR=${CURDIR}/../../../..
+
+# shellcheck source=../../../../utils/utils.sh
+source "$TESTDIR/utils/utils.sh"
+
+TESTAPP_PATH="$TESTDIR/utils/testapp"
+GEN_UST_EVENTS_TESTAPP_NAME="gen-ust-events"
+GEN_UST_EVENTS_TESTAPP_BIN="$TESTAPP_PATH/$GEN_UST_EVENTS_TESTAPP_NAME/$GEN_UST_EVENTS_TESTAPP_NAME"
+NOTIFICATION_CLIENT_BIN="$CURDIR/../utils/notification-client"
+NUM_TESTS=19
+
+NR_ITER=10
+NR_USEC_WAIT=5
+
+function test_rate_policy_every_n()
+{
+       local SESSION_NAME="my_triggered_session"
+       local TRIGGER_NAME="trigger1"
+       local END_TRIGGER_NAME="end-trigger1"
+       local SYNC_AFTER_NOTIF_REGISTER_PATH
+
+       SYNC_AFTER_NOTIF_REGISTER_PATH=$(mktemp -u test-notif-register.XXXXXX)
+
+       diag "Every N rate policy"
+
+       # Add a trigger with a notify action with a policy to fire it every 5
+       # time the condition is met.
+       lttng_add_trigger_ok \
+               $TRIGGER_NAME \
+               --condition on-event -u "tp:tptest" \
+               --action notify \
+               --fire-every 5
+
+       # Add a trigger with a notify action for the tp:end event of the test
+       # application. This allow us to "delimit" the reception loop for the
+       # notification client ensuring that all events were hit and passed into
+       # the notification subsystem. 
+       lttng_add_trigger_ok \
+               $END_TRIGGER_NAME \
+               --condition on-event -u "tp:end" \
+               --action notify
+
+       for i in $(seq 1 4); do
+               diag "Iteration $i of 4"
+               ## Phase 1
+               # Hit the trigger condition 4 time and validate that no (0)
+               # notification for that condition was received.
+               $NOTIFICATION_CLIENT_BIN \
+                       --trigger $TRIGGER_NAME \
+                       --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH" \
+                       --count 0 \
+                       --end-trigger "$END_TRIGGER_NAME" &
+               notif_client_pid=$!
+               while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do
+                       sleep 0.5
+               done
+
+               $GEN_UST_EVENTS_TESTAPP_BIN -i 4 -w $NR_USEC_WAIT --emit-end-event > /dev/null 2>&1
+
+               # notification-client will exit once it receives the end-trigger notification.
+               # Validation of the number of received notification is done by the
+               # notification client. Here it validate that it received 0 notifications.
+               wait $notif_client_pid
+               test "$?" -eq "0"
+               ok $? "notification client exited successfully"
+
+               ## Phase 2 
+               # Hit the condition 1 time and validate that a notification is
+               # received.
+               rm -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}"
+               $NOTIFICATION_CLIENT_BIN \
+                       --trigger $TRIGGER_NAME \
+                       --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH" \
+                       --count 1 \
+                       --end-trigger "$END_TRIGGER_NAME" &
+               notif_client_pid=$!
+               while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do
+                       sleep 0.5
+               done
+
+               # Artificially produce the desired event-rule condition.
+               $GEN_UST_EVENTS_TESTAPP_BIN -i 1 -w $NR_USEC_WAIT --emit-end-event > /dev/null 2>&1
+
+               # notification-client will exit once it receives the end-trigger notification.
+               # Validation of the number of received notification is done by the
+               # notification client. Here it validate that it received 1 notifications.
+               wait $notif_client_pid
+               test "$?" -eq "0"
+               ok $? "notification client exited successfully"
+
+               rm -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}"
+       done
+
+       # Tearing down.
+       lttng_remove_trigger_ok $TRIGGER_NAME
+       lttng_remove_trigger_ok $END_TRIGGER_NAME
+
+       rm -f "$SYNC_AFTER_NOTIF_REGISTER_PATH"
+}
+
+function test_rate_policy_once_after_n()
+{
+       local SESSION_NAME="my_triggered_session"
+       local TRIGGER_NAME="trigger1"
+       local END_TRIGGER_NAME="end-trigger1"
+       local SYNC_AFTER_NOTIF_REGISTER_PATH
+
+       SYNC_AFTER_NOTIF_REGISTER_PATH=$(mktemp -u test-notif-register.XXXXXX)
+
+       diag "Once after N rate policy"
+
+       # Add a trigger with a notify action with a policy to fire it every 5
+       # time the condition is met.
+       lttng_add_trigger_ok \
+               $TRIGGER_NAME \
+               --condition on-event -u "tp:tptest" \
+               --action notify \
+               --fire-once-after 5
+
+       # Add a trigger with a notify action for the tp:end event of the test
+       # application. This allow us to "delimit" the reception loop for the
+       # notification client ensuring that all events were hit and passed into
+       # the notification subsystem. 
+       lttng_add_trigger_ok \
+               $END_TRIGGER_NAME \
+               --condition on-event -u "tp:end" \
+               --action notify
+
+       ## Phase 1
+       # Hit the trigger condition 4 time and validate that no (0)
+       # notification for that condition was received.
+       $NOTIFICATION_CLIENT_BIN \
+               --trigger $TRIGGER_NAME \
+               --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH" \
+               --count 0 \
+               --end-trigger "$END_TRIGGER_NAME" &
+       notif_client_pid=$!
+       while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do
+               sleep 0.5
+       done
+
+       # Artificially produce the desired event-rule condition.
+       $GEN_UST_EVENTS_TESTAPP_BIN -i 4 -w $NR_USEC_WAIT --emit-end-event > /dev/null 2>&1
+
+       # notification-client will exit once it receives the end-trigger notification.
+       # Validation of the number of received notification is done by the
+       # notification client. Here it validate that it received 0 notifications.
+       wait $notif_client_pid
+       test "$?" -eq "0"
+       ok $? "notification client exited successfully"
+
+       ## Phase 2 
+       # Hit the condition 1 time and validate that a notification is
+       # received.
+       rm -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}"
+       $NOTIFICATION_CLIENT_BIN \
+               --trigger $TRIGGER_NAME \
+               --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH" \
+               --count 1 \
+               --end-trigger "$END_TRIGGER_NAME" &
+       notif_client_pid=$!
+       while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do
+               sleep 0.5
+       done
+
+       # Artificially produce the desired event-rule condition.
+       $GEN_UST_EVENTS_TESTAPP_BIN -i 1 -w $NR_USEC_WAIT --emit-end-event > /dev/null 2>&1
+
+       # notification-client will exit once it receives the end-trigger notification.
+       # Validation of the number of received notification is done by the
+       # notification client. Here it validate that it received 1 notifications.
+       wait $notif_client_pid
+       test "$?" -eq "0"
+       ok $? "notification client exited successfully"
+
+       ## Phase 3
+       # Hit the condition N time and validate that no (0) notification is
+       # received.
+       rm -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}"
+       $NOTIFICATION_CLIENT_BIN \
+               --trigger $TRIGGER_NAME \
+               --sync-after-notif-register "$SYNC_AFTER_NOTIF_REGISTER_PATH" \
+               --count 0 \
+               --end-trigger "$END_TRIGGER_NAME" &
+       notif_client_pid=$!
+       while [ ! -f "${SYNC_AFTER_NOTIF_REGISTER_PATH}" ]; do
+               sleep 0.5
+       done
+
+       # Artificially produce the desired event-rule condition.
+       $GEN_UST_EVENTS_TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --emit-end-event > /dev/null 2>&1
+
+       # notification-client will exit once it receives the end-trigger notification.
+       # Validation of the number of received notification is done by the
+       # notification client. Here it validate that it received 0 notifications.
+       wait $notif_client_pid
+       test "$?" -eq "0"
+       ok $? "notification client exited successfully"
+
+       # Tearing down.
+       lttng_remove_trigger_ok $TRIGGER_NAME
+       lttng_remove_trigger_ok $END_TRIGGER_NAME
+
+       rm -f "$SYNC_AFTER_NOTIF_REGISTER_PATH"
+}
+
+ # MUST set TESTDIR before calling those functions
+plan_tests $NUM_TESTS
+
+print_test_banner "$TEST_DESC"
+
+start_lttng_sessiond_notap
+
+test_rate_policy_every_n
+test_rate_policy_once_after_n
+
+stop_lttng_sessiond_notap
index ac7f099251a13781eef3d76bec511225c216c934..fa1af958d7d98346ea78bb723e4a7b2106507745 100755 (executable)
@@ -363,14 +363,14 @@ test_snapshot_action ()
            rule: some-event (type: tracepoint, domain: ust)
            tracer notifications discarded: 0
          actions:
-           snapshot session \`ze-session\`, firing policy: after every 10 occurrences
+           snapshot session \`ze-session\`, rate policy: after every 10 occurrences
        - id: T9
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
            tracer notifications discarded: 0
          actions:
-           snapshot session \`ze-session\`, firing policy: once after 10 occurrences
+           snapshot session \`ze-session\`, rate policy: once after 10 occurrences
        EOF
 
        list_triggers "snapshot action" "${tmp_expected_stdout}"
@@ -393,14 +393,14 @@ test_notify_action ()
            rule: some-event (type: tracepoint, domain: ust)
            tracer notifications discarded: 0
          actions:
-           notify, firing policy: once after 5 occurrences
+           notify, rate policy: once after 5 occurrences
        - id: T1
          user id: ${uid}
          condition: event rule hit
            rule: some-event (type: tracepoint, domain: ust)
            tracer notifications discarded: 0
          actions:
-           notify, firing policy: after every 10 occurrences
+           notify, rate policy: after every 10 occurrences
        EOF
 
        list_triggers "snapshot action" "${tmp_expected_stdout}"
index 10dbd3a608d3b68ecab77e808725ecda1b786b26..2a0f3c9fb6a6c231079a0b937ff439bc1a7894b8 100644 (file)
@@ -16,7 +16,7 @@ TESTS = \
        test_event_expr_to_bytecode \
        test_event_rule \
        test_fd_tracker \
-       test_firing_policy \
+       test_rate_policy \
        test_kernel_data \
        test_kernel_probe \
        test_log_level_rule \
@@ -53,7 +53,7 @@ noinst_PROGRAMS = \
        test_event_expr_to_bytecode \
        test_event_rule \
        test_fd_tracker \
-       test_firing_policy \
+       test_rate_policy \
        test_kernel_data \
        test_kernel_probe \
        test_log_level_rule \
@@ -234,9 +234,9 @@ test_relayd_backward_compat_group_by_session_SOURCES = test_relayd_backward_comp
 test_relayd_backward_compat_group_by_session_LDADD = $(LIBTAP) $(LIBCOMMON) $(RELAYD_OBJS)
 test_relayd_backward_compat_group_by_session_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/src/bin/lttng-relayd
 
-# firing policy object unit test
-test_firing_policy_SOURCES = test_firing_policy.c
-test_firing_policy_LDADD = $(LIBTAP) $(LIBCOMMON) $(LIBLTTNG_CTL) $(DL_LIBS) \
+# rate policy object unit test
+test_rate_policy_SOURCES = test_rate_policy.c
+test_rate_policy_LDADD = $(LIBTAP) $(LIBCOMMON) $(LIBLTTNG_CTL) $(DL_LIBS) \
                      $(top_builddir)/src/bin/lttng/lttng-loglevel.$(OBJEXT)
 
 # fd tracker unit test
index 80e534036c9f03c202026b06962bbc84064753ac..95df311d02e5894df8e990b1830c5afdb8b2cb66 100644 (file)
@@ -21,9 +21,9 @@
 #include <common/payload.h>
 #include <lttng/action/action-internal.h>
 #include <lttng/action/action.h>
-#include <lttng/action/firing-policy-internal.h>
-#include <lttng/action/firing-policy.h>
 #include <lttng/action/notify.h>
+#include <lttng/action/rate-policy-internal.h>
+#include <lttng/action/rate-policy.h>
 #include <lttng/action/rotate-session.h>
 #include <lttng/action/snapshot-session.h>
 #include <lttng/action/start-session.h>
@@ -42,15 +42,15 @@ static void test_action_notify(void)
        enum lttng_action_status status;
        struct lttng_action *notify_action = NULL,
                            *notify_action_from_buffer = NULL;
-       struct lttng_firing_policy *policy = NULL, *default_policy;
+       struct lttng_rate_policy *policy = NULL, *default_policy;
        struct lttng_payload payload;
 
        lttng_payload_init(&payload);
 
        /* To set. */
-       policy = lttng_firing_policy_every_n_create(100);
+       policy = lttng_rate_policy_every_n_create(100);
        /* For comparison. */
-       default_policy = lttng_firing_policy_every_n_create(1);
+       default_policy = lttng_rate_policy_every_n_create(1);
 
        assert(policy && default_policy);
 
@@ -61,27 +61,27 @@ static void test_action_notify(void)
 
        /* Validate the default policy for a notify action. */
        {
-               const struct lttng_firing_policy *cur_policy = NULL;
-               status = lttng_action_notify_get_firing_policy(
+               const struct lttng_rate_policy *cur_policy = NULL;
+               status = lttng_action_notify_get_rate_policy(
                                notify_action, &cur_policy);
                ok(status == LTTNG_ACTION_STATUS_OK &&
-                                               lttng_firing_policy_is_equal(
+                                               lttng_rate_policy_is_equal(
                                                                default_policy,
                                                                cur_policy),
                                "Default policy is every n=1");
        }
 
        /* Set a custom policy. */
-       status = lttng_action_notify_set_firing_policy(notify_action, policy);
-       ok(status == LTTNG_ACTION_STATUS_OK, "Set firing policy");
+       status = lttng_action_notify_set_rate_policy(notify_action, policy);
+       ok(status == LTTNG_ACTION_STATUS_OK, "Set rate policy");
 
        /* Validate the custom policy for a notify action. */
        {
-               const struct lttng_firing_policy *cur_policy = NULL;
-               status = lttng_action_notify_get_firing_policy(
+               const struct lttng_rate_policy *cur_policy = NULL;
+               status = lttng_action_notify_get_rate_policy(
                                notify_action, &cur_policy);
                ok(status == LTTNG_ACTION_STATUS_OK &&
-                                               lttng_firing_policy_is_equal(
+                                               lttng_rate_policy_is_equal(
                                                                policy,
                                                                cur_policy),
                                "Notify action policy get");
@@ -103,8 +103,8 @@ static void test_action_notify(void)
        ok(lttng_action_is_equal(notify_action, notify_action_from_buffer),
                        "Serialized and de-serialized notify action are equal");
 
-       lttng_firing_policy_destroy(default_policy);
-       lttng_firing_policy_destroy(policy);
+       lttng_rate_policy_destroy(default_policy);
+       lttng_rate_policy_destroy(policy);
        lttng_action_destroy(notify_action);
        lttng_action_destroy(notify_action_from_buffer);
        lttng_payload_reset(&payload);
@@ -116,7 +116,7 @@ static void test_action_rotate_session(void)
        enum lttng_action_status status;
        struct lttng_action *rotate_session_action = NULL,
                            *rotate_session_action_from_buffer = NULL;
-       struct lttng_firing_policy *policy = NULL, *default_policy;
+       struct lttng_rate_policy *policy = NULL, *default_policy;
        struct lttng_payload payload;
        const char *session_name = "my_session_name";
        const char *get_session_name;
@@ -124,9 +124,9 @@ static void test_action_rotate_session(void)
        lttng_payload_init(&payload);
 
        /* To set. */
-       policy = lttng_firing_policy_every_n_create(100);
+       policy = lttng_rate_policy_every_n_create(100);
        /* For comparison. */
-       default_policy = lttng_firing_policy_every_n_create(1);
+       default_policy = lttng_rate_policy_every_n_create(1);
 
        assert(policy && default_policy);
 
@@ -163,28 +163,28 @@ static void test_action_rotate_session(void)
 
        /* Validate the default policy for a rotate_session action. */
        {
-               const struct lttng_firing_policy *cur_policy = NULL;
-               status = lttng_action_rotate_session_get_firing_policy(
+               const struct lttng_rate_policy *cur_policy = NULL;
+               status = lttng_action_rotate_session_get_rate_policy(
                                rotate_session_action, &cur_policy);
                ok(status == LTTNG_ACTION_STATUS_OK &&
-                                               lttng_firing_policy_is_equal(
+                                               lttng_rate_policy_is_equal(
                                                                default_policy,
                                                                cur_policy),
                                "Default policy is every n=1");
        }
 
        /* Set a custom policy. */
-       status = lttng_action_rotate_session_set_firing_policy(
+       status = lttng_action_rotate_session_set_rate_policy(
                        rotate_session_action, policy);
-       ok(status == LTTNG_ACTION_STATUS_OK, "Set firing policy");
+       ok(status == LTTNG_ACTION_STATUS_OK, "Set rate policy");
 
        /* Validate the custom policy for a rotate_session action. */
        {
-               const struct lttng_firing_policy *cur_policy = NULL;
-               status = lttng_action_rotate_session_get_firing_policy(
+               const struct lttng_rate_policy *cur_policy = NULL;
+               status = lttng_action_rotate_session_get_rate_policy(
                                rotate_session_action, &cur_policy);
                ok(status == LTTNG_ACTION_STATUS_OK &&
-                                               lttng_firing_policy_is_equal(
+                                               lttng_rate_policy_is_equal(
                                                                policy,
                                                                cur_policy),
                                "rotate_session action policy get");
@@ -208,8 +208,8 @@ static void test_action_rotate_session(void)
                           rotate_session_action_from_buffer),
                        "Serialized and de-serialized rotate_session action are equal");
 
-       lttng_firing_policy_destroy(default_policy);
-       lttng_firing_policy_destroy(policy);
+       lttng_rate_policy_destroy(default_policy);
+       lttng_rate_policy_destroy(policy);
        lttng_action_destroy(rotate_session_action);
        lttng_action_destroy(rotate_session_action_from_buffer);
        lttng_payload_reset(&payload);
@@ -221,7 +221,7 @@ static void test_action_start_session(void)
        enum lttng_action_status status;
        struct lttng_action *start_session_action = NULL,
                            *start_session_action_from_buffer = NULL;
-       struct lttng_firing_policy *policy = NULL, *default_policy;
+       struct lttng_rate_policy *policy = NULL, *default_policy;
        struct lttng_payload payload;
        const char *session_name = "my_session_name";
        const char *get_session_name;
@@ -229,9 +229,9 @@ static void test_action_start_session(void)
        lttng_payload_init(&payload);
 
        /* To set. */
-       policy = lttng_firing_policy_every_n_create(100);
+       policy = lttng_rate_policy_every_n_create(100);
        /* For comparison. */
-       default_policy = lttng_firing_policy_every_n_create(1);
+       default_policy = lttng_rate_policy_every_n_create(1);
 
        assert(policy && default_policy);
 
@@ -268,28 +268,28 @@ static void test_action_start_session(void)
 
        /* Validate the default policy for a start_session action. */
        {
-               const struct lttng_firing_policy *cur_policy = NULL;
-               status = lttng_action_start_session_get_firing_policy(
+               const struct lttng_rate_policy *cur_policy = NULL;
+               status = lttng_action_start_session_get_rate_policy(
                                start_session_action, &cur_policy);
                ok(status == LTTNG_ACTION_STATUS_OK &&
-                                               lttng_firing_policy_is_equal(
+                                               lttng_rate_policy_is_equal(
                                                                default_policy,
                                                                cur_policy),
                                "Default policy is every n=1");
        }
 
        /* Set a custom policy. */
-       status = lttng_action_start_session_set_firing_policy(
+       status = lttng_action_start_session_set_rate_policy(
                        start_session_action, policy);
-       ok(status == LTTNG_ACTION_STATUS_OK, "Set firing policy");
+       ok(status == LTTNG_ACTION_STATUS_OK, "Set rate policy");
 
        /* Validate the custom policy for a start_session action. */
        {
-               const struct lttng_firing_policy *cur_policy = NULL;
-               status = lttng_action_start_session_get_firing_policy(
+               const struct lttng_rate_policy *cur_policy = NULL;
+               status = lttng_action_start_session_get_rate_policy(
                                start_session_action, &cur_policy);
                ok(status == LTTNG_ACTION_STATUS_OK &&
-                                               lttng_firing_policy_is_equal(
+                                               lttng_rate_policy_is_equal(
                                                                policy,
                                                                cur_policy),
                                "start_session action policy get");
@@ -313,8 +313,8 @@ static void test_action_start_session(void)
                           start_session_action_from_buffer),
                        "Serialized and de-serialized start_session action are equal");
 
-       lttng_firing_policy_destroy(default_policy);
-       lttng_firing_policy_destroy(policy);
+       lttng_rate_policy_destroy(default_policy);
+       lttng_rate_policy_destroy(policy);
        lttng_action_destroy(start_session_action);
        lttng_action_destroy(start_session_action_from_buffer);
        lttng_payload_reset(&payload);
@@ -326,7 +326,7 @@ static void test_action_stop_session(void)
        enum lttng_action_status status;
        struct lttng_action *stop_session_action = NULL,
                            *stop_session_action_from_buffer = NULL;
-       struct lttng_firing_policy *policy = NULL, *default_policy;
+       struct lttng_rate_policy *policy = NULL, *default_policy;
        struct lttng_payload payload;
        const char *session_name = "my_session_name";
        const char *get_session_name;
@@ -334,9 +334,9 @@ static void test_action_stop_session(void)
        lttng_payload_init(&payload);
 
        /* To set. */
-       policy = lttng_firing_policy_every_n_create(100);
+       policy = lttng_rate_policy_every_n_create(100);
        /* For comparison. */
-       default_policy = lttng_firing_policy_every_n_create(1);
+       default_policy = lttng_rate_policy_every_n_create(1);
 
        assert(policy && default_policy);
 
@@ -372,28 +372,28 @@ static void test_action_stop_session(void)
 
        /* Validate the default policy for a stop_session action. */
        {
-               const struct lttng_firing_policy *cur_policy = NULL;
-               status = lttng_action_stop_session_get_firing_policy(
+               const struct lttng_rate_policy *cur_policy = NULL;
+               status = lttng_action_stop_session_get_rate_policy(
                                stop_session_action, &cur_policy);
                ok(status == LTTNG_ACTION_STATUS_OK &&
-                                               lttng_firing_policy_is_equal(
+                                               lttng_rate_policy_is_equal(
                                                                default_policy,
                                                                cur_policy),
                                "Default policy is every n=1");
        }
 
        /* Set a custom policy. */
-       status = lttng_action_stop_session_set_firing_policy(
+       status = lttng_action_stop_session_set_rate_policy(
                        stop_session_action, policy);
-       ok(status == LTTNG_ACTION_STATUS_OK, "Set firing policy");
+       ok(status == LTTNG_ACTION_STATUS_OK, "Set rate policy");
 
        /* Validate the custom policy for a stop_session action. */
        {
-               const struct lttng_firing_policy *cur_policy = NULL;
-               status = lttng_action_stop_session_get_firing_policy(
+               const struct lttng_rate_policy *cur_policy = NULL;
+               status = lttng_action_stop_session_get_rate_policy(
                                stop_session_action, &cur_policy);
                ok(status == LTTNG_ACTION_STATUS_OK &&
-                                               lttng_firing_policy_is_equal(
+                                               lttng_rate_policy_is_equal(
                                                                policy,
                                                                cur_policy),
                                "stop_session action policy get");
@@ -417,8 +417,8 @@ static void test_action_stop_session(void)
                           stop_session_action_from_buffer),
                        "Serialized and de-serialized stop_session action are equal");
 
-       lttng_firing_policy_destroy(default_policy);
-       lttng_firing_policy_destroy(policy);
+       lttng_rate_policy_destroy(default_policy);
+       lttng_rate_policy_destroy(policy);
        lttng_action_destroy(stop_session_action);
        lttng_action_destroy(stop_session_action_from_buffer);
        lttng_payload_reset(&payload);
@@ -430,7 +430,7 @@ static void test_action_snapshot_session(void)
        enum lttng_action_status status;
        struct lttng_action *snapshot_session_action = NULL,
                            *snapshot_session_action_from_buffer = NULL;
-       struct lttng_firing_policy *policy = NULL, *default_policy;
+       struct lttng_rate_policy *policy = NULL, *default_policy;
        struct lttng_payload payload;
        const char *session_name = "my_session_name";
        const char *get_session_name;
@@ -438,9 +438,9 @@ static void test_action_snapshot_session(void)
        lttng_payload_init(&payload);
 
        /* To set. */
-       policy = lttng_firing_policy_every_n_create(100);
+       policy = lttng_rate_policy_every_n_create(100);
        /* For comparison. */
-       default_policy = lttng_firing_policy_every_n_create(1);
+       default_policy = lttng_rate_policy_every_n_create(1);
 
        assert(policy && default_policy);
 
@@ -477,28 +477,28 @@ static void test_action_snapshot_session(void)
 
        /* Validate the default policy for a snapshot_session action. */
        {
-               const struct lttng_firing_policy *cur_policy = NULL;
-               status = lttng_action_snapshot_session_get_firing_policy(
+               const struct lttng_rate_policy *cur_policy = NULL;
+               status = lttng_action_snapshot_session_get_rate_policy(
                                snapshot_session_action, &cur_policy);
                ok(status == LTTNG_ACTION_STATUS_OK &&
-                                               lttng_firing_policy_is_equal(
+                                               lttng_rate_policy_is_equal(
                                                                default_policy,
                                                                cur_policy),
                                "Default policy is every n=1");
        }
 
        /* Set a custom policy. */
-       status = lttng_action_snapshot_session_set_firing_policy(
+       status = lttng_action_snapshot_session_set_rate_policy(
                        snapshot_session_action, policy);
-       ok(status == LTTNG_ACTION_STATUS_OK, "Set firing policy");
+       ok(status == LTTNG_ACTION_STATUS_OK, "Set rate policy");
 
        /* Validate the custom policy for a snapshot_session action. */
        {
-               const struct lttng_firing_policy *cur_policy = NULL;
-               status = lttng_action_snapshot_session_get_firing_policy(
+               const struct lttng_rate_policy *cur_policy = NULL;
+               status = lttng_action_snapshot_session_get_rate_policy(
                                snapshot_session_action, &cur_policy);
                ok(status == LTTNG_ACTION_STATUS_OK &&
-                                               lttng_firing_policy_is_equal(
+                                               lttng_rate_policy_is_equal(
                                                                policy,
                                                                cur_policy),
                                "snapshot_session action policy get");
@@ -522,8 +522,8 @@ static void test_action_snapshot_session(void)
                           snapshot_session_action_from_buffer),
                        "Serialized and de-serialized snapshot_session action are equal");
 
-       lttng_firing_policy_destroy(default_policy);
-       lttng_firing_policy_destroy(policy);
+       lttng_rate_policy_destroy(default_policy);
+       lttng_rate_policy_destroy(policy);
        lttng_action_destroy(snapshot_session_action);
        lttng_action_destroy(snapshot_session_action_from_buffer);
        lttng_payload_reset(&payload);
diff --git a/tests/unit/test_firing_policy.c b/tests/unit/test_firing_policy.c
deleted file mode 100644 (file)
index e7504c2..0000000
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * Unit tests for the firing policy object API.
- *
- * Copyright (C) 2019 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
- *
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- */
-
-#include <assert.h>
-#include <inttypes.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <tap/tap.h>
-
-#include <common/payload-view.h>
-#include <common/payload.h>
-#include <lttng/action/firing-policy-internal.h>
-#include <lttng/action/firing-policy.h>
-
-/* For error.h. */
-int lttng_opt_quiet = 1;
-int lttng_opt_verbose;
-int lttng_opt_mi;
-
-#define NUM_TESTS 42
-
-static void test_firing_policy_every_n(void)
-{
-       enum lttng_firing_policy_status status;
-       struct lttng_firing_policy *policy_a = NULL; /* Interval of 100. */
-       struct lttng_firing_policy *policy_b = NULL; /* Interval of 100. */
-       struct lttng_firing_policy *policy_c = NULL; /* Interval of 1. */
-       struct lttng_firing_policy *policy_from_buffer = NULL;
-       uint64_t interval_a_b = 100;
-       uint64_t interval_c = 1;
-       uint64_t interval_query = 0;
-       struct lttng_payload payload;
-
-       lttng_payload_init(&payload);
-
-       policy_a = lttng_firing_policy_every_n_create(interval_a_b);
-       policy_b = lttng_firing_policy_every_n_create(interval_a_b);
-       policy_c = lttng_firing_policy_every_n_create(interval_c);
-       ok(policy_a != NULL,
-                       "Firing policy 'every n' A created: interval: %" PRIu64,
-                       interval_a_b);
-       ok(policy_b != NULL,
-                       "Firing policy 'every n' B created: interval: %" PRIu64,
-                       interval_a_b);
-       ok(policy_c != NULL,
-                       "Firing policy 'every n' C created: interval: %" PRIu64,
-                       interval_c);
-
-       ok(LTTNG_FIRING_POLICY_TYPE_EVERY_N ==
-                                       lttng_firing_policy_get_type(policy_a),
-                       "Type is LTTNG_FIRING_POLICY_TYPE_EVERY_N");
-
-       /* Getter tests */
-       status = lttng_firing_policy_every_n_get_interval(NULL, NULL);
-       ok(status == LTTNG_FIRING_POLICY_STATUS_INVALID,
-                       "Get interval returns INVALID");
-
-       status = lttng_firing_policy_every_n_get_interval(
-                       NULL, &interval_query);
-       ok(status == LTTNG_FIRING_POLICY_STATUS_INVALID,
-                       "Get interval returns INVALID");
-
-       status = lttng_firing_policy_every_n_get_interval(policy_a, NULL);
-       ok(status == LTTNG_FIRING_POLICY_STATUS_INVALID,
-                       "Get interval returns INVALID");
-
-       status = lttng_firing_policy_every_n_get_interval(
-                       policy_a, &interval_query);
-       ok(status == LTTNG_FIRING_POLICY_STATUS_OK &&
-                                       interval_query == interval_a_b,
-                       "Getting interval A");
-
-       status = lttng_firing_policy_every_n_get_interval(
-                       policy_b, &interval_query);
-       ok(status == LTTNG_FIRING_POLICY_STATUS_OK &&
-                                       interval_query == interval_a_b,
-                       "Getting interval B");
-
-       status = lttng_firing_policy_every_n_get_interval(
-                       policy_c, &interval_query);
-       ok(status == LTTNG_FIRING_POLICY_STATUS_OK &&
-                                       interval_query == interval_c,
-                       "Getting interval C");
-
-       /* is_equal tests */
-       ok(false == lttng_firing_policy_is_equal(NULL, NULL),
-                       "is equal (NULL,NULL)");
-       ok(false == lttng_firing_policy_is_equal(policy_a, NULL),
-                       "is equal (object, NULL)");
-       ok(false == lttng_firing_policy_is_equal(NULL, policy_a),
-                       "is equal (NULL, object)");
-       ok(true == lttng_firing_policy_is_equal(policy_a, policy_a),
-                       "is equal (object A, object A)");
-
-       ok(true == lttng_firing_policy_is_equal(policy_a, policy_b),
-                       "is equal (object A, object B");
-       ok(true == lttng_firing_policy_is_equal(policy_b, policy_a),
-                       "is equal (object B, object A");
-
-       ok(false == lttng_firing_policy_is_equal(policy_a, policy_c),
-                       "is equal (object A, object C)");
-       ok(false == lttng_firing_policy_is_equal(policy_c, policy_a),
-                       "is equal (object C, object A)");
-
-       /* Serialization and create_from buffer. */
-       ok(lttng_firing_policy_serialize(policy_a, &payload) == 0,
-                       "Serializing firing policy");
-       {
-               struct lttng_payload_view view =
-                               lttng_payload_view_from_payload(
-                                               &payload, 0, -1);
-
-               ok(lttng_firing_policy_create_from_payload(
-                                  &view, &policy_from_buffer) > 0 &&
-                                               policy_from_buffer != NULL,
-                               "Deserializing firing policy");
-       }
-
-       ok(lttng_firing_policy_is_equal(policy_a, policy_from_buffer),
-                       "Original and deserialized instances are equal");
-
-       lttng_firing_policy_destroy(policy_a);
-       lttng_firing_policy_destroy(policy_b);
-       lttng_firing_policy_destroy(policy_c);
-       lttng_firing_policy_destroy(policy_from_buffer);
-       lttng_payload_reset(&payload);
-}
-
-static void test_firing_policy_once_after_n(void)
-{
-       enum lttng_firing_policy_status status;
-       struct lttng_firing_policy *policy_a = NULL; /* Threshold of 100. */
-       struct lttng_firing_policy *policy_b = NULL; /* threshold of 100 */
-       struct lttng_firing_policy *policy_c = NULL; /* threshold of 1 */
-       struct lttng_firing_policy *policy_from_buffer = NULL;
-       uint64_t threshold_a_b = 100;
-       uint64_t threshold_c = 1;
-       uint64_t threshold_query = 0;
-       struct lttng_payload payload;
-
-       lttng_payload_init(&payload);
-
-       policy_a = lttng_firing_policy_once_after_n_create(threshold_a_b);
-       policy_b = lttng_firing_policy_once_after_n_create(threshold_a_b);
-       policy_c = lttng_firing_policy_once_after_n_create(threshold_c);
-       ok(policy_a != NULL,
-                       "Firing policy every n A created: threshold: %" PRIu64,
-                       threshold_a_b);
-       ok(policy_b != NULL,
-                       "Firing policy every n B created: threshold: %" PRIu64,
-                       threshold_a_b);
-       ok(policy_c != NULL,
-                       "Firing policy every n C created: threshold: %" PRIu64,
-                       threshold_c);
-
-       ok(LTTNG_FIRING_POLICY_TYPE_ONCE_AFTER_N ==
-                                       lttng_firing_policy_get_type(policy_a),
-                       "Type is LTTNG_FIRING_POLICY_TYPE_once_after_n");
-
-       /* Getter tests */
-       status = lttng_firing_policy_once_after_n_get_threshold(NULL, NULL);
-       ok(status == LTTNG_FIRING_POLICY_STATUS_INVALID,
-                       "Get threshold returns INVALID");
-
-       status = lttng_firing_policy_once_after_n_get_threshold(
-                       NULL, &threshold_query);
-       ok(status == LTTNG_FIRING_POLICY_STATUS_INVALID,
-                       "Get threshold returns INVALID");
-
-       status = lttng_firing_policy_once_after_n_get_threshold(policy_a, NULL);
-       ok(status == LTTNG_FIRING_POLICY_STATUS_INVALID,
-                       "Get threshold returns INVALID");
-
-       status = lttng_firing_policy_once_after_n_get_threshold(
-                       policy_a, &threshold_query);
-       ok(status == LTTNG_FIRING_POLICY_STATUS_OK &&
-                                       threshold_query == threshold_a_b,
-                       "Getting threshold A");
-
-       status = lttng_firing_policy_once_after_n_get_threshold(
-                       policy_b, &threshold_query);
-       ok(status == LTTNG_FIRING_POLICY_STATUS_OK &&
-                                       threshold_query == threshold_a_b,
-                       "Getting threshold B");
-
-       status = lttng_firing_policy_once_after_n_get_threshold(
-                       policy_c, &threshold_query);
-       ok(status == LTTNG_FIRING_POLICY_STATUS_OK &&
-                                       threshold_query == threshold_c,
-                       "Getting threshold C");
-
-       /* is_equal tests */
-       ok(false == lttng_firing_policy_is_equal(NULL, NULL),
-                       "is equal (NULL,NULL)");
-       ok(false == lttng_firing_policy_is_equal(policy_a, NULL),
-                       "is equal (object, NULL)");
-       ok(false == lttng_firing_policy_is_equal(NULL, policy_a),
-                       "is equal (NULL, object)");
-       ok(true == lttng_firing_policy_is_equal(policy_a, policy_a),
-                       "is equal (object A, object A)");
-
-       ok(true == lttng_firing_policy_is_equal(policy_a, policy_b),
-                       "is equal (object A, object B");
-       ok(true == lttng_firing_policy_is_equal(policy_b, policy_a),
-                       "is equal (object B, object A");
-
-       ok(false == lttng_firing_policy_is_equal(policy_a, policy_c),
-                       "is equal (object A, object C)");
-       ok(false == lttng_firing_policy_is_equal(policy_c, policy_a),
-                       "is equal (object C, object A)");
-
-       /* Serialization and create_from buffer. */
-       ok(lttng_firing_policy_serialize(policy_a, &payload) == 0,
-                       "Serializing firing policy");
-       {
-               struct lttng_payload_view view =
-                               lttng_payload_view_from_payload(
-                                               &payload, 0, -1);
-
-               ok(lttng_firing_policy_create_from_payload(
-                                  &view, &policy_from_buffer) > 0 &&
-                                               policy_from_buffer != NULL,
-                               "Deserializing firing policy");
-       }
-
-       ok(lttng_firing_policy_is_equal(policy_a, policy_from_buffer),
-                       "Original and deserialized instances are equal");
-
-       lttng_firing_policy_destroy(policy_a);
-       lttng_firing_policy_destroy(policy_b);
-       lttng_firing_policy_destroy(policy_c);
-       lttng_firing_policy_destroy(policy_from_buffer);
-       lttng_payload_reset(&payload);
-}
-
-int main(int argc, const char *argv[])
-{
-       plan_tests(NUM_TESTS);
-       test_firing_policy_every_n();
-       test_firing_policy_once_after_n();
-       return exit_status();
-}
diff --git a/tests/unit/test_rate_policy.c b/tests/unit/test_rate_policy.c
new file mode 100644 (file)
index 0000000..fcb2773
--- /dev/null
@@ -0,0 +1,253 @@
+/*
+ * Unit tests for the rate policy object API.
+ *
+ * Copyright (C) 2019 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
+ *
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ */
+
+#include <assert.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <tap/tap.h>
+
+#include <common/payload-view.h>
+#include <common/payload.h>
+#include <lttng/action/rate-policy-internal.h>
+#include <lttng/action/rate-policy.h>
+
+/* For error.h. */
+int lttng_opt_quiet = 1;
+int lttng_opt_verbose;
+int lttng_opt_mi;
+
+#define NUM_TESTS 42
+
+static void test_rate_policy_every_n(void)
+{
+       enum lttng_rate_policy_status status;
+       struct lttng_rate_policy *policy_a = NULL; /* Interval of 100. */
+       struct lttng_rate_policy *policy_b = NULL; /* Interval of 100 */
+       struct lttng_rate_policy *policy_c = NULL; /* Interval of 1 */
+       struct lttng_rate_policy *policy_from_buffer = NULL;
+       uint64_t interval_a_b = 100;
+       uint64_t interval_c = 1;
+       uint64_t interval_query = 0;
+       struct lttng_payload payload;
+
+       lttng_payload_init(&payload);
+
+       policy_a = lttng_rate_policy_every_n_create(interval_a_b);
+       policy_b = lttng_rate_policy_every_n_create(interval_a_b);
+       policy_c = lttng_rate_policy_every_n_create(interval_c);
+       ok(policy_a != NULL,
+                       "Rate policy every n A created: interval: %" PRIu64,
+                       interval_a_b);
+       ok(policy_b != NULL,
+                       "Rate policy every n B created: interval: %" PRIu64,
+                       interval_a_b);
+       ok(policy_c != NULL,
+                       "Rate policy every n C created: interval: %" PRIu64,
+                       interval_c);
+
+       ok(LTTNG_RATE_POLICY_TYPE_EVERY_N ==
+                                       lttng_rate_policy_get_type(policy_a),
+                       "Type is LTTNG_RATE_POLICY_TYPE_EVERY_N");
+
+       /* Getter tests */
+       status = lttng_rate_policy_every_n_get_interval(NULL, NULL);
+       ok(status == LTTNG_RATE_POLICY_STATUS_INVALID,
+                       "Get interval returns INVALID");
+
+       status = lttng_rate_policy_every_n_get_interval(NULL, &interval_query);
+       ok(status == LTTNG_RATE_POLICY_STATUS_INVALID,
+                       "Get interval returns INVALID");
+
+       status = lttng_rate_policy_every_n_get_interval(policy_a, NULL);
+       ok(status == LTTNG_RATE_POLICY_STATUS_INVALID,
+                       "Get interval returns INVALID");
+
+       status = lttng_rate_policy_every_n_get_interval(
+                       policy_a, &interval_query);
+       ok(status == LTTNG_RATE_POLICY_STATUS_OK &&
+                                       interval_query == interval_a_b,
+                       " Getting interval A");
+
+       status = lttng_rate_policy_every_n_get_interval(
+                       policy_b, &interval_query);
+       ok(status == LTTNG_RATE_POLICY_STATUS_OK &&
+                                       interval_query == interval_a_b,
+                       " Getting interval B");
+
+       status = lttng_rate_policy_every_n_get_interval(
+                       policy_c, &interval_query);
+       ok(status == LTTNG_RATE_POLICY_STATUS_OK &&
+                                       interval_query == interval_c,
+                       " Getting interval C");
+
+       /* is_equal tests */
+       /* TODO: this is the behaviour introduced by the
+        * lttng_condition_is_equal back in 2017 do we want to fix this and
+        * return true if both are NULL?
+        */
+       ok(false == lttng_rate_policy_is_equal(NULL, NULL),
+                       "is equal (NULL,NULL)");
+       ok(false == lttng_rate_policy_is_equal(policy_a, NULL),
+                       "is equal (object, NULL)");
+       ok(false == lttng_rate_policy_is_equal(NULL, policy_a),
+                       " is equal (NULL, object)");
+       ok(true == lttng_rate_policy_is_equal(policy_a, policy_a),
+                       "is equal (object A, object A)");
+
+       ok(true == lttng_rate_policy_is_equal(policy_a, policy_b),
+                       "is equal (object A, object B");
+       ok(true == lttng_rate_policy_is_equal(policy_b, policy_a),
+                       "is equal (object B, object A");
+
+       ok(false == lttng_rate_policy_is_equal(policy_a, policy_c),
+                       "is equal (object A, object C)");
+       ok(false == lttng_rate_policy_is_equal(policy_c, policy_a),
+                       "is equal (object C, object A)");
+
+       /* Serialization and create_from buffer. */
+       ok(lttng_rate_policy_serialize(policy_a, &payload) == 0, "Serializing");
+       {
+               struct lttng_payload_view view =
+                               lttng_payload_view_from_payload(
+                                               &payload, 0, -1);
+
+               ok(lttng_rate_policy_create_from_payload(
+                                  &view, &policy_from_buffer) > 0 &&
+                                               policy_from_buffer != NULL,
+                               "Deserializing");
+       }
+
+       ok(lttng_rate_policy_is_equal(policy_a, policy_from_buffer),
+                       "serialized and from buffer are equal");
+
+       lttng_rate_policy_destroy(policy_a);
+       lttng_rate_policy_destroy(policy_b);
+       lttng_rate_policy_destroy(policy_c);
+       lttng_payload_reset(&payload);
+}
+
+static void test_rate_policy_once_after_n(void)
+{
+       enum lttng_rate_policy_status status;
+       struct lttng_rate_policy *policy_a = NULL; /* Threshold of 100. */
+       struct lttng_rate_policy *policy_b = NULL; /* threshold of 100 */
+       struct lttng_rate_policy *policy_c = NULL; /* threshold of 1 */
+       struct lttng_rate_policy *policy_from_buffer = NULL;
+       uint64_t threshold_a_b = 100;
+       uint64_t threshold_c = 1;
+       uint64_t threshold_query = 0;
+       struct lttng_payload payload;
+
+       lttng_payload_init(&payload);
+
+       policy_a = lttng_rate_policy_once_after_n_create(threshold_a_b);
+       policy_b = lttng_rate_policy_once_after_n_create(threshold_a_b);
+       policy_c = lttng_rate_policy_once_after_n_create(threshold_c);
+       ok(policy_a != NULL,
+                       "Rate policy every n A created: threshold: %" PRIu64,
+                       threshold_a_b);
+       ok(policy_b != NULL,
+                       "Rate policy every n B created: threshold: %" PRIu64,
+                       threshold_a_b);
+       ok(policy_c != NULL,
+                       "Rate policy every n C created: threshold: %" PRIu64,
+                       threshold_c);
+
+       ok(LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N ==
+                                       lttng_rate_policy_get_type(policy_a),
+                       "Type is LTTNG_RATE_POLICY_TYPE_once_after_n");
+
+       /* Getter tests */
+       status = lttng_rate_policy_once_after_n_get_threshold(NULL, NULL);
+       ok(status == LTTNG_RATE_POLICY_STATUS_INVALID,
+                       "Get threshold returns INVALID");
+
+       status = lttng_rate_policy_once_after_n_get_threshold(
+                       NULL, &threshold_query);
+       ok(status == LTTNG_RATE_POLICY_STATUS_INVALID,
+                       "Get threshold returns INVALID");
+
+       status = lttng_rate_policy_once_after_n_get_threshold(policy_a, NULL);
+       ok(status == LTTNG_RATE_POLICY_STATUS_INVALID,
+                       "Get threshold returns INVALID");
+
+       status = lttng_rate_policy_once_after_n_get_threshold(
+                       policy_a, &threshold_query);
+       ok(status == LTTNG_RATE_POLICY_STATUS_OK &&
+                                       threshold_query == threshold_a_b,
+                       " Getting threshold A");
+
+       status = lttng_rate_policy_once_after_n_get_threshold(
+                       policy_b, &threshold_query);
+       ok(status == LTTNG_RATE_POLICY_STATUS_OK &&
+                                       threshold_query == threshold_a_b,
+                       " Getting threshold B");
+
+       status = lttng_rate_policy_once_after_n_get_threshold(
+                       policy_c, &threshold_query);
+       ok(status == LTTNG_RATE_POLICY_STATUS_OK &&
+                                       threshold_query == threshold_c,
+                       " Getting threshold C");
+
+       /* is_equal tests */
+       /* TODO: this is the behaviour introduced by the
+        * lttng_condition_is_equal back in 2017 do we want to fix this and
+        * return true if both are NULL?
+        */
+       ok(false == lttng_rate_policy_is_equal(NULL, NULL),
+                       "is equal (NULL,NULL)");
+       ok(false == lttng_rate_policy_is_equal(policy_a, NULL),
+                       "is equal (object, NULL)");
+       ok(false == lttng_rate_policy_is_equal(NULL, policy_a),
+                       " is equal (NULL, object)");
+       ok(true == lttng_rate_policy_is_equal(policy_a, policy_a),
+                       "is equal (object A, object A)");
+
+       ok(true == lttng_rate_policy_is_equal(policy_a, policy_b),
+                       "is equal (object A, object B");
+       ok(true == lttng_rate_policy_is_equal(policy_b, policy_a),
+                       "is equal (object B, object A");
+
+       ok(false == lttng_rate_policy_is_equal(policy_a, policy_c),
+                       "is equal (object A, object C)");
+       ok(false == lttng_rate_policy_is_equal(policy_c, policy_a),
+                       "is equal (object C, object A)");
+
+       /* Serialization and create_from buffer. */
+       ok(lttng_rate_policy_serialize(policy_a, &payload) == 0, "Serializing");
+       {
+               struct lttng_payload_view view =
+                               lttng_payload_view_from_payload(
+                                               &payload, 0, -1);
+
+               ok(lttng_rate_policy_create_from_payload(
+                                  &view, &policy_from_buffer) > 0 &&
+                                               policy_from_buffer != NULL,
+                               "Deserializing");
+       }
+
+       ok(lttng_rate_policy_is_equal(policy_a, policy_from_buffer),
+                       "serialized and from buffer are equal");
+
+       lttng_rate_policy_destroy(policy_a);
+       lttng_rate_policy_destroy(policy_b);
+       lttng_rate_policy_destroy(policy_c);
+       lttng_payload_reset(&payload);
+}
+
+int main(int argc, const char *argv[])
+{
+       plan_tests(NUM_TESTS);
+       test_rate_policy_every_n();
+       test_rate_policy_once_after_n();
+       return exit_status();
+}
This page took 0.161539 seconds and 4 git commands to generate.