X-Git-Url: http://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=include%2Flttng%2Faction%2Frate-policy.h;fp=include%2Flttng%2Faction%2Frate-policy.h;h=a3a288a28e715754675ebe7da5a2aae244623ef2;hp=0000000000000000000000000000000000000000;hb=7f4d5b07cf7be895b38b69073389a4fcc318ec29;hpb=72365501d3148ca977a09bad8de0ec51b427bdd8 diff --git a/include/lttng/action/rate-policy.h b/include/lttng/action/rate-policy.h new file mode 100644 index 000000000..a3a288a28 --- /dev/null +++ b/include/lttng/action/rate-policy.h @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2021 Jonathan Rajotte + * + * SPDX-License-Identifier: LGPL-2.1-only + * + */ + +#ifndef LTTNG_RATE_POLICY_H +#define LTTNG_RATE_POLICY_H + +#include +#include + +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 */