X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fenable_rotation.c;h=81a55b24c8aaec4810cec9ce54bcbc1621d1a6ea;hp=a746f016f4ceb189b9fff4243ab23cf0ef1cc874;hb=dbd512ea8aa5349849aeeccda6130aa9e28cf23c;hpb=259c267446a63c501298f39a5d2397314b11f729 diff --git a/src/bin/lttng/commands/enable_rotation.c b/src/bin/lttng/commands/enable_rotation.c index a746f016f..81a55b24c 100644 --- a/src/bin/lttng/commands/enable_rotation.c +++ b/src/bin/lttng/commands/enable_rotation.c @@ -36,10 +36,17 @@ static char *opt_session_name; static struct mi_writer *writer; +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif + enum { OPT_HELP = 1, OPT_LIST_OPTIONS, OPT_TIMER, + OPT_SIZE, }; static struct poptOption long_options[] = { @@ -48,10 +55,11 @@ static struct poptOption long_options[] = { {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL}, {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0}, {"timer", 0, POPT_ARG_INT, 0, OPT_TIMER, 0, 0}, + {"size", 0, POPT_ARG_INT, 0, OPT_SIZE, 0, 0}, {0, 0, 0, 0, 0, 0, 0} }; -static int setup_rotate(char *session_name, uint64_t timer) +static int setup_rotate(char *session_name, uint64_t timer, uint64_t size) { int ret = 0; struct lttng_rotation_schedule_attr *attr = NULL; @@ -61,11 +69,6 @@ static int setup_rotate(char *session_name, uint64_t timer) goto error; } - ret = lttng_rotation_schedule_attr_set_session_name(attr, session_name); - if (ret < 0) { - goto error; - } - if (lttng_opt_mi) { /* Open rotation_schedule element */ ret = mi_lttng_writer_open_element(writer, @@ -93,8 +96,20 @@ static int setup_rotate(char *session_name, uint64_t timer) } } } + if (size) { + lttng_rotation_schedule_attr_set_size(attr, size); + MSG("Configuring session %s to rotate every %" PRIu64 " bytes written", + session_name, size); + if (lttng_opt_mi) { + ret = mi_lttng_writer_write_element_unsigned_int(writer, + config_element_rotation_size, size); + if (ret) { + goto end; + } + } + } - ret = lttng_rotation_set_schedule(attr); + ret = lttng_rotation_set_schedule(session_name, attr); if (ret) { ERR("%s", lttng_strerror(ret)); if (lttng_opt_mi) { @@ -132,6 +147,7 @@ static int setup_rotate(char *session_name, uint64_t timer) error: ret = -1; end: + lttng_rotation_schedule_attr_destroy(attr); return ret; } @@ -147,8 +163,8 @@ int cmd_enable_rotation(int argc, const char **argv) static poptContext pc; char *session_name = NULL; char *opt_arg = NULL; - uint64_t timer = 0; bool free_session_name = false; + uint64_t timer = 0, size = 0; pc = poptGetContext(NULL, argc, argv, long_options, 0); popt_ret = poptReadDefaultConfig(pc, 0); @@ -181,6 +197,16 @@ int cmd_enable_rotation(int argc, const char **argv) } DBG("Rotation timer set to %" PRIu64, timer); break; + case OPT_SIZE: + errno = 0; + opt_arg = poptGetOptArg(pc); + if (utils_parse_size_suffix(opt_arg, &size) < 0 || !size) { + ERR("Wrong value for --size option: %s", opt_arg); + ret = CMD_ERROR; + goto end; + } + DBG("Rotation size set to %" PRIu64, size); + break; default: ret = CMD_UNDEFINED; goto end; @@ -223,12 +249,12 @@ int cmd_enable_rotation(int argc, const char **argv) } /* No config options, just rotate the session now */ - if (timer == 0) { - ERR("No timer given"); + if (timer == 0 && size == 0) { + ERR("No timer or size given"); success = 0; command_ret = -1; } else { - command_ret = setup_rotate(session_name, timer); + command_ret = setup_rotate(session_name, timer, size); } if (command_ret) {