From: Julien Desfossez Date: Thu, 21 Dec 2017 19:32:32 +0000 (-0500) Subject: Save, restore and list the rotation parameters X-Git-Tag: v2.11.0-rc1~329 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=329f344308786acb81d8939eb8e1ad37307696c2;p=lttng-tools.git Save, restore and list the rotation parameters Add the support to save, restore and list the automatic rotation parameters. Signed-off-by: Julien Desfossez Signed-off-by: Jérémie Galarneau --- diff --git a/include/lttng/rotate-internal.h b/include/lttng/rotate-internal.h index 00a348ff7..29ea8c835 100644 --- a/include/lttng/rotate-internal.h +++ b/include/lttng/rotate-internal.h @@ -95,4 +95,14 @@ struct lttng_session_get_current_output_return { char path[LTTNG_PATH_MAX]; } LTTNG_PACKED; +/* For the LTTNG_ROTATION_SCHEDULE_GET_TIMER_PERIOD command. */ +struct lttng_rotation_schedule_get_timer_period { + uint64_t rotate_timer; +} LTTNG_PACKED; + +/* For the LTTNG_ROTATION_SCHEDULE_GET_SIZE command. */ +struct lttng_rotation_schedule_get_size { + uint64_t rotate_size; +} LTTNG_PACKED; + #endif /* LTTNG_ROTATE_INTERNAL_ABI_H */ diff --git a/include/lttng/rotation.h b/include/lttng/rotation.h index 9b797ac11..186cbd6f6 100644 --- a/include/lttng/rotation.h +++ b/include/lttng/rotation.h @@ -188,6 +188,26 @@ extern int lttng_rotate_session(struct lttng_rotation_immediate_attr *attr, extern int lttng_rotation_set_schedule( struct lttng_rotation_schedule_attr *attr); +/* + * Ask the sessiond for the value of the rotate timer (in micro-seconds) of the + * session. + * + * On success, return 0 and set the value or rotate_timer, on error return a + * negative value. + */ +extern int lttng_rotation_schedule_get_timer_period(const char *session_name, + uint64_t *rotate_timer); + +/* + * Ask the sessiond for the value of the rotate size (in micro-seconds) of the + * session. + * + * On success, return 0 and set the value or rotate_size, on error return + * a negative value. + */ +extern int lttng_rotation_schedule_get_size(const char *session_name, + uint64_t *rotate_size); + #ifdef __cplusplus } #endif diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 5e4148fb6..cec3a504a 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -2967,6 +2967,8 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int sock, case LTTNG_ROTATION_GET_INFO: case LTTNG_SESSION_GET_CURRENT_OUTPUT: case LTTNG_ROTATION_SET_SCHEDULE: + case LTTNG_ROTATION_SCHEDULE_GET_TIMER_PERIOD: + case LTTNG_ROTATION_SCHEDULE_GET_SIZE: need_domain = 0; break; default: @@ -3011,6 +3013,8 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int sock, case LTTNG_DATA_PENDING: case LTTNG_ROTATE_SESSION: case LTTNG_ROTATION_GET_INFO: + case LTTNG_ROTATION_SCHEDULE_GET_TIMER_PERIOD: + case LTTNG_ROTATION_SCHEDULE_GET_SIZE: break; default: /* Setup lttng message with no payload */ @@ -4205,6 +4209,50 @@ error_add_context: ret = LTTNG_OK; break; } + case LTTNG_ROTATION_SCHEDULE_GET_TIMER_PERIOD: + { + struct lttng_rotation_schedule_get_timer_period *get_timer; + + get_timer = zmalloc(sizeof(struct lttng_rotation_schedule_get_timer_period)); + if (!get_timer) { + ret = ENOMEM; + goto error; + } + get_timer->rotate_timer = cmd_ctx->session->rotate_timer_period; + + ret = setup_lttng_msg_no_cmd_header(cmd_ctx, get_timer, + sizeof(struct lttng_rotation_schedule_get_timer_period)); + free(get_timer); + if (ret < 0) { + ret = -ret; + goto error; + } + + ret = LTTNG_OK; + break; + } + case LTTNG_ROTATION_SCHEDULE_GET_SIZE: + { + struct lttng_rotation_schedule_get_size *get_size; + + get_size = zmalloc(sizeof(struct lttng_rotation_schedule_get_size)); + if (!get_size) { + ret = ENOMEM; + goto error; + } + get_size->rotate_size = cmd_ctx->session->rotate_size; + + ret = setup_lttng_msg_no_cmd_header(cmd_ctx, get_size, + sizeof(struct lttng_rotation_schedule_get_size)); + free(get_size); + if (ret < 0) { + ret = -ret; + goto error; + } + + ret = LTTNG_OK; + break; + } default: ret = LTTNG_ERR_UND; break; diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index af01654cd..ea4feb0c3 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -2033,7 +2033,8 @@ int save_session(struct ltt_session *session, goto end; } - if (session->snapshot_mode || session->live_timer) { + if (session->snapshot_mode || session->live_timer || + session->rotate_timer_period || session->rotate_size) { ret = config_writer_open_element(writer, config_element_attributes); if (ret) { ret = LTTNG_ERR_SAVE_IO_FAIL; @@ -2047,7 +2048,7 @@ int save_session(struct ltt_session *session, ret = LTTNG_ERR_SAVE_IO_FAIL; goto end; } - } else { + } else if (session->live_timer) { ret = config_writer_write_element_unsigned_int(writer, config_element_live_timer_interval, session->live_timer); if (ret) { @@ -2055,6 +2056,25 @@ int save_session(struct ltt_session *session, goto end; } } + if (session->rotate_timer_period) { + ret = config_writer_write_element_unsigned_int(writer, + config_element_rotation_timer_interval, + session->rotate_timer_period); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + } + + if (session->rotate_size) { + ret = config_writer_write_element_unsigned_int(writer, + config_element_rotation_size, + session->rotate_size); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + } /* /attributes */ ret = config_writer_close_element(writer); diff --git a/src/bin/lttng/commands/list.c b/src/bin/lttng/commands/list.c index 898c0de6a..e05134cbb 100644 --- a/src/bin/lttng/commands/list.c +++ b/src/bin/lttng/commands/list.c @@ -1520,6 +1520,57 @@ end: return ret; } +/* + * List the rotate settings (timer/size if any). + */ +static int list_rotate_settings(const char *session_name) +{ + int ret; + uint64_t size, timer; + + ret = lttng_rotation_schedule_get_timer_period(session_name, &timer); + if (ret) { + goto end; + } + + ret = lttng_rotation_schedule_get_size(session_name, &size); + if (ret) { + goto end; + } + + if (!timer && !size) { + ret = 0; + goto end; + } + + _MSG("Automatic rotation schedule settings:\n"); + + if (timer) { + _MSG(" timer period: %" PRIu64" µs\n", timer); + if (lttng_opt_mi) { + ret = mi_lttng_writer_write_element_unsigned_int(writer, + config_element_rotation_timer_interval, timer); + if (ret) { + goto end; + } + } + } + if (size) { + _MSG(" size threshold: %" PRIu64" bytes\n", size); + if (lttng_opt_mi) { + ret = mi_lttng_writer_write_element_unsigned_int(writer, + config_element_rotation_size, size); + if (ret) { + goto end; + } + } + } + _MSG("\n"); + +end: + return ret; +} + /* * Machine interface * Find the session with session_name as name @@ -1925,6 +1976,11 @@ int cmd_list(int argc, const char **argv) goto end; } + ret = list_rotate_settings(session_name); + if (ret) { + goto end; + } + /* Domain listing */ if (opt_domain) { ret = list_domains(session_name); diff --git a/src/common/config/config-session-abi.h b/src/common/config/config-session-abi.h index 65589f83e..2746c378c 100644 --- a/src/common/config/config-session-abi.h +++ b/src/common/config/config-session-abi.h @@ -81,6 +81,7 @@ extern const char * const config_element_trackers; extern const char * const config_element_targets; extern const char * const config_element_target_pid; extern const char * const config_element_rotation_timer_interval; +extern const char * const config_element_rotation_size; extern const char * const config_element_rotation_schedule; extern const char * const config_domain_type_kernel; diff --git a/src/common/config/session-config.c b/src/common/config/session-config.c index 4d5045f09..49047b1d6 100644 --- a/src/common/config/session-config.c +++ b/src/common/config/session-config.c @@ -133,6 +133,7 @@ const char * const config_element_targets = "targets"; const char * const config_element_target_pid = "pid_target"; LTTNG_HIDDEN const char * const config_element_rotation_timer_interval = "rotation_schedule_timer_period"; +LTTNG_HIDDEN const char * const config_element_rotation_size = "rotation_schedule_size"; LTTNG_HIDDEN const char * const config_element_rotation_schedule = "rotation_schedule"; const char * const config_domain_type_kernel = "KERNEL"; diff --git a/src/common/config/session.xsd b/src/common/config/session.xsd index 7f4592f1e..2c51ebec7 100644 --- a/src/common/config/session.xsd +++ b/src/common/config/session.xsd @@ -278,7 +278,8 @@ by its signed 32-bit representation when converted to msec. - + + diff --git a/src/common/sessiond-comm/sessiond-comm.h b/src/common/sessiond-comm/sessiond-comm.h index 8f08d9904..b8278bbe0 100644 --- a/src/common/sessiond-comm/sessiond-comm.h +++ b/src/common/sessiond-comm/sessiond-comm.h @@ -105,6 +105,8 @@ enum lttcomm_sessiond_command { LTTNG_ROTATION_GET_INFO = 46, LTTNG_ROTATION_SET_SCHEDULE = 47, LTTNG_SESSION_GET_CURRENT_OUTPUT = 48, + LTTNG_ROTATION_SCHEDULE_GET_TIMER_PERIOD = 49, + LTTNG_ROTATION_SCHEDULE_GET_SIZE = 50, }; enum lttcomm_relayd_command { diff --git a/src/lib/lttng-ctl/rotate.c b/src/lib/lttng-ctl/rotate.c index d0e127497..9ad32f962 100644 --- a/src/lib/lttng-ctl/rotate.c +++ b/src/lib/lttng-ctl/rotate.c @@ -329,3 +329,57 @@ int lttng_rotation_set_schedule( end: return ret; } + +int lttng_rotation_schedule_get_timer_period(const char *session_name, + uint64_t *rotate_timer) +{ + struct lttcomm_session_msg lsm; + struct lttng_rotation_schedule_get_timer_period *get_timer = NULL; + int ret; + + memset(&lsm, 0, sizeof(lsm)); + lsm.cmd_type = LTTNG_ROTATION_SCHEDULE_GET_TIMER_PERIOD; + lttng_ctl_copy_string(lsm.session.name, session_name, + sizeof(lsm.session.name)); + + ret = lttng_ctl_ask_sessiond(&lsm, (void **) &get_timer); + if (ret < 0) { + ret = -1; + goto end; + } + + *rotate_timer = get_timer->rotate_timer; + + ret = 0; + +end: + free(get_timer); + return ret; +} + +int lttng_rotation_schedule_get_size(const char *session_name, + uint64_t *rotate_size) +{ + struct lttcomm_session_msg lsm; + struct lttng_rotation_schedule_get_size *get_size = NULL; + int ret; + + memset(&lsm, 0, sizeof(lsm)); + lsm.cmd_type = LTTNG_ROTATION_SCHEDULE_GET_SIZE; + lttng_ctl_copy_string(lsm.session.name, session_name, + sizeof(lsm.session.name)); + + ret = lttng_ctl_ask_sessiond(&lsm, (void **) &get_size); + if (ret < 0) { + ret = -1; + goto end; + } + + *rotate_size = get_size->rotate_size; + + ret = 0; + +end: + free(get_size); + return ret; +}