From: Jonathan Rajotte Date: Tue, 31 Mar 2015 21:15:36 +0000 (-0400) Subject: Save/load: pid_tracker feature. X-Git-Tag: v2.8.0-rc1~495 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=847a5916c26ab9cc0dfc9322cccd2c748c54747e;p=lttng-tools.git Save/load: pid_tracker feature. Xml schema updated Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index d6316ef97..0a1393a4b 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -30,6 +30,7 @@ #include #include +#include "kernel.h" #include "save.h" #include "session.h" #include "syscall.h" @@ -722,8 +723,6 @@ end: return ret; } -/* TODO: save/restore tracker pid */ - static int save_kernel_context(struct config_writer *writer, struct lttng_kernel_context *ctx) @@ -1192,6 +1191,99 @@ 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)) { + 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_domains(struct config_writer *writer, struct ltt_session *session) { @@ -1224,6 +1316,24 @@ 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_KERNEL); + if (ret) { + goto end; + } + + /* /trackers */ + 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) { @@ -1247,6 +1357,24 @@ 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) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } /* /domain */ ret = config_writer_close_element(writer); if (ret) { diff --git a/src/common/config/config-session-abi.h b/src/common/config/config-session-abi.h index b2e939718..d8a37b718 100644 --- a/src/common/config/config-session-abi.h +++ b/src/common/config/config-session-abi.h @@ -70,6 +70,8 @@ extern const char * const config_element_pids; extern const char * const config_element_shared_memory_path; extern const char * const config_element_pid_tracker; 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_domain_type_kernel; extern const char * const config_domain_type_ust; diff --git a/src/common/config/config.c b/src/common/config/config.c index 783e784b2..03601be48 100644 --- a/src/common/config/config.c +++ b/src/common/config/config.c @@ -120,6 +120,8 @@ const char * const config_element_pids = "pids"; const char * const config_element_shared_memory_path = "shared_memory_path"; const char * const config_element_pid_tracker = "pid_tracker"; const char * const config_element_trackers = "trackers"; +const char * const config_element_targets = "targets"; +const char * const config_element_target_pid = "pid_target"; const char * const config_domain_type_kernel = "KERNEL"; const char * const config_domain_type_ust = "UST"; @@ -2090,6 +2092,79 @@ end: return ret; } +static +int process_pid_tracker_node(xmlNodePtr pid_tracker_node, + struct lttng_handle *handle) +{ + int ret, child; + xmlNodePtr targets_node = NULL; + xmlNodePtr node; + + assert(handle); + assert(pid_tracker_node); + /* get the targets node */ + for (node = xmlFirstElementChild(pid_tracker_node); node; + node = xmlNextElementSibling(node)) { + if (!strcmp((const char *) node->name, + config_element_targets)) { + targets_node = node; + break; + } + } + + if (!targets_node) { + ret = LTTNG_ERR_INVALID; + goto end; + } + + /* Go through all pid_target node */ + child = xmlChildElementCount(targets_node); + if (child == 0) { + /* The session is explicitly set to target nothing. */ + ret = lttng_untrack_pid(handle, -1); + if (ret) { + goto end; + } + } + for (node = xmlFirstElementChild(targets_node); node; + node = xmlNextElementSibling(node)) { + xmlNodePtr pid_target_node = node; + + /* get pid node and track it */ + for (node = xmlFirstElementChild(pid_target_node); node; + node = xmlNextElementSibling(node)) { + if (!strcmp((const char *) node->name, + config_element_pid)) { + int64_t pid; + xmlChar *content = NULL; + + content = xmlNodeGetContent(node); + if (!content) { + ret = LTTNG_ERR_LOAD_INVALID_CONFIG; + goto end; + } + + ret = parse_int(content, &pid); + free(content); + if (ret) { + ret = LTTNG_ERR_LOAD_INVALID_CONFIG; + goto end; + } + + ret = lttng_track_pid(handle, (int) pid); + if (ret) { + goto end; + } + } + } + node = pid_target_node; + } + +end: + return ret; +} + + static int process_domain_node(xmlNodePtr domain_node, const char *session_name) { @@ -2097,6 +2172,8 @@ int process_domain_node(xmlNodePtr domain_node, const char *session_name) struct lttng_domain domain = { 0 }; struct lttng_handle *handle = NULL; xmlNodePtr channels_node = NULL; + xmlNodePtr trackers_node = NULL; + xmlNodePtr pid_tracker_node = NULL; xmlNodePtr node; assert(session_name); @@ -2163,6 +2240,36 @@ int process_domain_node(xmlNodePtr domain_node, const char *session_name) goto end; } } + + /* get the trackers node */ + for (node = xmlFirstElementChild(domain_node); node; + node = xmlNextElementSibling(node)) { + if (!strcmp((const char *) node->name, + config_element_trackers)) { + trackers_node = node; + break; + } + } + + if (!trackers_node) { + goto end; + } + + for (node = xmlFirstElementChild(trackers_node); node; + node = xmlNextElementSibling(node)) { + if (!strcmp((const char *)node->name,config_element_pid_tracker)) { + pid_tracker_node = node; + ret = process_pid_tracker_node(pid_tracker_node, handle); + if (ret) { + goto end; + } + } + } + + if (!pid_tracker_node) { + lttng_track_pid(handle, -1); + } + end: lttng_destroy_handle(handle); return ret; diff --git a/src/common/config/session.xsd b/src/common/config/session.xsd index 0a7458d17..49b7cd112 100644 --- a/src/common/config/session.xsd +++ b/src/common/config/session.xsd @@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --> +elementFormDefault="qualified" version="2.7"> @@ -208,16 +208,46 @@ elementFormDefault="qualified" version="2.5"> - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +