X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=include%2Flttng%2Frotation.h;h=a8df4e682dc8b718b6975bd1bd6e63e2e4e65ca6;hp=0b4b2ad2f5eb8f92c01e60f9a484e8d23c3b19fd;hb=b6151646d77a70cd8054543c07924c840646950b;hpb=4f23c58345539eee2e44ae370c31dd6202de2d58 diff --git a/include/lttng/rotation.h b/include/lttng/rotation.h index 0b4b2ad2f..a8df4e682 100644 --- a/include/lttng/rotation.h +++ b/include/lttng/rotation.h @@ -20,6 +20,7 @@ #define LTTNG_ROTATION_H #include +#include #ifdef __cplusplus extern "C" { @@ -56,7 +57,7 @@ enum lttng_rotation_state { /* * The rotation could not be completed due to an error. */ - LTTNG_ROTATION_STATE_ERROR = 4, + LTTNG_ROTATION_STATE_ERROR = -1, }; enum lttng_rotation_status { @@ -67,19 +68,33 @@ enum lttng_rotation_status { LTTNG_ROTATION_STATUS_ERROR = -1, /* Invalid parameters provided. */ LTTNG_ROTATION_STATUS_INVALID = -2, + /* A schedule of this type is already set. */ + LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET = -3, + /* No such rotation schedule set. */ + LTTNG_ROTATION_STATUS_SCHEDULE_NOT_SET = -3, +}; + +enum lttng_rotation_schedule_type { + LTTNG_ROTATION_SCHEDULE_TYPE_UNKNOWN = -1, + LTTNG_ROTATION_SCHEDULE_TYPE_SIZE_THRESHOLD = 0, + LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC = 1, }; /* - * Input parameter to the lttng_rotate_session command. - * - * An immediate rotation is performed as soon as possible by the tracers. + * Descriptor of an immediate session rotation to be performed as soon as + * possible by the tracers. */ -struct lttng_rotation_immediate_attr; +struct lttng_rotation_immediate_descriptor; /* - * Input parameter to the lttng_rotate_schedule command. + * Session rotation schedule to add to a session. */ -struct lttng_rotation_schedule_attr; +struct lttng_rotation_schedule; + +/* + * A set of lttng_rotation_schedule objects. + */ +struct lttng_rotation_schedules; /* * Handle used to represent a specific rotation. @@ -87,136 +102,178 @@ struct lttng_rotation_schedule_attr; struct lttng_rotation_handle; /* - * Return a newly allocated immediate session rotation descriptor object or NULL - * on error. + * lttng rotate session handle functions. */ -extern struct lttng_rotation_immediate_attr * -lttng_rotation_immediate_attr_create(void); /* - * Return a newly allocated scheduled rotate session descriptor object or NULL - * on error. + * Get the current state of the rotation referenced by the handle. + * + * This will issue a request to the session daemon on every call. Hence, + * the result of this call may change over time. */ -extern struct lttng_rotation_schedule_attr * -lttng_rotation_schedule_attr_create(void); +extern enum lttng_rotation_status lttng_rotation_handle_get_state( + struct lttng_rotation_handle *rotation_handle, + enum lttng_rotation_state *rotation_state); /* - * Destroy a given immediate session rotation descriptor object. + * Get the location of the rotation's resulting archive. + * + * The rotation must be completed in order for this call to succeed. + * The location returned remains owned by the rotation handle. + * + * Note that location will not be set in case of error, or if the session + * rotation handle has expired. */ -extern void lttng_rotation_immediate_attr_destroy( - struct lttng_rotation_immediate_attr *attr); +extern enum lttng_rotation_status lttng_rotation_handle_get_archive_location( + struct lttng_rotation_handle *rotation_handle, + const struct lttng_trace_archive_location **location); /* - * Destroy a given scheduled rotate session descriptor object. + * Destroy an lttng_rotate_session handle. */ -extern void lttng_rotation_schedule_attr_destroy( - struct lttng_rotation_schedule_attr *attr); +extern void lttng_rotation_handle_destroy( + struct lttng_rotation_handle *rotation_handle); /* - * Set the name of the session to rotate immediately. + * Rotate the output folder of the session. + * + * On success, handle is allocated and can be used to monitor the progress + * of the rotation with lttng_rotation_get_state(). The handle must be freed + * by the caller with lttng_rotation_handle_destroy(). + * + * Passing NULL as the immediate rotation descriptor results in the default + * options being used. * - * The session_name parameter is copied to the immediate session rotation - * attributes. + * Return 0 if the rotate action was successfully launched or a negative + * LTTng error code on error. */ -extern enum lttng_rotation_status lttng_rotation_immediate_attr_set_session_name( - struct lttng_rotation_immediate_attr *attr, - const char *session_name); +extern int lttng_rotate_session(const char *session_name, + struct lttng_rotation_immediate_descriptor *descriptor, + struct lttng_rotation_handle **rotation_handle); /* - * Set the name of the session to rotate automatically. - * - * The session_name parameter is copied to the immediate session rotation - * attributes. + * Get the type of a rotation schedule object. */ -extern enum lttng_rotation_status lttng_rotation_schedule_attr_set_session_name( - struct lttng_rotation_schedule_attr *attr, - const char *session_name); +extern enum lttng_rotation_schedule_type lttng_rotation_schedule_get_type( + const struct lttng_rotation_schedule *schedule); /* - * Set the timer to periodically rotate the session (µs, -1ULL to disable). + * Return a newly allocated size-based session rotation schedule or NULL on + * error. */ -extern enum lttng_rotation_status lttng_rotation_schedule_attr_set_timer_period( - struct lttng_rotation_schedule_attr *attr, uint64_t timer); +extern struct lttng_rotation_schedule * +lttng_rotation_schedule_size_threshold_create(void); /* - * Set the size to rotate the session (bytes, -1ULL to disable). + * Get a session rotation schedule's size threshold. + * + * Returns LTTNG_ROTATION_STATUS_OK on success. + * LTTNG_ROTATION_STATUS_UNAVAILABLE is returned if the value is unset. */ -void lttng_rotation_schedule_attr_set_size( - struct lttng_rotation_schedule_attr *attr, uint64_t size); +extern enum lttng_rotation_status +lttng_rotation_schedule_size_threshold_get_threshold( + const struct lttng_rotation_schedule *schedule, + uint64_t *size_threshold_bytes); /* - * lttng rotate session handle functions. + * Set a session rotation schedule's size threshold. */ +extern enum lttng_rotation_status +lttng_rotation_schedule_size_threshold_set_threshold( + struct lttng_rotation_schedule *schedule, + uint64_t size_threshold_bytes); /* - * Get the current state of the rotation referenced by the handle. - * - * This will issue a request to the session daemon on every call. Hence, - * the result of this call may change over time. + * Return a newly allocated periodic session rotation schedule or NULL on + * error. */ -extern enum lttng_rotation_status lttng_rotation_handle_get_state( - struct lttng_rotation_handle *rotation_handle, - enum lttng_rotation_state *rotation_state); +extern struct lttng_rotation_schedule * +lttng_rotation_schedule_periodic_create(void); /* - * Get the location of the rotation's resulting archive. + * Get a time-based session rotation schedule's period. * - * The rotation must be completed in order for this call to succeed. - * The path returned is owned by the rotation handle. - * - * Note that path will not be set in case of error, or if the session - * rotation has expired. - * - * FIXME: Return an lttng_location object instead of a path. + * Returns LTTNG_ROTATION_STATUS_OK on success. + * LTTNG_ROTATION_STATUS_UNAVAILABLE is returned if the value is unset. */ -extern enum lttng_rotation_status lttng_rotation_handle_get_completed_archive_location( - struct lttng_rotation_handle *rotation_handle, - const char **path); +extern enum lttng_rotation_status lttng_rotation_schedule_periodic_get_period( + const struct lttng_rotation_schedule *schedule, + uint64_t *period_us); /* - * Destroy an lttng_rotate_session handle. + * Set a time-based session rotation schedule's period. */ -extern void lttng_rotation_handle_destroy( - struct lttng_rotation_handle *rotation_handle); +extern enum lttng_rotation_status lttng_rotation_schedule_periodic_set_period( + struct lttng_rotation_schedule *schedule, + uint64_t period_us); + +/* + * Destroy a rotation schedule. + */ +extern void lttng_rotation_schedule_destroy( + struct lttng_rotation_schedule *schedule); + +/* + * Destroy a set of rotation schedules. Pointers to any schedule contained + * in this set become invalid after this call. + */ +extern void lttng_rotation_schedules_destroy( + struct lttng_rotation_schedules *schedules); + +/* + * Get the number of schedules in a schedule set. + */ +extern enum lttng_rotation_status lttng_rotation_schedules_get_count( + const struct lttng_rotation_schedules *schedules, + unsigned int *count); /* - * Rotate the output folder of the session + * Get a schedule from the set at a given index. * - * On success, handle is allocated and can be used to monitor the progress - * of the rotation with lttng_rotation_get_state(). The handle must be freed - * by the caller with lttng_rotation_handle_destroy(). + * Note that the set maintains the ownership of the returned schedule. + * It must not be destroyed by the user, nor should it be held beyond + * the lifetime of the schedules set. * - * Return 0 if the rotate action was successfully launched or a negative - * LTTng error code on error. + * Returns a rotation schedule, or NULL on error. */ -extern int lttng_rotate_session(struct lttng_rotation_immediate_attr *attr, - struct lttng_rotation_handle **rotation_handle); +extern const struct lttng_rotation_schedule * +lttng_rotation_schedules_get_at_index( + const struct lttng_rotation_schedules *schedules, + unsigned int index); /* - * Configure a session to rotate periodically or based on the size written. + * Add a session rotation schedule to a session. + * + * Note that the current implementation currently limits the rotation schedules + * associated to a given session to one per type. + * + * Returns LTTNG_ROTATION_STATUS_OK on success, + * LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET if a rotation of the same type + * is already set. */ -extern int lttng_rotation_set_schedule( - struct lttng_rotation_schedule_attr *attr); +extern enum lttng_rotation_status lttng_session_add_rotation_schedule( + const char *session_name, + const struct lttng_rotation_schedule *schedule); /* - * Ask the sessiond for the value of the rotate timer (in micro-seconds) of the - * session. + * Remove a session rotation schedule from a session. * - * On success, return 0 and set the value or rotate_timer, on error return a - * negative value. + * Returns LTTNG_ROTATION_STATUS_OK on success, + * LTTNG_ROTATION_STATUS_SCHEDULE_INVALID if the provided schedule is + * not set. */ -extern int lttng_rotation_schedule_get_timer_period(const char *session_name, - uint64_t *rotate_timer); +extern enum lttng_rotation_status lttng_session_remove_rotation_schedule( + const char *session_name, + const struct lttng_rotation_schedule *schedule); /* - * Ask the sessiond for the value of the rotate size (in micro-seconds) of the - * session. + * Get the rotation schedules associated with a given session. * - * On success, return 0 and set the value or rotate_size, on error return - * a negative value. + * Returns LTTNG_OK on success, or a negative lttng error code on error. */ -extern int lttng_rotation_schedule_get_size(const char *session_name, - uint64_t *rotate_size); +extern int lttng_session_list_rotation_schedules( + const char *session_name, + struct lttng_rotation_schedules **schedules); #ifdef __cplusplus }