/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
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
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 \
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 \
#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);
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 {
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. */
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;
/*
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);
struct lttng_action_notify {
struct lttng_action parent;
- struct lttng_firing_policy *policy;
+ struct lttng_rate_policy *policy;
};
LTTNG_HIDDEN
#define LTTNG_ACTION_NOTIFY_H
struct lttng_action;
-struct lttng_firing_policy;
+struct lttng_rate_policy;
#ifdef __cplusplus
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().
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
}
--- /dev/null
+/*
+ * 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 */
--- /dev/null
+/*
+ * 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 */
#define LTTNG_ACTION_ROTATE_SESSION_H
struct lttng_action;
-struct lttng_firing_policy;
+struct lttng_rate_policy;
#ifdef __cplusplus
extern "C" {
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
}
struct lttng_action;
struct lttng_snapshot_output;
-struct lttng_firing_policy;
+struct lttng_rate_policy;
/*
* Create a newly allocated snapshot-session action object.
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
}
#define LTTNG_ACTION_START_SESSION_H
struct lttng_action;
-struct lttng_firing_policy;
+struct lttng_rate_policy;
#ifdef __cplusplus
extern "C" {
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
}
#define LTTNG_ACTION_STOP_SESSION_H
struct lttng_action;
-struct lttng_firing_policy;
+struct lttng_rate_policy;
#ifdef __cplusplus
extern "C" {
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
}
/* 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>
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) {
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);
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);
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;
}
}
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;
/*
* 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,
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;
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;
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);
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);
}
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;
}
}
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;
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
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
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");
}
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;
}
}
- /* 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;
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);
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);
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;
}
}
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;
{
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);
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;
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;
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;
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;
}
}
- 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;
}
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;
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 \
#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>
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;
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;
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;
#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)
{
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);
}
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;
_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);
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;
}
/* Default policy. */
- policy = lttng_firing_policy_every_n_create(1);
+ policy = lttng_rate_policy_every_n_create(1);
if (!policy) {
goto end;
}
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;
end:
free(notify);
- lttng_firing_policy_destroy(policy);
+ lttng_rate_policy_destroy(policy);
return action;
}
{
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;
}
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;
_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;
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;
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;
--- /dev/null
+/*
+ * 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;
+}
#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>
/* Owned by this. */
char *session_name;
- struct lttng_firing_policy *policy;
+ struct lttng_rate_policy *policy;
};
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(
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;
}
goto end;
}
- ret = lttng_firing_policy_serialize(
+ ret = lttng_rate_policy_serialize(
action_rotate_session->policy, payload);
if (ret) {
ret = -1;
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);
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) {
}
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;
}
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;
action = NULL;
end:
- lttng_firing_policy_destroy(policy);
+ lttng_rate_policy_destroy(policy);
lttng_action_rotate_session_destroy(action);
return consumed_len;
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;
}
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;
}
end:
- lttng_firing_policy_destroy(policy);
+ lttng_rate_policy_destroy(policy);
return action;
}
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;
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;
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;
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;
#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>
* 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):
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 *
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;
}
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;
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;
}
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:
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(
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;
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);
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;
}
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;
}
end:
- lttng_firing_policy_destroy(policy);
+ lttng_rate_policy_destroy(policy);
return action;
}
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;
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;
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;
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;
#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>
/* Owned by this. */
char *session_name;
- struct lttng_firing_policy *policy;
+ struct lttng_rate_policy *policy;
};
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(
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;
}
goto end;
}
- ret = lttng_firing_policy_serialize(
+ ret = lttng_rate_policy_serialize(
action_start_session->policy, payload);
if (ret) {
ret = -1;
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);
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;
}
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;
}
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;
action = NULL;
end:
- lttng_firing_policy_destroy(policy);
+ lttng_rate_policy_destroy(policy);
lttng_action_start_session_destroy(action);
return consumed_len;
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;
}
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;
}
end:
- lttng_firing_policy_destroy(policy);
+ lttng_rate_policy_destroy(policy);
return action;
}
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;
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;
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;
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;
#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>
/* Owned by this. */
char *session_name;
- struct lttng_firing_policy *policy;
+ struct lttng_rate_policy *policy;
};
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(
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;
}
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;
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);
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;
}
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;
}
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;
action = NULL;
end:
- lttng_firing_policy_destroy(policy);
+ lttng_rate_policy_destroy(policy);
lttng_action_stop_session_destroy(action);
return consumed_len;
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;
}
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;
}
end:
- lttng_firing_policy_destroy(policy);
+ lttng_rate_policy_destroy(policy);
return action;
}
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;
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;
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 += \
-SUBDIRS=utils start-stop firing-policy
+SUBDIRS=utils start-stop rate-policy
noinst_SCRIPTS = test_add_trigger_cli \
test_list_triggers_cli \
+++ /dev/null
-# 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
+++ /dev/null
-#!/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
--- /dev/null
+# 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
--- /dev/null
+#!/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
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}"
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}"
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 \
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 \
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
#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>
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);
/* 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");
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);
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;
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);
/* 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");
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);
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;
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);
/* 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");
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);
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;
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);
/* 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");
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);
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;
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);
/* 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");
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);
+++ /dev/null
-/*
- * 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();
-}
--- /dev/null
+/*
+ * 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();
+}