| 1 | /* |
| 2 | * Copyright (C) 2021 Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> |
| 3 | * |
| 4 | * SPDX-License-Identifier: LGPL-2.1-only |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #ifndef LTTNG_RATE_POLICY_H |
| 9 | #define LTTNG_RATE_POLICY_H |
| 10 | |
| 11 | #include <lttng/lttng-export.h> |
| 12 | |
| 13 | #include <inttypes.h> |
| 14 | #include <sys/types.h> |
| 15 | |
| 16 | struct lttng_rate_policy; |
| 17 | |
| 18 | #ifdef __cplusplus |
| 19 | extern "C" { |
| 20 | #endif |
| 21 | |
| 22 | enum lttng_rate_policy_status { |
| 23 | LTTNG_RATE_POLICY_STATUS_OK = 0, |
| 24 | LTTNG_RATE_POLICY_STATUS_ERROR = -1, |
| 25 | LTTNG_RATE_POLICY_STATUS_UNKNOWN = -2, |
| 26 | LTTNG_RATE_POLICY_STATUS_INVALID = -3, |
| 27 | LTTNG_RATE_POLICY_STATUS_UNSET = -4, |
| 28 | LTTNG_RATE_POLICY_STATUS_UNSUPPORTED = -5, |
| 29 | LTTNG_RATE_POLICY_STATUS_PERMISSION_DENIED = -6, |
| 30 | }; |
| 31 | |
| 32 | enum lttng_rate_policy_type { |
| 33 | LTTNG_RATE_POLICY_TYPE_UNKNOWN = -1, |
| 34 | LTTNG_RATE_POLICY_TYPE_EVERY_N = 0, |
| 35 | LTTNG_RATE_POLICY_TYPE_ONCE_AFTER_N = 1, |
| 36 | }; |
| 37 | |
| 38 | /* |
| 39 | * Get the type of a rate policy. |
| 40 | */ |
| 41 | LTTNG_EXPORT extern enum lttng_rate_policy_type |
| 42 | lttng_rate_policy_get_type(const struct lttng_rate_policy *policy); |
| 43 | |
| 44 | /* |
| 45 | * Create a rate_policy of type `every n`. |
| 46 | * |
| 47 | * A `every n` rate policy will carry the execution of an action only when the |
| 48 | * action was ready for execution for a multiple of N. |
| 49 | * |
| 50 | * Returns a rate_policy object on success, NULL on error. |
| 51 | * rate_policy objects must be destroyed using the lttng_rate_policy_destroy() |
| 52 | * function. |
| 53 | */ |
| 54 | LTTNG_EXPORT extern struct lttng_rate_policy *lttng_rate_policy_every_n_create(uint64_t interval); |
| 55 | |
| 56 | /* |
| 57 | * Get the interval of a every N rate policy. |
| 58 | * |
| 59 | * Returns LTTNG_RATE_POLICY_STATUS_OK and a sets the interval. |
| 60 | * on success, LTTNG_RATE_FIRING_POLICY_STATUS_INVALID if an invalid |
| 61 | * parameter is passed. |
| 62 | */ |
| 63 | LTTNG_EXPORT extern enum lttng_rate_policy_status |
| 64 | lttng_rate_policy_every_n_get_interval(const struct lttng_rate_policy *policy, uint64_t *interval); |
| 65 | |
| 66 | /* |
| 67 | * Create a rate_policy of type `once after N`. |
| 68 | * |
| 69 | * A `once after N` rate policy will carry the execution of an action only when |
| 70 | * the action was ready for execution at least N times and will only be carried |
| 71 | * one time. |
| 72 | * |
| 73 | * Returns a rate_policy object on success, NULL on error. |
| 74 | * rate_policy objects must be destroyed using the lttng_rate_policy_destroy() |
| 75 | * function. |
| 76 | */ |
| 77 | LTTNG_EXPORT extern struct lttng_rate_policy * |
| 78 | lttng_rate_policy_once_after_n_create(uint64_t threshold); |
| 79 | |
| 80 | /* |
| 81 | * Get the threshold of a once after N rate policy. |
| 82 | * |
| 83 | * Returns LTTNG_RATE_POLICY_STATUS_OK and sets the threshold. |
| 84 | * on success, LTTNG_RATE_POLICY_STATUS_INVALID if an invalid |
| 85 | * parameter is passed. |
| 86 | */ |
| 87 | LTTNG_EXPORT extern enum lttng_rate_policy_status |
| 88 | lttng_rate_policy_once_after_n_get_threshold(const struct lttng_rate_policy *policy, |
| 89 | uint64_t *threshold); |
| 90 | |
| 91 | /* |
| 92 | * Destroy (frees) a rate policy object. |
| 93 | */ |
| 94 | LTTNG_EXPORT extern void lttng_rate_policy_destroy(struct lttng_rate_policy *policy); |
| 95 | |
| 96 | #ifdef __cplusplus |
| 97 | } |
| 98 | #endif |
| 99 | |
| 100 | #endif /* LTTNG_rate_policy_H */ |