From: Jérémie Galarneau Date: Sun, 30 Aug 2015 22:55:52 +0000 (-0400) Subject: Fix: Save tracker as part of UST and Kernel domains only X-Git-Tag: v2.8.0-rc1~442 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=e8fcabef14e1e2ce8d159c68c5585931df1216b4;p=lttng-tools.git Fix: Save tracker as part of UST and Kernel domains only Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index ccd4a0943..b8fe25ce4 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -1250,6 +1250,99 @@ const char *get_config_domain_str(enum lttng_domain_type domain) return str_dom; } +static +int save_pid_tracker(struct config_writer *writer, + struct ltt_session *sess, int domain) +{ + int ret = 0; + ssize_t nr_pids = 0, i; + int32_t *pids = NULL; + + switch (domain) { + case LTTNG_DOMAIN_KERNEL: + { + nr_pids = kernel_list_tracker_pids(sess->kernel_session, &pids); + if (nr_pids < 0) { + ret = LTTNG_ERR_KERN_LIST_FAIL; + goto end; + } + break; + } + case LTTNG_DOMAIN_UST: + { + nr_pids = trace_ust_list_tracker_pids(sess->ust_session, &pids); + if (nr_pids < 0) { + ret = LTTNG_ERR_UST_LIST_FAIL; + goto end; + } + break; + } + case LTTNG_DOMAIN_JUL: + case LTTNG_DOMAIN_LOG4J: + case LTTNG_DOMAIN_PYTHON: + default: + ret = LTTNG_ERR_UNKNOWN_DOMAIN; + goto end; + } + + /* Only create a pid_tracker if enabled or untrack all */ + if (nr_pids != 1 || (nr_pids == 1 && pids[0] != -1)) { + ret = config_writer_open_element(writer, + config_element_pid_tracker); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + + ret = config_writer_open_element(writer, + config_element_targets); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + + for (i = 0; i < nr_pids; i++) { + ret = config_writer_open_element(writer, + config_element_target_pid); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + + ret = config_writer_write_element_unsigned_int(writer, + config_element_pid, pids[i]); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + + /* /pid_target */ + ret = config_writer_close_element(writer); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + } + + /* /targets */ + ret = config_writer_close_element(writer); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + + /* /pid_tracker */ + ret = config_writer_close_element(writer); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + } +end: + free(pids); + return ret; +} + static int save_ust_domain(struct config_writer *writer, struct ltt_session *session, enum lttng_domain_type domain) @@ -1326,107 +1419,34 @@ int save_ust_domain(struct config_writer *writer, goto end; } - /* /domain */ - ret = config_writer_close_element(writer); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; - } - -end: - return ret; -} - -static -int save_pid_tracker(struct config_writer *writer, - struct ltt_session *sess, int domain) -{ - int ret = 0; - ssize_t nr_pids = 0, i; - int32_t *pids = NULL; - - switch (domain) { - case LTTNG_DOMAIN_KERNEL: - { - nr_pids = kernel_list_tracker_pids(sess->kernel_session, &pids); - if (nr_pids < 0) { - ret = LTTNG_ERR_KERN_LIST_FAIL; - goto end; - } - break; - } - case LTTNG_DOMAIN_UST: - { - nr_pids = trace_ust_list_tracker_pids(sess->ust_session, &pids); - if (nr_pids < 0) { - ret = LTTNG_ERR_UST_LIST_FAIL; - goto end; - } - break; - } - case LTTNG_DOMAIN_JUL: - case LTTNG_DOMAIN_LOG4J: - case LTTNG_DOMAIN_PYTHON: - default: - ret = LTTNG_ERR_UNKNOWN_DOMAIN; - goto end; - } - - /* Only create a pid_tracker if enabled or untrack all */ - if (nr_pids != 1 || (nr_pids == 1 && pids[0] != -1)) { + if (domain == LTTNG_DOMAIN_UST) { ret = config_writer_open_element(writer, - config_element_pid_tracker); + config_element_trackers); if (ret) { ret = LTTNG_ERR_SAVE_IO_FAIL; goto end; } - ret = config_writer_open_element(writer, - config_element_targets); + ret = save_pid_tracker(writer, session, LTTNG_DOMAIN_UST); if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; goto end; } - for (i = 0; i < nr_pids; i++) { - ret = config_writer_open_element(writer, - config_element_target_pid); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; - } - - ret = config_writer_write_element_unsigned_int(writer, - config_element_pid, pids[i]); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; - } - - /* /pid_target */ - ret = config_writer_close_element(writer); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; - } - } - - /* /targets */ + /* /trackers */ ret = config_writer_close_element(writer); if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; goto end; } + } - /* /pid_tracker */ - ret = config_writer_close_element(writer); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; - } + /* /domain */ + ret = config_writer_close_element(writer); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; } + end: - free(pids); return ret; } @@ -1494,24 +1514,6 @@ int save_domains(struct config_writer *writer, struct ltt_session *session) goto end; } - ret = config_writer_open_element(writer, - config_element_trackers); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; - } - - ret = save_pid_tracker(writer, session, LTTNG_DOMAIN_UST); - if (ret) { - goto end; - } - - /* /trackers */ - ret = config_writer_close_element(writer); - if (ret) { - goto end; - } - ret = save_ust_domain(writer, session, LTTNG_DOMAIN_JUL); if (ret) { goto end;