From 9a0fa4458e73d7a9d7245d6b4c1432f1e612f74e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 22 Jan 2016 16:23:43 -0500 Subject: [PATCH 01/16] Cleanup comments in lttng-ctl.c MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/lib/lttng-ctl/lttng-ctl.c | 245 ++++++++++++++++++---------------- 1 file changed, 133 insertions(+), 112 deletions(-) diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 665aba57d..0dcd673eb 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -197,9 +197,9 @@ end: } /* - * Check if we are in the specified group. + * Check if we are in the specified group. * - * If yes return 1, else return -1. + * If yes return 1, else return -1. */ LTTNG_HIDDEN int lttng_check_tracing_group(void) @@ -268,7 +268,7 @@ static int try_connect_sessiond(const char *sock_path) ret = lttcomm_connect_unix_sock(sock_path); if (ret < 0) { - /* Not alive */ + /* Not alive. */ goto error; } @@ -292,7 +292,7 @@ error: */ static int set_session_daemon_path(void) { - int in_tgroup = 0; /* In tracing group */ + int in_tgroup = 0; /* In tracing group. */ uid_t uid; uid = getuid(); @@ -311,7 +311,7 @@ static int set_session_daemon_path(void) int ret; if (in_tgroup) { - /* Tracing group */ + /* Tracing group. */ ret = try_connect_sessiond(sessiond_sock_path); if (ret >= 0) { goto end; @@ -321,8 +321,10 @@ static int set_session_daemon_path(void) /* ...or not in tracing group (and not root), default */ /* - * With GNU C < 2.1, snprintf returns -1 if the target buffer is too small; - * With GNU C >= 2.1, snprintf returns the required size (excluding closing null) + * With GNU C < 2.1, snprintf returns -1 if the target buffer + * is too small; + * With GNU C >= 2.1, snprintf returns the required size + * (excluding closing null) */ ret = snprintf(sessiond_sock_path, sizeof(sessiond_sock_path), DEFAULT_HOME_CLIENT_UNIX_SOCK, utils_get_home_dir()); @@ -338,9 +340,9 @@ error: } /* - * Connect to the LTTng session daemon. + * Connect to the LTTng session daemon. * - * On success, return 0. On error, return -1. + * On success, return 0. On error, return -1. */ static int connect_sessiond(void) { @@ -356,7 +358,7 @@ static int connect_sessiond(void) goto error; } - /* Connect to the sesssion daemon */ + /* Connect to the sesssion daemon. */ ret = lttcomm_connect_unix_sock(sessiond_sock_path); if (ret < 0) { goto error; @@ -373,6 +375,7 @@ error: /* * Clean disconnect from the session daemon. + * * On success, return 0. On error, return -1. */ static int disconnect_sessiond(void) @@ -478,6 +481,7 @@ end: /* * Create lttng handle and return pointer. + * * The returned pointer will be NULL in case of malloc() error. */ struct lttng_handle *lttng_create_handle(const char *session_name, @@ -516,6 +520,7 @@ void lttng_destroy_handle(struct lttng_handle *handle) /* * Register an outside consumer. + * * Returns size of returned session payload data or a negative error code. */ int lttng_register_consumer(struct lttng_handle *handle, @@ -533,14 +538,16 @@ int lttng_register_consumer(struct lttng_handle *handle, sizeof(lsm.session.name)); lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain); - lttng_ctl_copy_string(lsm.u.reg.path, socket_path, sizeof(lsm.u.reg.path)); + lttng_ctl_copy_string(lsm.u.reg.path, socket_path, + sizeof(lsm.u.reg.path)); return lttng_ctl_ask_sessiond(&lsm, NULL); } /* - * Start tracing for all traces of the session. - * Returns size of returned session payload data or a negative error code. + * Start tracing for all traces of the session. + * + * Returns size of returned session payload data or a negative error code. */ int lttng_start_tracing(const char *session_name) { @@ -596,8 +603,8 @@ static int _lttng_stop_tracing(const char *session_name, int wait) } /* - * Data sleep time before retrying (in usec). Don't sleep if the call - * returned value indicates availability. + * Data sleep time before retrying (in usec). Don't sleep if the + * call returned value indicates availability. */ if (data_ret) { usleep(DEFAULT_DATA_AVAILABILITY_WAIT_TIME); @@ -639,7 +646,7 @@ int lttng_add_context(struct lttng_handle *handle, { struct lttcomm_session_msg lsm; - /* Safety check. Both are mandatory */ + /* Safety check. Both are mandatory. */ if (handle == NULL || ctx == NULL) { return -LTTNG_ERR_INVALID; } @@ -668,10 +675,12 @@ int lttng_add_context(struct lttng_handle *handle, } /* - * Enable event(s) for a channel. - * If no event name is specified, all events are enabled. - * If no channel name is specified, the default 'channel0' is used. - * Returns size of returned session payload data or a negative error code. + * Enable event(s) for a channel. + * + * If no event name is specified, all events are enabled. + * If no channel name is specified, the default 'channel0' is used. + * + * Returns size of returned session payload data or a negative error code. */ int lttng_enable_event(struct lttng_handle *handle, struct lttng_event *ev, const char *channel_name) @@ -831,7 +840,7 @@ static int generate_filter(char *filter_expression, ret = -LTTNG_ERR_FILTER_INVAL; goto parse_error; } - /* Validate strings used as literals in the expression */ + /* Validate strings used as literals in the expression. */ ret = filter_visitor_ir_validate_string(ctx); if (ret) { ret = -LTTNG_ERR_FILTER_INVAL; @@ -904,7 +913,8 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle, goto error; } - /* Empty filter string will always be rejected by the parser + /* + * Empty filter string will always be rejected by the parser * anyway, so treat this corner-case early to eliminate * lttng_fmemopen error for 0-byte allocation. */ @@ -953,10 +963,10 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle, /* * We have either a filter or some exclusions, so we need to set up - * a variable-length memory block from where to send the data + * a variable-length memory block from where to send the data. */ - /* Parse filter expression */ + /* Parse filter expression. */ if (filter_expression != NULL || handle->domain.type == LTTNG_DOMAIN_JUL || handle->domain.type == LTTNG_DOMAIN_LOG4J || handle->domain.type == LTTNG_DOMAIN_PYTHON) { @@ -969,13 +979,17 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle, agent_filter = set_agent_filter(filter_expression, ev); if (!agent_filter) { if (!filter_expression) { - /* No JUL and no filter, just skip everything below. */ + /* + * No JUL and no filter, just skip + * everything below. + */ goto ask_sessiond; } } else { /* - * With an agent filter, the original filter has been added to - * it thus replace the filter expression. + * With an agent filter, the original filter has + * been added to it thus replace the filter + * expression. */ filter_expression = agent_filter; free_filter_expression = 1; @@ -996,20 +1010,20 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle, goto mem_error; } - /* Put exclusion names first in the data */ + /* Put exclusion names first in the data. */ while (exclusion_count--) { strncpy(varlen_data + LTTNG_SYMBOL_NAME_LEN * exclusion_count, *(exclusion_list + exclusion_count), LTTNG_SYMBOL_NAME_LEN - 1); } - /* Add filter expression next */ + /* Add filter expression next. */ if (lsm.u.enable.expression_len != 0) { memcpy(varlen_data + LTTNG_SYMBOL_NAME_LEN * lsm.u.enable.exclusion_count, filter_expression, lsm.u.enable.expression_len); } - /* Add filter bytecode next */ + /* Add filter bytecode next. */ if (ctx && lsm.u.enable.bytecode_len != 0) { memcpy(varlen_data + LTTNG_SYMBOL_NAME_LEN * lsm.u.enable.exclusion_count @@ -1020,7 +1034,8 @@ int lttng_enable_event_with_exclusions(struct lttng_handle *handle, ret = lttng_ctl_ask_sessiond_varlen(&lsm, varlen_data, (LTTNG_SYMBOL_NAME_LEN * lsm.u.enable.exclusion_count) + - lsm.u.enable.bytecode_len + lsm.u.enable.expression_len, NULL); + lsm.u.enable.bytecode_len + lsm.u.enable.expression_len, + NULL); free(varlen_data); mem_error: @@ -1032,15 +1047,16 @@ mem_error: filter_error: if (free_filter_expression) { /* - * The filter expression has been replaced and must be freed as it is - * not the original filter expression received as a parameter. + * The filter expression has been replaced and must be freed as + * it is not the original filter expression received as a + * parameter. */ free(filter_expression); } error: /* - * Return directly to the caller and don't ask the sessiond since something - * went wrong in the parsing of data above. + * Return directly to the caller and don't ask the sessiond since + * something went wrong in the parsing of data above. */ return ret; @@ -1070,7 +1086,8 @@ int lttng_disable_event_ext(struct lttng_handle *handle, goto error; } - /* Empty filter string will always be rejected by the parser + /* + * Empty filter string will always be rejected by the parser * anyway, so treat this corner-case early to eliminate * lttng_fmemopen error for 0-byte allocation. */ @@ -1130,13 +1147,17 @@ int lttng_disable_event_ext(struct lttng_handle *handle, agent_filter = set_agent_filter(filter_expression, ev); if (!agent_filter) { if (!filter_expression) { - /* No JUL and no filter, just skip everything below. */ + /* + * No JUL and no filter, just skip + * everything below. + */ goto ask_sessiond; } } else { /* - * With a JUL filter, the original filter has been added to it - * thus replace the filter expression. + * With a JUL filter, the original filter has + * been added to it thus replace the filter + * expression. */ filter_expression = agent_filter; free_filter_expression = 1; @@ -1156,13 +1177,13 @@ int lttng_disable_event_ext(struct lttng_handle *handle, goto mem_error; } - /* Add filter expression */ + /* Add filter expression. */ if (lsm.u.disable.expression_len != 0) { memcpy(varlen_data, filter_expression, lsm.u.disable.expression_len); } - /* Add filter bytecode next */ + /* Add filter bytecode next. */ if (ctx && lsm.u.disable.bytecode_len != 0) { memcpy(varlen_data + lsm.u.disable.expression_len, @@ -1183,15 +1204,16 @@ mem_error: filter_error: if (free_filter_expression) { /* - * The filter expression has been replaced and must be freed as it is - * not the original filter expression received as a parameter. + * The filter expression has been replaced and must be freed as + * it is not the original filter expression received as a + * parameter. */ free(filter_expression); } error: /* - * Return directly to the caller and don't ask the sessiond since something - * went wrong in the parsing of data above. + * Return directly to the caller and don't ask the sessiond since + * something went wrong in the parsing of data above. */ return ret; @@ -1201,10 +1223,10 @@ ask_sessiond: } /* - * Disable event(s) of a channel and domain. - * If no event name is specified, all events are disabled. - * If no channel name is specified, the default 'channel0' is used. - * Returns size of returned session payload data or a negative error code. + * Disable event(s) of a channel and domain. + * If no event name is specified, all events are disabled. + * If no channel name is specified, the default 'channel0' is used. + * Returns size of returned session payload data or a negative error code. */ int lttng_disable_event(struct lttng_handle *handle, const char *name, const char *channel_name) @@ -1219,17 +1241,15 @@ int lttng_disable_event(struct lttng_handle *handle, const char *name, } /* - * Enable channel per domain - * Returns size of returned session payload data or a negative error code. + * Enable channel per domain + * Returns size of returned session payload data or a negative error code. */ int lttng_enable_channel(struct lttng_handle *handle, struct lttng_channel *chan) { struct lttcomm_session_msg lsm; - /* - * NULL arguments are forbidden. No default values. - */ + /* NULL arguments are forbidden. No default values. */ if (handle == NULL || chan == NULL) { return -LTTNG_ERR_INVALID; } @@ -1249,14 +1269,14 @@ int lttng_enable_channel(struct lttng_handle *handle, } /* - * All tracing will be stopped for registered events of the channel. - * Returns size of returned session payload data or a negative error code. + * All tracing will be stopped for registered events of the channel. + * Returns size of returned session payload data or a negative error code. */ int lttng_disable_channel(struct lttng_handle *handle, const char *name) { struct lttcomm_session_msg lsm; - /* Safety check. Both are mandatory */ + /* Safety check. Both are mandatory. */ if (handle == NULL || name == NULL) { return -LTTNG_ERR_INVALID; } @@ -1277,16 +1297,14 @@ int lttng_disable_channel(struct lttng_handle *handle, const char *name) } /* - * Add PID to session tracker. - * Return 0 on success else a negative LTTng error code. + * Add PID to session tracker. + * Return 0 on success else a negative LTTng error code. */ int lttng_track_pid(struct lttng_handle *handle, int pid) { struct lttcomm_session_msg lsm; - /* - * NULL arguments are forbidden. No default values. - */ + /* NULL arguments are forbidden. No default values. */ if (handle == NULL) { return -LTTNG_ERR_INVALID; } @@ -1305,16 +1323,14 @@ int lttng_track_pid(struct lttng_handle *handle, int pid) } /* - * Remove PID from session tracker. - * Return 0 on success else a negative LTTng error code. + * Remove PID from session tracker. + * Return 0 on success else a negative LTTng error code. */ int lttng_untrack_pid(struct lttng_handle *handle, int pid) { struct lttcomm_session_msg lsm; - /* - * NULL arguments are forbidden. No default values. - */ + /* NULL arguments are forbidden. No default values. */ if (handle == NULL) { return -LTTNG_ERR_INVALID; } @@ -1333,10 +1349,10 @@ int lttng_untrack_pid(struct lttng_handle *handle, int pid) } /* - * Lists all available tracepoints of domain. - * Sets the contents of the events array. - * Returns the number of lttng_event entries in events; - * on error, returns a negative value. + * Lists all available tracepoints of domain. + * Sets the contents of the events array. + * Returns the number of lttng_event entries in events; + * on error, returns a negative value. */ int lttng_list_tracepoints(struct lttng_handle *handle, struct lttng_event **events) @@ -1361,10 +1377,10 @@ int lttng_list_tracepoints(struct lttng_handle *handle, } /* - * Lists all available tracepoint fields of domain. - * Sets the contents of the event field array. - * Returns the number of lttng_event_field entries in events; - * on error, returns a negative value. + * Lists all available tracepoint fields of domain. + * Sets the contents of the event field array. + * Returns the number of lttng_event_field entries in events; + * on error, returns a negative value. */ int lttng_list_tracepoint_fields(struct lttng_handle *handle, struct lttng_event_field **fields) @@ -1389,11 +1405,11 @@ int lttng_list_tracepoint_fields(struct lttng_handle *handle, } /* - * Lists all available kernel system calls. Allocates and sets the contents of - * the events array. + * Lists all available kernel system calls. Allocates and sets the contents of + * the events array. * - * Returns the number of lttng_event entries in events; on error, returns a - * negative value. + * Returns the number of lttng_event entries in events; on error, returns a + * negative value. */ int lttng_list_syscalls(struct lttng_event **events) { @@ -1418,8 +1434,8 @@ int lttng_list_syscalls(struct lttng_event **events) } /* - * Returns a human readable string describing - * the error code (a negative value). + * Returns a human readable string describing + * the error code (a negative value). */ const char *lttng_strerror(int code) { @@ -1463,8 +1479,8 @@ int lttng_create_session(const char *name, const char *url) } /* - * Destroy session using name. - * Returns size of returned session payload data or a negative error code. + * Destroy session using name. + * Returns size of returned session payload data or a negative error code. */ int lttng_destroy_session(const char *session_name) { @@ -1484,10 +1500,10 @@ int lttng_destroy_session(const char *session_name) } /* - * Ask the session daemon for all available sessions. - * Sets the contents of the sessions array. - * Returns the number of lttng_session entries in sessions; - * on error, returns a negative value. + * Ask the session daemon for all available sessions. + * Sets the contents of the sessions array. + * Returns the number of lttng_session entries in sessions; + * on error, returns a negative value. */ int lttng_list_sessions(struct lttng_session **sessions) { @@ -1525,10 +1541,10 @@ int lttng_set_session_shm_path(const char *session_name, } /* - * Ask the session daemon for all available domains of a session. - * Sets the contents of the domains array. - * Returns the number of lttng_domain entries in domains; - * on error, returns a negative value. + * Ask the session daemon for all available domains of a session. + * Sets the contents of the domains array. + * Returns the number of lttng_domain entries in domains; + * on error, returns a negative value. */ int lttng_list_domains(const char *session_name, struct lttng_domain **domains) @@ -1555,10 +1571,10 @@ int lttng_list_domains(const char *session_name, } /* - * Ask the session daemon for all available channels of a session. - * Sets the contents of the channels array. - * Returns the number of lttng_channel entries in channels; - * on error, returns a negative value. + * Ask the session daemon for all available channels of a session. + * Sets the contents of the channels array. + * Returns the number of lttng_channel entries in channels; + * on error, returns a negative value. */ int lttng_list_channels(struct lttng_handle *handle, struct lttng_channel **channels) @@ -1586,10 +1602,10 @@ int lttng_list_channels(struct lttng_handle *handle, } /* - * Ask the session daemon for all available events of a session channel. - * Sets the contents of the events array. - * Returns the number of lttng_event entries in events; - * on error, returns a negative value. + * Ask the session daemon for all available events of a session channel. + * Sets the contents of the events array. + * Returns the number of lttng_event entries in events; + * on error, returns a negative value. */ int lttng_list_events(struct lttng_handle *handle, const char *channel_name, struct lttng_event **events) @@ -1680,7 +1696,8 @@ void lttng_channel_set_default_attr(struct lttng_domain *domain, switch (domain->type) { case LTTNG_DOMAIN_KERNEL: - attr->switch_timer_interval = DEFAULT_KERNEL_CHANNEL_SWITCH_TIMER; + attr->switch_timer_interval = + DEFAULT_KERNEL_CHANNEL_SWITCH_TIMER; attr->read_timer_interval = DEFAULT_KERNEL_CHANNEL_READ_TIMER; attr->subbuf_size = default_get_kernel_channel_subbuf_size(); attr->num_subbuf = DEFAULT_KERNEL_CHANNEL_SUBBUF_NUM; @@ -1692,16 +1709,20 @@ void lttng_channel_set_default_attr(struct lttng_domain *domain, attr->subbuf_size = default_get_ust_uid_channel_subbuf_size(); attr->num_subbuf = DEFAULT_UST_UID_CHANNEL_SUBBUF_NUM; attr->output = DEFAULT_UST_UID_CHANNEL_OUTPUT; - attr->switch_timer_interval = DEFAULT_UST_UID_CHANNEL_SWITCH_TIMER; - attr->read_timer_interval = DEFAULT_UST_UID_CHANNEL_READ_TIMER; + attr->switch_timer_interval = + DEFAULT_UST_UID_CHANNEL_SWITCH_TIMER; + attr->read_timer_interval = + DEFAULT_UST_UID_CHANNEL_READ_TIMER; break; case LTTNG_BUFFER_PER_PID: default: attr->subbuf_size = default_get_ust_pid_channel_subbuf_size(); attr->num_subbuf = DEFAULT_UST_PID_CHANNEL_SUBBUF_NUM; attr->output = DEFAULT_UST_PID_CHANNEL_OUTPUT; - attr->switch_timer_interval = DEFAULT_UST_PID_CHANNEL_SWITCH_TIMER; - attr->read_timer_interval = DEFAULT_UST_PID_CHANNEL_READ_TIMER; + attr->switch_timer_interval = + DEFAULT_UST_PID_CHANNEL_SWITCH_TIMER; + attr->read_timer_interval = + DEFAULT_UST_PID_CHANNEL_READ_TIMER; break; } default: @@ -1722,25 +1743,25 @@ int lttng_session_daemon_alive(void) ret = set_session_daemon_path(); if (ret < 0) { - /* Error */ + /* Error. */ return ret; } if (*sessiond_sock_path == '\0') { /* - * No socket path set. Weird error which means the constructor was not - * called. + * No socket path set. Weird error which means the constructor + * was not called. */ assert(0); } ret = try_connect_sessiond(sessiond_sock_path); if (ret < 0) { - /* Not alive */ + /* Not alive. */ return 0; } - /* Is alive */ + /* Is alive. */ return 1; } @@ -1834,7 +1855,7 @@ int _lttng_create_session_ext(const char *name, const char *url, lsm.cmd_type = LTTNG_CREATE_SESSION; lttng_ctl_copy_string(lsm.session.name, name, sizeof(lsm.session.name)); - /* There should never be a data URL */ + /* There should never be a data URL. */ size = uri_parse_str_urls(url, NULL, &uris); if (size < 0) { ret = -LTTNG_ERR_INVALID; @@ -2034,7 +2055,7 @@ int lttng_list_tracker_pids(struct lttng_handle *handle, } /* - * lib constructor + * lib constructor. */ static void __attribute__((constructor)) init() { @@ -2043,7 +2064,7 @@ static void __attribute__((constructor)) init() } /* - * lib destructor + * lib destructor. */ static void __attribute__((destructor)) lttng_ctl_exit() { -- 2.34.1 From 72316fcf465b4aad870d422dca8cae5214d917ec Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 26 Jan 2016 11:42:45 -0500 Subject: [PATCH 02/16] Add application context support to lttng-ctl lttng_add_context MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Forward the provider and context names of app contexts to the session daemon. Signed-off-by: Jérémie Galarneau --- include/lttng/event.h | 34 +++++++----- src/bin/lttng-sessiond/main.c | 69 +++++++++++++++++++++++- src/common/sessiond-comm/sessiond-comm.h | 2 + src/lib/lttng-ctl/lttng-ctl.c | 55 ++++++++++++++++--- 4 files changed, 138 insertions(+), 22 deletions(-) diff --git a/include/lttng/event.h b/include/lttng/event.h index 3e8fbe3e8..e5b2b4bb0 100644 --- a/include/lttng/event.h +++ b/include/lttng/event.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2014 - David Goulet + * Copyright (C) 2016 - Jérémie Galarneau * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License, version 2.1 only, @@ -121,21 +122,22 @@ enum lttng_event_output { /* Event context possible type */ enum lttng_event_context_type { - LTTNG_EVENT_CONTEXT_PID = 0, - LTTNG_EVENT_CONTEXT_PERF_COUNTER = 1, /* Backward compat. */ - LTTNG_EVENT_CONTEXT_PROCNAME = 2, - LTTNG_EVENT_CONTEXT_PRIO = 3, - LTTNG_EVENT_CONTEXT_NICE = 4, - LTTNG_EVENT_CONTEXT_VPID = 5, - LTTNG_EVENT_CONTEXT_TID = 6, - LTTNG_EVENT_CONTEXT_VTID = 7, - LTTNG_EVENT_CONTEXT_PPID = 8, - LTTNG_EVENT_CONTEXT_VPPID = 9, - LTTNG_EVENT_CONTEXT_PTHREAD_ID = 10, - LTTNG_EVENT_CONTEXT_HOSTNAME = 11, - LTTNG_EVENT_CONTEXT_IP = 12, - LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER = 13, + LTTNG_EVENT_CONTEXT_PID = 0, + LTTNG_EVENT_CONTEXT_PERF_COUNTER = 1, /* Backward compat. */ + LTTNG_EVENT_CONTEXT_PROCNAME = 2, + LTTNG_EVENT_CONTEXT_PRIO = 3, + LTTNG_EVENT_CONTEXT_NICE = 4, + LTTNG_EVENT_CONTEXT_VPID = 5, + LTTNG_EVENT_CONTEXT_TID = 6, + LTTNG_EVENT_CONTEXT_VTID = 7, + LTTNG_EVENT_CONTEXT_PPID = 8, + LTTNG_EVENT_CONTEXT_VPPID = 9, + LTTNG_EVENT_CONTEXT_PTHREAD_ID = 10, + LTTNG_EVENT_CONTEXT_HOSTNAME = 11, + LTTNG_EVENT_CONTEXT_IP = 12, + LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER = 13, LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER = 14, + LTTNG_EVENT_CONTEXT_APP_CONTEXT = 15, }; enum lttng_event_field_type { @@ -178,6 +180,10 @@ struct lttng_event_context { union { struct lttng_event_perf_counter_ctx perf_counter; + struct { + char *provider_name; + char *ctx_name; + } app_ctx; char padding[LTTNG_EVENT_CONTEXT_PADDING2]; } u; }; diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index c1f466ed7..7a8b5ae42 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -3343,9 +3343,74 @@ skip_domain: switch (cmd_ctx->lsm->cmd_type) { case LTTNG_ADD_CONTEXT: { - ret = cmd_add_context(cmd_ctx->session, cmd_ctx->lsm->domain.type, + /* + * An LTTNG_ADD_CONTEXT command might have a supplementary + * payload if the context being added is an application context. + */ + if (cmd_ctx->lsm->u.context.ctx.ctx == + LTTNG_EVENT_CONTEXT_APP_CONTEXT) { + char *provider_name = NULL, *context_name = NULL; + size_t provider_name_len = + cmd_ctx->lsm->u.context.provider_name_len; + size_t context_name_len = + cmd_ctx->lsm->u.context.context_name_len; + + if (provider_name_len == 0 || context_name_len == 0) { + /* + * Application provider and context names MUST + * be provided. + */ + ret = -LTTNG_ERR_INVALID; + goto error; + } + + provider_name = zmalloc(provider_name_len + 1); + if (!provider_name) { + ret = -LTTNG_ERR_NOMEM; + goto error; + } + + context_name = zmalloc(context_name_len + 1); + if (!context_name) { + ret = -LTTNG_ERR_NOMEM; + goto error_add_context; + } + + ret = lttcomm_recv_unix_sock(sock, provider_name, + provider_name_len); + if (ret < 0) { + goto error_add_context; + } + + ret = lttcomm_recv_unix_sock(sock, context_name, + context_name_len); + if (ret < 0) { + goto error_add_context; + } + cmd_ctx->lsm->u.context.ctx.u.app_ctx.provider_name = + provider_name; + cmd_ctx->lsm->u.context.ctx.u.app_ctx.ctx_name = + context_name; + } + + /* + * cmd_add_context assumes ownership of the provider and context + * names. + */ + ret = cmd_add_context(cmd_ctx->session, + cmd_ctx->lsm->domain.type, cmd_ctx->lsm->u.context.channel_name, - &cmd_ctx->lsm->u.context.ctx, kernel_poll_pipe[1]); + &cmd_ctx->lsm->u.context.ctx, + kernel_poll_pipe[1]); + + cmd_ctx->lsm->u.context.ctx.u.app_ctx.provider_name = NULL; + cmd_ctx->lsm->u.context.ctx.u.app_ctx.ctx_name = NULL; +error_add_context: + free(cmd_ctx->lsm->u.context.ctx.u.app_ctx.provider_name); + free(cmd_ctx->lsm->u.context.ctx.u.app_ctx.ctx_name); + if (ret < 0) { + goto error; + } break; } case LTTNG_DISABLE_CHANNEL: diff --git a/src/common/sessiond-comm/sessiond-comm.h b/src/common/sessiond-comm/sessiond-comm.h index 778618876..4a204c02e 100644 --- a/src/common/sessiond-comm/sessiond-comm.h +++ b/src/common/sessiond-comm/sessiond-comm.h @@ -270,6 +270,8 @@ struct lttcomm_session_msg { struct { char channel_name[LTTNG_SYMBOL_NAME_LEN]; struct lttng_event_context ctx LTTNG_PACKED; + uint32_t provider_name_len; + uint32_t context_name_len; } LTTNG_PACKED context; /* Use by register_consumer */ struct { diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 0dcd673eb..03b74c0b7 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -4,6 +4,7 @@ * Linux Trace Toolkit Control Library * * Copyright (C) 2011 David Goulet + * Copyright (C) 2016 - Jérémie Galarneau * * This library is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License, version 2.1 only, @@ -644,15 +645,18 @@ int lttng_add_context(struct lttng_handle *handle, struct lttng_event_context *ctx, const char *event_name, const char *channel_name) { + int ret; + size_t len = 0; + char *buf = NULL; struct lttcomm_session_msg lsm; /* Safety check. Both are mandatory. */ if (handle == NULL || ctx == NULL) { - return -LTTNG_ERR_INVALID; + ret = -LTTNG_ERR_INVALID; + goto end; } memset(&lsm, 0, sizeof(lsm)); - lsm.cmd_type = LTTNG_ADD_CONTEXT; /* If no channel name, send empty string. */ @@ -665,13 +669,52 @@ int lttng_add_context(struct lttng_handle *handle, } lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain); - - memcpy(&lsm.u.context.ctx, ctx, sizeof(struct lttng_event_context)); - lttng_ctl_copy_string(lsm.session.name, handle->session_name, sizeof(lsm.session.name)); - return lttng_ctl_ask_sessiond(&lsm, NULL); + if (ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT) { + size_t provider_len, ctx_len; + const char *provider_name = ctx->u.app_ctx.provider_name; + const char *ctx_name = ctx->u.app_ctx.ctx_name; + + if (!provider_name || !ctx_name) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + provider_len = strlen(provider_name); + if (provider_len == 0) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + lsm.u.context.provider_name_len = provider_len; + + ctx_len = strlen(ctx_name); + if (ctx_len == 0) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + lsm.u.context.context_name_len = ctx_len; + + len = provider_len + ctx_len; + buf = zmalloc(len); + if (!buf) { + ret = -LTTNG_ERR_NOMEM; + goto end; + } + + memcpy(buf, provider_name, provider_len); + memcpy(buf + provider_len, ctx_name, ctx_len); + } + memcpy(&lsm.u.context.ctx, ctx, sizeof(struct lttng_event_context)); + /* Don't leak application addresses to the sessiond. */ + lsm.u.context.ctx.u.app_ctx.provider_name = NULL; + lsm.u.context.ctx.u.app_ctx.ctx_name = NULL; + + ret = lttng_ctl_ask_sessiond_varlen(&lsm, buf, len, NULL); +end: + free(buf); + return ret; } /* -- 2.34.1 From 8ef030a7bff927ba186a69156cce57490fc5ccde Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 26 Jan 2016 11:44:12 -0500 Subject: [PATCH 03/16] Use lttng_domain_type enum instead of bare integer MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/context.c | 8 +++++--- src/bin/lttng-sessiond/context.h | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/bin/lttng-sessiond/context.c b/src/bin/lttng-sessiond/context.c index 866a039e7..be15cebd2 100644 --- a/src/bin/lttng-sessiond/context.c +++ b/src/bin/lttng-sessiond/context.c @@ -87,7 +87,8 @@ error: /* * Add UST context to channel. */ -static int add_uctx_to_channel(struct ltt_ust_session *usess, int domain, +static int add_uctx_to_channel(struct ltt_ust_session *usess, + enum lttng_domain_type domain, struct ltt_ust_channel *uchan, struct lttng_event_context *ctx) { int ret; @@ -239,8 +240,9 @@ error: /* * Add UST context to tracer. */ -int context_ust_add(struct ltt_ust_session *usess, int domain, - struct lttng_event_context *ctx, char *channel_name) +int context_ust_add(struct ltt_ust_session *usess, + enum lttng_domain_type domain, struct lttng_event_context *ctx, + char *channel_name) { int ret = LTTNG_OK; struct lttng_ht_iter iter; diff --git a/src/bin/lttng-sessiond/context.h b/src/bin/lttng-sessiond/context.h index e3047761b..01b35167e 100644 --- a/src/bin/lttng-sessiond/context.h +++ b/src/bin/lttng-sessiond/context.h @@ -26,7 +26,8 @@ int context_kernel_add(struct ltt_kernel_session *ksession, struct lttng_event_context *ctx, char *channel_name); -int context_ust_add(struct ltt_ust_session *usess, int domain, - struct lttng_event_context *ctx, char *channel_name); +int context_ust_add(struct ltt_ust_session *usess, + enum lttng_domain_type domain, struct lttng_event_context *ctx, + char *channel_name); #endif /* _LTT_CONTEXT_H */ -- 2.34.1 From 8df907cb3e58910e3588c6cdc384dafc81963a22 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 26 Jan 2016 11:45:42 -0500 Subject: [PATCH 04/16] Remove superflous domain check in add_uctx_to_channel MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/context.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/bin/lttng-sessiond/context.c b/src/bin/lttng-sessiond/context.c index be15cebd2..941ab2535 100644 --- a/src/bin/lttng-sessiond/context.c +++ b/src/bin/lttng-sessiond/context.c @@ -97,6 +97,7 @@ static int add_uctx_to_channel(struct ltt_ust_session *usess, assert(usess); assert(uchan); assert(ctx); + assert(domain == LTTNG_DOMAIN_UST); /* Check if context is duplicate */ cds_list_for_each_entry(uctx, &uchan->ctx_list, list) { @@ -113,15 +114,8 @@ static int add_uctx_to_channel(struct ltt_ust_session *usess, goto error; } - switch (domain) { - case LTTNG_DOMAIN_UST: - ret = ust_app_add_ctx_channel_glb(usess, uchan, uctx); - if (ret < 0) { - goto error; - } - break; - default: - ret = -ENOSYS; + ret = ust_app_add_ctx_channel_glb(usess, uchan, uctx); + if (ret < 0) { goto error; } -- 2.34.1 From 5235bf17705eb1e731486605cfd040801745b032 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 26 Jan 2016 11:46:17 -0500 Subject: [PATCH 05/16] Remove superflous domain check in context_ust_add MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/context.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/bin/lttng-sessiond/context.c b/src/bin/lttng-sessiond/context.c index 941ab2535..ffd6e3ad5 100644 --- a/src/bin/lttng-sessiond/context.c +++ b/src/bin/lttng-sessiond/context.c @@ -246,21 +246,11 @@ int context_ust_add(struct ltt_ust_session *usess, assert(usess); assert(ctx); assert(channel_name); + assert(domain == LTTNG_DOMAIN_UST); rcu_read_lock(); - /* - * Define which channel's hashtable to use from the domain or quit if - * unknown domain. - */ - switch (domain) { - case LTTNG_DOMAIN_UST: - chan_ht = usess->domain_global.channels; - break; - default: - ret = LTTNG_ERR_UND; - goto error; - } + chan_ht = usess->domain_global.channels; /* Get UST channel if defined */ if (channel_name[0] != '\0') { -- 2.34.1 From 885b6cbc5396dd88637c0cb53ab60eda0a513274 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 26 Jan 2016 11:46:48 -0500 Subject: [PATCH 06/16] Enforce const-correctness in UNIX socket wrappers MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/common/sessiond-comm/inet.c | 4 ++-- src/common/sessiond-comm/inet.h | 4 ++-- src/common/sessiond-comm/inet6.c | 4 ++-- src/common/sessiond-comm/inet6.h | 4 ++-- src/common/sessiond-comm/sessiond-comm.h | 4 ++-- src/common/sessiond-comm/unix.c | 4 ++-- src/common/sessiond-comm/unix.h | 2 +- src/lib/lttng-ctl/lttng-ctl-helper.h | 4 ++-- src/lib/lttng-ctl/lttng-ctl.c | 4 ++-- 9 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/common/sessiond-comm/inet.c b/src/common/sessiond-comm/inet.c index 35ce3b6b5..b870deef4 100644 --- a/src/common/sessiond-comm/inet.c +++ b/src/common/sessiond-comm/inet.c @@ -407,7 +407,7 @@ ssize_t lttcomm_recvmsg_inet_sock(struct lttcomm_sock *sock, void *buf, * Return the size of sent data. */ LTTNG_HIDDEN -ssize_t lttcomm_sendmsg_inet_sock(struct lttcomm_sock *sock, void *buf, +ssize_t lttcomm_sendmsg_inet_sock(struct lttcomm_sock *sock, const void *buf, size_t len, int flags) { struct msghdr msg; @@ -416,7 +416,7 @@ ssize_t lttcomm_sendmsg_inet_sock(struct lttcomm_sock *sock, void *buf, memset(&msg, 0, sizeof(msg)); - iov[0].iov_base = buf; + iov[0].iov_base = (void *) buf; iov[0].iov_len = len; msg.msg_iov = iov; msg.msg_iovlen = 1; diff --git a/src/common/sessiond-comm/inet.h b/src/common/sessiond-comm/inet.h index 6a79c9106..03549fabd 100644 --- a/src/common/sessiond-comm/inet.h +++ b/src/common/sessiond-comm/inet.h @@ -57,8 +57,8 @@ extern int lttcomm_listen_inet_sock(struct lttcomm_sock *sock, int backlog); extern ssize_t lttcomm_recvmsg_inet_sock(struct lttcomm_sock *sock, void *buf, size_t len, int flags); -extern ssize_t lttcomm_sendmsg_inet_sock(struct lttcomm_sock *sock, void *buf, - size_t len, int flags); +extern ssize_t lttcomm_sendmsg_inet_sock(struct lttcomm_sock *sock, + const void *buf, size_t len, int flags); /* Initialize inet communication layer. */ extern void lttcomm_inet_init(void); diff --git a/src/common/sessiond-comm/inet6.c b/src/common/sessiond-comm/inet6.c index a29adad42..51d02ebb9 100644 --- a/src/common/sessiond-comm/inet6.c +++ b/src/common/sessiond-comm/inet6.c @@ -386,7 +386,7 @@ ssize_t lttcomm_recvmsg_inet6_sock(struct lttcomm_sock *sock, void *buf, * Return the size of sent data. */ LTTNG_HIDDEN -ssize_t lttcomm_sendmsg_inet6_sock(struct lttcomm_sock *sock, void *buf, +ssize_t lttcomm_sendmsg_inet6_sock(struct lttcomm_sock *sock, const void *buf, size_t len, int flags) { struct msghdr msg; @@ -395,7 +395,7 @@ ssize_t lttcomm_sendmsg_inet6_sock(struct lttcomm_sock *sock, void *buf, memset(&msg, 0, sizeof(msg)); - iov[0].iov_base = buf; + iov[0].iov_base = (void *) buf; iov[0].iov_len = len; msg.msg_iov = iov; msg.msg_iovlen = 1; diff --git a/src/common/sessiond-comm/inet6.h b/src/common/sessiond-comm/inet6.h index 3af3be5be..5c2ed5371 100644 --- a/src/common/sessiond-comm/inet6.h +++ b/src/common/sessiond-comm/inet6.h @@ -38,7 +38,7 @@ extern int lttcomm_listen_inet6_sock(struct lttcomm_sock *sock, int backlog); extern ssize_t lttcomm_recvmsg_inet6_sock(struct lttcomm_sock *sock, void *buf, size_t len, int flags); -extern ssize_t lttcomm_sendmsg_inet6_sock(struct lttcomm_sock *sock, void *buf, - size_t len, int flags); +extern ssize_t lttcomm_sendmsg_inet6_sock(struct lttcomm_sock *sock, + const void *buf, size_t len, int flags); #endif /* _LTTCOMM_INET6_H */ diff --git a/src/common/sessiond-comm/sessiond-comm.h b/src/common/sessiond-comm/sessiond-comm.h index 4a204c02e..ec7d36ae5 100644 --- a/src/common/sessiond-comm/sessiond-comm.h +++ b/src/common/sessiond-comm/sessiond-comm.h @@ -218,8 +218,8 @@ struct lttcomm_proto_ops { int (*listen) (struct lttcomm_sock *sock, int backlog); ssize_t (*recvmsg) (struct lttcomm_sock *sock, void *buf, size_t len, int flags); - ssize_t (*sendmsg) (struct lttcomm_sock *sock, void *buf, size_t len, - int flags); + ssize_t (*sendmsg) (struct lttcomm_sock *sock, const void *buf, + size_t len, int flags); }; /* diff --git a/src/common/sessiond-comm/unix.c b/src/common/sessiond-comm/unix.c index 5e0ba6281..8d2e03a5b 100644 --- a/src/common/sessiond-comm/unix.c +++ b/src/common/sessiond-comm/unix.c @@ -205,7 +205,7 @@ ssize_t lttcomm_recv_unix_sock(int sock, void *buf, size_t len) * Return the size of sent data. */ LTTNG_HIDDEN -ssize_t lttcomm_send_unix_sock(int sock, void *buf, size_t len) +ssize_t lttcomm_send_unix_sock(int sock, const void *buf, size_t len) { struct msghdr msg; struct iovec iov[1]; @@ -213,7 +213,7 @@ ssize_t lttcomm_send_unix_sock(int sock, void *buf, size_t len) memset(&msg, 0, sizeof(msg)); - iov[0].iov_base = buf; + iov[0].iov_base = (void *) buf; iov[0].iov_len = len; msg.msg_iov = iov; msg.msg_iovlen = 1; diff --git a/src/common/sessiond-comm/unix.h b/src/common/sessiond-comm/unix.h index 7ea05032f..24786b8fe 100644 --- a/src/common/sessiond-comm/unix.h +++ b/src/common/sessiond-comm/unix.h @@ -49,7 +49,7 @@ ssize_t lttcomm_recv_fds_unix_sock(int sock, int *fds, size_t nb_fd); LTTNG_HIDDEN ssize_t lttcomm_recv_unix_sock(int sock, void *buf, size_t len); LTTNG_HIDDEN -ssize_t lttcomm_send_unix_sock(int sock, void *buf, size_t len); +ssize_t lttcomm_send_unix_sock(int sock, const void *buf, size_t len); LTTNG_HIDDEN ssize_t lttcomm_send_creds_unix_sock(int sock, void *buf, size_t len); diff --git a/src/lib/lttng-ctl/lttng-ctl-helper.h b/src/lib/lttng-ctl/lttng-ctl-helper.h index 5f6d5c209..b7a28268c 100644 --- a/src/lib/lttng-ctl/lttng-ctl-helper.h +++ b/src/lib/lttng-ctl/lttng-ctl-helper.h @@ -35,14 +35,14 @@ void lttng_ctl_copy_lttng_domain(struct lttng_domain *dst, struct lttng_domain *src); /* - * Sends the lttcomm message to the session daemon and fills buf of the + * Sends the lttcomm message to the session daemon and fills buf if the * returned data is not NULL. * * Return the size of the received data on success or else a negative lttng * error code. If buf is NULL, 0 is returned on success. */ int lttng_ctl_ask_sessiond_varlen(struct lttcomm_session_msg *lsm, - void *vardata, size_t varlen, void **buf); + const void *vardata, size_t varlen, void **buf); /* * Use this if no variable length data needs to be sent. diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 03b74c0b7..14bb7b32d 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -150,7 +150,7 @@ end: * On success, returns the number of bytes sent (>=0) * On error, returns -1 */ -static int send_session_varlen(void *data, size_t len) +static int send_session_varlen(const void *data, size_t len) { int ret; @@ -400,7 +400,7 @@ static int disconnect_sessiond(void) */ LTTNG_HIDDEN int lttng_ctl_ask_sessiond_varlen(struct lttcomm_session_msg *lsm, - void *vardata, size_t varlen, void **buf) + const void *vardata, size_t varlen, void **buf) { int ret; size_t size; -- 2.34.1 From 5b2f9c4dd9ef66cbf9253955653324281eac263b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 27 Jan 2016 19:01:50 -0500 Subject: [PATCH 07/16] Add app context support to lttng client MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/bin/lttng/commands/add_context.c | 214 ++++++++++++++++++++++----- 1 file changed, 177 insertions(+), 37 deletions(-) diff --git a/src/bin/lttng/commands/add_context.c b/src/bin/lttng/commands/add_context.c index fb37c0aa7..d58ee908b 100644 --- a/src/bin/lttng/commands/add_context.c +++ b/src/bin/lttng/commands/add_context.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2011 - David Goulet + * Copyright (C) 2016 - Jérémie Galarneau * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2 only, @@ -38,12 +39,16 @@ static char *opt_channel_name; static char *opt_session_name; static int opt_kernel; static int opt_userspace; +static int opt_jul; +static int opt_log4j; static char *opt_type; enum { OPT_HELP = 1, OPT_TYPE, OPT_USERSPACE, + OPT_JUL, + OPT_LOG4J, OPT_LIST_OPTIONS, }; @@ -69,6 +74,7 @@ enum context_type { CONTEXT_IP = 12, CONTEXT_PERF_CPU_COUNTER = 13, CONTEXT_PERF_THREAD_COUNTER = 14, + CONTEXT_APP_CONTEXT = 15, }; /* @@ -144,6 +150,8 @@ static struct poptOption long_options[] = { {"channel", 'c', POPT_ARG_STRING, &opt_channel_name, 0, 0, 0}, {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0}, + {"jul", 'j', POPT_ARG_NONE, 0, OPT_JUL, 0, 0}, + {"log4j", 'l', POPT_ARG_NONE, 0, OPT_LOG4J, 0, 0}, {"type", 't', POPT_ARG_STRING, &opt_type, OPT_TYPE, 0, 0}, {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL}, {0, 0, 0, 0, 0, 0, 0} @@ -199,6 +207,10 @@ const struct ctx_opts { uint32_t type; uint64_t config; } perf; + struct { + char *provider_name; + char *ctx_name; + } app_ctx; } u; } ctx_opts[] = { { "pid", CONTEXT_PID }, @@ -441,7 +453,7 @@ const struct ctx_opts { * Context type for command line option parsing. */ struct ctx_type { - const struct ctx_opts *opt; + struct ctx_opts *opt; struct cds_list_head list; }; @@ -505,6 +517,8 @@ static void usage(FILE *ofp) fprintf(ofp, " -c, --channel NAME Apply to channel\n"); fprintf(ofp, " -k, --kernel Apply to the kernel tracer\n"); fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n"); + fprintf(ofp, " -j, --jul Apply to Java application using JUL\n"); + fprintf(ofp, " -l, --log4j Apply for Java application using LOG4j\n"); fprintf(ofp, "\n"); fprintf(ofp, "Context:\n"); fprintf(ofp, " -t, --type TYPE Context type. You can repeat that option on\n"); @@ -526,10 +540,12 @@ static void usage(FILE *ofp) /* * Find context numerical value from string. + * + * Return -1 if not found. */ static int find_ctx_type_idx(const char *opt) { - int ret = -1, i = 0; + int ret, i = 0; while (ctx_opts[i].symbol != NULL) { if (strcmp(opt, ctx_opts[i].symbol) == 0) { @@ -539,10 +555,27 @@ static int find_ctx_type_idx(const char *opt) i++; } + ret = -1; end: return ret; } +static +enum lttng_domain_type get_domain(void) +{ + if (opt_kernel) { + return LTTNG_DOMAIN_KERNEL; + } else if (opt_userspace) { + return LTTNG_DOMAIN_UST; + } else if (opt_jul) { + return LTTNG_DOMAIN_JUL; + } else if (opt_log4j) { + return LTTNG_DOMAIN_LOG4J; + } else { + assert(0); + } +} + /* * Add context to channel or event. */ @@ -557,14 +590,7 @@ static int add_context(char *session_name) memset(&context, 0, sizeof(context)); memset(&dom, 0, sizeof(dom)); - if (opt_kernel) { - dom.type = LTTNG_DOMAIN_KERNEL; - } else if (opt_userspace) { - dom.type = LTTNG_DOMAIN_UST; - } else { - assert(0); - } - + dom.type = get_domain(); handle = lttng_create_handle(session_name, &dom); if (handle == NULL) { ret = CMD_ERROR; @@ -599,6 +625,12 @@ static int add_context(char *session_name) *ptr = '_'; } break; + case LTTNG_EVENT_CONTEXT_APP_CONTEXT: + context.u.app_ctx.provider_name = + type->opt->u.app_ctx.provider_name; + context.u.app_ctx.ctx_name = + type->opt->u.app_ctx.ctx_name; + break; default: break; } @@ -671,12 +703,132 @@ error: return ret; } +static +void destroy_ctx_type(struct ctx_type *type) +{ + if (!type) { + return; + } + free(type->opt->symbol); + free(type->opt); + free(type); +} + +static +struct ctx_type *create_ctx_type(void) +{ + struct ctx_type *type = zmalloc(sizeof(*type)); + + if (!type) { + PERROR("malloc ctx_type"); + goto end; + } + + type->opt = zmalloc(sizeof(*type->opt)); + if (!type->opt) { + PERROR("malloc ctx_type options"); + destroy_ctx_type(type); + goto end; + } +end: + return type; +} + +static +struct ctx_type *get_context_type(const char *ctx) +{ + int opt_index; + struct ctx_type *type = NULL; + const char app_ctx_prefix[] = "$app."; + char *provider_name = NULL, *ctx_name = NULL; + size_t i, len, colon_pos = 0, provider_name_len, ctx_name_len; + + if (!ctx) { + goto not_found; + } + + type = create_ctx_type(); + if (!type) { + goto not_found; + } + + /* Check if ctx matches a known static context. */ + opt_index = find_ctx_type_idx(ctx); + if (opt_index >= 0) { + *type->opt = ctx_opts[opt_index]; + type->opt->symbol = strdup(ctx_opts[opt_index].symbol); + goto found; + } + + /* + * No match found against static contexts; check if it is an app + * context. + */ + len = strlen(ctx); + if (len <= sizeof(app_ctx_prefix) - 1) { + goto not_found; + } + + /* String starts with $app. */ + if (strncmp(ctx, app_ctx_prefix, sizeof(app_ctx_prefix) - 1)) { + goto not_found; + } + + /* Validate that the ':' separator is present. */ + for (i = sizeof(app_ctx_prefix); i < len; i++) { + const char c = ctx[i]; + + if (c == ':') { + colon_pos = i; + break; + } + } + + /* + * No colon found or no ctx name ("$app.provider:") or no provider name + * given ("$app.:..."), which is invalid. + */ + if (!colon_pos || colon_pos == len || + colon_pos == sizeof(app_ctx_prefix)) { + ERR("Invalid application context provided: no provider or context name provided."); + goto not_found; + } + + provider_name_len = colon_pos - sizeof(app_ctx_prefix) + 2; + provider_name = zmalloc(provider_name_len); + if (!provider_name) { + PERROR("malloc provider_name"); + goto not_found; + } + strncpy(provider_name, ctx + sizeof(app_ctx_prefix) - 1, + provider_name_len - 1); + type->opt->u.app_ctx.provider_name = provider_name; + + ctx_name_len = len - colon_pos; + ctx_name = zmalloc(ctx_name_len); + if (!ctx_name) { + PERROR("malloc ctx_name"); + goto not_found; + } + strncpy(ctx_name, ctx + colon_pos + 1, ctx_name_len - 1); + type->opt->u.app_ctx.ctx_name = ctx_name; + type->opt->ctx_type = CONTEXT_APP_CONTEXT; + type->opt->symbol = strdup(ctx); +found: + return type; +not_found: + free(provider_name); + free(ctx_name); + destroy_ctx_type(type); + return NULL; +} + /* * Add context to channel or event. */ int cmd_add_context(int argc, const char **argv) { - int index, opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS; + int opt, ret = CMD_SUCCESS, command_ret = CMD_SUCCESS; int success = 1; static poptContext pc; struct ctx_type *type, *tmptype; @@ -697,37 +849,25 @@ int cmd_add_context(int argc, const char **argv) usage(stdout); goto end; case OPT_TYPE: - /* - * Look up the index of opt_type in ctx_opts[] first, so we don't - * have to free(type) on failure. - */ - index = find_ctx_type_idx(opt_type); - if (index < 0) { + { + type = get_context_type(opt_type); + if (!type) { ERR("Unknown context type %s", opt_type); - ret = CMD_ERROR; - goto end; - } - - type = zmalloc(sizeof(struct ctx_type)); - if (type == NULL) { - PERROR("malloc ctx_type"); ret = CMD_FATAL; goto end; } - - type->opt = &ctx_opts[index]; - if (type->opt->symbol == NULL) { - ERR("Unknown context type %s", opt_type); - free(type); - ret = CMD_ERROR; - goto end; - } else { - cds_list_add_tail(&type->list, &ctx_type_list.head); - } + cds_list_add_tail(&type->list, &ctx_type_list.head); break; + } case OPT_USERSPACE: opt_userspace = 1; break; + case OPT_JUL: + opt_jul = 1; + break; + case OPT_LOG4J: + opt_log4j = 1; + break; case OPT_LIST_OPTIONS: list_cmd_options(stdout, long_options); goto end; @@ -738,8 +878,8 @@ int cmd_add_context(int argc, const char **argv) } } - ret = print_missing_or_multiple_domains(opt_kernel + opt_userspace); - + ret = print_missing_or_multiple_domains(opt_kernel + opt_userspace + + opt_jul + opt_log4j); if (ret) { ret = CMD_ERROR; goto end; @@ -830,7 +970,7 @@ end: /* Cleanup allocated memory */ cds_list_for_each_entry_safe(type, tmptype, &ctx_type_list.head, list) { - free(type); + destroy_ctx_type(type); } /* Overwrite ret if an error occurred during add_context() */ -- 2.34.1 From 8b6f8f8b05fdfbcd707a98ea0935051be5219a5b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Thu, 28 Jan 2016 16:39:33 -0500 Subject: [PATCH 08/16] Notify java agent of enabled application contexts MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/agent.c | 322 +++++++++++++++++++++++-- src/bin/lttng-sessiond/agent.h | 9 + src/bin/lttng-sessiond/channel.c | 23 +- src/bin/lttng-sessiond/cmd.c | 39 ++- src/bin/lttng-sessiond/context.c | 40 ++- src/bin/lttng-sessiond/lttng-ust-abi.h | 6 + src/bin/lttng-sessiond/lttng-ust-ctl.h | 13 +- src/bin/lttng-sessiond/trace-ust.c | 52 +++- src/bin/lttng-sessiond/trace-ust.h | 4 +- src/bin/lttng-sessiond/ust-app.c | 52 +++- src/bin/lttng-sessiond/ust-app.h | 3 +- src/common/sessiond-comm/agent.h | 21 +- 12 files changed, 526 insertions(+), 58 deletions(-) diff --git a/src/bin/lttng-sessiond/agent.c b/src/bin/lttng-sessiond/agent.c index f6f2f772e..b2608a186 100644 --- a/src/bin/lttng-sessiond/agent.c +++ b/src/bin/lttng-sessiond/agent.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2013 - David Goulet + * Copyright (C) 2016 - Jérémie Galarneau * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License, version 2 only, as @@ -18,6 +19,7 @@ #define _LGPL_SOURCE #include #include +#include #include #include @@ -31,6 +33,20 @@ #define AGENT_RET_CODE_INDEX(code) (code - AGENT_RET_CODE_SUCCESS) +/* + * Agent application context representation. + */ +struct agent_app_ctx { + char *provider_name; + char *ctx_name; + + /* agent_app_ctx are part of the agent app_ctx_list. */ + struct cds_list_head list_node; + + /* For call_rcu teardown. */ + struct rcu_head rcu_node; +}; + /* * Human readable agent return code. */ @@ -225,7 +241,7 @@ error: * * Return 0 on success or else a negative errno value of sendmsg() op. */ -static int send_payload(struct lttcomm_sock *sock, void *data, +static int send_payload(struct lttcomm_sock *sock, const void *data, size_t size) { int ret; @@ -371,7 +387,7 @@ static int enable_event(struct agent_app *app, struct agent_event *event) uint64_t data_size; size_t filter_expression_length; uint32_t reply_ret_code; - struct lttcomm_agent_enable msg; + struct lttcomm_agent_enable_event msg; struct lttcomm_agent_generic_reply reply; assert(app); @@ -447,6 +463,112 @@ error: return ret; } +/* + * Send Pascal-style string. Size is sent as a 32-bit big endian integer. + */ +static +int send_pstring(struct lttcomm_sock *sock, const char *str, uint32_t len) +{ + int ret; + uint32_t len_be; + + len_be = htobe32(len); + ret = send_payload(sock, &len_be, sizeof(len_be)); + if (ret) { + goto end; + } + + ret = send_payload(sock, str, len); + if (ret) { + goto end; + } +end: + return ret; +} + +/* + * Internal enable application context on an agent application. This function + * communicates with the agent to enable a given application context. + * + * Return LTTNG_OK on success or else a LTTNG_ERR* code. + */ +static int app_context_op(struct agent_app *app, + struct agent_app_ctx *ctx, enum lttcomm_agent_command cmd) +{ + int ret; + uint32_t reply_ret_code; + struct lttcomm_agent_generic_reply reply; + size_t app_ctx_provider_name_len, app_ctx_name_len, data_size; + + assert(app); + assert(app->sock); + assert(ctx); + assert(cmd == AGENT_CMD_APP_CTX_ENABLE || + cmd == AGENT_CMD_APP_CTX_DISABLE); + + DBG2("Agent %s application %s:%s for app pid: %d and socket %d", + cmd == AGENT_CMD_APP_CTX_ENABLE ? "enabling" : "disabling", + ctx->provider_name, ctx->ctx_name, + app->pid, app->sock->fd); + + /* + * Calculate the payload's size, which consists of the size (u32, BE) + * of the provider name, the NULL-terminated provider name string, the + * size (u32, BE) of the context name, followed by the NULL-terminated + * context name string. + */ + app_ctx_provider_name_len = strlen(ctx->provider_name) + 1; + app_ctx_name_len = strlen(ctx->ctx_name) + 1; + data_size = sizeof(uint32_t) + app_ctx_provider_name_len + + sizeof(uint32_t) + app_ctx_name_len; + + ret = send_header(app->sock, data_size, cmd, 0); + if (ret < 0) { + goto error_io; + } + + if (app_ctx_provider_name_len > UINT32_MAX || + app_ctx_name_len > UINT32_MAX) { + ERR("Application context name > MAX_UINT32"); + ret = LTTNG_ERR_INVALID; + goto error; + } + + ret = send_pstring(app->sock, ctx->provider_name, + (uint32_t) app_ctx_provider_name_len); + if (ret < 0) { + goto error_io; + } + + ret = send_pstring(app->sock, ctx->ctx_name, + (uint32_t) app_ctx_name_len); + if (ret < 0) { + goto error_io; + } + + ret = recv_reply(app->sock, &reply, sizeof(reply)); + if (ret < 0) { + goto error_io; + } + + reply_ret_code = be32toh(reply.ret_code); + log_reply_code(reply_ret_code); + switch (reply_ret_code) { + case AGENT_RET_CODE_SUCCESS: + break; + default: + ret = LTTNG_ERR_UNK; + goto error; + } + + return LTTNG_OK; + +error_io: + ret = LTTNG_ERR_UST_ENABLE_FAIL; +error: + return ret; +} + /* * Internal disable agent event call on a agent application. This function * communicates with the agent to disable a given event. @@ -458,7 +580,7 @@ static int disable_event(struct agent_app *app, struct agent_event *event) int ret; uint64_t data_size; uint32_t reply_ret_code; - struct lttcomm_agent_disable msg; + struct lttcomm_agent_disable_event msg; struct lttcomm_agent_generic_reply reply; assert(app); @@ -561,8 +683,91 @@ error: return ret; } +static +void destroy_app_ctx(struct agent_app_ctx *ctx) +{ + free(ctx->provider_name); + free(ctx->ctx_name); + free(ctx); +} + +static +struct agent_app_ctx *create_app_ctx(struct lttng_event_context *ctx) +{ + struct agent_app_ctx *agent_ctx = NULL; + + if (!ctx) { + goto end; + } + + assert(ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT); + agent_ctx = zmalloc(sizeof(*ctx)); + if (!agent_ctx) { + goto end; + } + + agent_ctx->provider_name = strdup(ctx->u.app_ctx.provider_name); + agent_ctx->ctx_name = strdup(ctx->u.app_ctx.ctx_name); + if (!agent_ctx->provider_name || !agent_ctx->ctx_name) { + destroy_app_ctx(agent_ctx); + agent_ctx = NULL; + } +end: + return agent_ctx; +} + +/* + * Enable agent context on every agent applications registered with the session + * daemon. + * + * Return LTTNG_OK on success or else a LTTNG_ERR* code. + */ +int agent_enable_context(struct lttng_event_context *ctx, + enum lttng_domain_type domain) +{ + int ret; + struct agent_app *app; + struct lttng_ht_iter iter; + + assert(ctx); + if (ctx->ctx != LTTNG_EVENT_CONTEXT_APP_CONTEXT) { + ret = LTTNG_ERR_INVALID; + goto error; + } + + rcu_read_lock(); + + cds_lfht_for_each_entry(agent_apps_ht_by_sock->ht, &iter.iter, app, + node.node) { + struct agent_app_ctx *agent_ctx; + + if (app->domain != domain) { + continue; + } + + agent_ctx = create_app_ctx(ctx); + if (!agent_ctx) { + goto error_unlock; + } + + /* Enable event on agent application through TCP socket. */ + ret = app_context_op(app, agent_ctx, AGENT_CMD_APP_CTX_ENABLE); + if (ret != LTTNG_OK) { + destroy_app_ctx(agent_ctx); + goto error_unlock; + } + } + + ret = LTTNG_OK; + +error_unlock: + rcu_read_unlock(); +error: + return ret; +} + /* - * Disable agent event on every agent applications registered with the session + * Disable agent event on every agent application registered with the session * daemon. * * Return LTTNG_OK on success or else a LTTNG_ERR* code. @@ -602,6 +807,39 @@ end: return ret; } +/* + * Disable agent context on every agent application registered with the session + * daemon. + * + * Return LTTNG_OK on success or else a LTTNG_ERR* code. + */ +int disable_context(struct agent_app_ctx *ctx, enum lttng_domain_type domain) +{ + int ret = LTTNG_OK; + struct agent_app *app; + struct lttng_ht_iter iter; + + assert(ctx); + + rcu_read_lock(); + DBG2("Disabling agent application context %s:%s", + ctx->provider_name, ctx->ctx_name); + cds_lfht_for_each_entry(agent_apps_ht_by_sock->ht, &iter.iter, app, + node.node) { + if (app->domain != domain) { + continue; + } + + ret = app_context_op(app, ctx, AGENT_CMD_APP_CTX_DISABLE); + if (ret != LTTNG_OK) { + goto end; + } + } +end: + rcu_read_unlock(); + return ret; +} + /* * Ask every agent for the list of possible event. Events is allocated with the * events of every agent application. @@ -808,6 +1046,7 @@ int agent_init(struct agent *agt) } lttng_ht_node_init_u64(&agt->node, agt->domain); + CDS_INIT_LIST_HEAD(&agt->app_ctx_list); return 0; error: @@ -907,6 +1146,32 @@ void agent_add_event(struct agent_event *event, struct agent *agt) agt->being_used = 1; } +/* + * Unique add of a agent context to an agent object. + */ +int agent_add_context(struct lttng_event_context *ctx, struct agent *agt) +{ + int ret = LTTNG_OK; + struct agent_app_ctx *agent_ctx = NULL; + + assert(ctx); + assert(agt); + assert(agt->events); + assert(ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT); + + agent_ctx = create_app_ctx(ctx); + if (!agent_ctx) { + ret = LTTNG_ERR_NOMEM; + goto end; + } + + DBG3("Agent adding context %s:%s", ctx->u.app_ctx.provider_name, + ctx->u.app_ctx.ctx_name); + cds_list_add_tail_rcu(&agent_ctx->list_node, &agt->app_ctx_list); +end: + return ret; +} + /* * Find multiple agent events sharing the given name. * @@ -1008,6 +1273,15 @@ void agent_destroy_event(struct agent_event *event) free(event); } +static +void destroy_app_ctx_rcu(struct rcu_head *head) +{ + struct agent_app_ctx *ctx = + caa_container_of(head, struct agent_app_ctx, rcu_node); + + destroy_app_ctx(ctx); +} + /* * Destroy an agent completely. */ @@ -1015,6 +1289,7 @@ void agent_destroy(struct agent *agt) { struct lttng_ht_node_str *node; struct lttng_ht_iter iter; + struct agent_app_ctx *ctx; assert(agt); @@ -1026,9 +1301,10 @@ void agent_destroy(struct agent *agt) struct agent_event *event; /* - * When destroying an event, we have to try to disable it on the agent - * side so the event stops generating data. The return value is not - * important since we have to continue anyway destroying the object. + * When destroying an event, we have to try to disable it on the + * agent side so the event stops generating data. The return + * value is not important since we have to continue anyway + * destroying the object. */ event = caa_container_of(node, struct agent_event, node); (void) agent_disable_event(event, agt->domain); @@ -1037,8 +1313,13 @@ void agent_destroy(struct agent *agt) assert(!ret); call_rcu(&node->head, destroy_event_agent_rcu); } - rcu_read_unlock(); + cds_list_for_each_entry_rcu(ctx, &agt->app_ctx_list, list_node) { + (void) disable_context(ctx, agt->domain); + cds_list_del(&ctx->list_node); + call_rcu(&ctx->rcu_node, destroy_app_ctx_rcu); + } + rcu_read_unlock(); ht_cleanup_push(agt->events); free(agt); } @@ -1119,6 +1400,7 @@ void agent_update(struct agent *agt, int sock) struct agent_app *app; struct agent_event *event; struct lttng_ht_iter iter; + struct agent_app_ctx *ctx; assert(agt); assert(sock >= 0); @@ -1126,19 +1408,18 @@ void agent_update(struct agent *agt, int sock) DBG("Agent updating app socket %d", sock); rcu_read_lock(); + app = agent_find_app_by_sock(sock); + /* + * We are in the registration path thus if the application is gone, + * there is a serious code flow error. + */ + assert(app); cds_lfht_for_each_entry(agt->events->ht, &iter.iter, event, node.node) { /* Skip event if disabled. */ if (!event->enabled) { continue; } - app = agent_find_app_by_sock(sock); - /* - * We are in the registration path thus if the application is gone, - * there is a serious code flow error. - */ - assert(app); - ret = enable_event(app, event); if (ret != LTTNG_OK) { DBG2("Agent update unable to enable event %s on app pid: %d sock %d", @@ -1147,5 +1428,16 @@ void agent_update(struct agent *agt, int sock) continue; } } + + cds_list_for_each_entry_rcu(ctx, &agt->app_ctx_list, list_node) { + ret = app_context_op(app, ctx, AGENT_CMD_APP_CTX_ENABLE); + if (ret != LTTNG_OK) { + DBG2("Agent update unable to add application context %s:%s on app pid: %d sock %d", + ctx->provider_name, ctx->ctx_name, + app->pid, app->sock->fd); + continue; + } + } + rcu_read_unlock(); } diff --git a/src/bin/lttng-sessiond/agent.h b/src/bin/lttng-sessiond/agent.h index 2b3d864a6..c0808c48f 100644 --- a/src/bin/lttng-sessiond/agent.h +++ b/src/bin/lttng-sessiond/agent.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2013 - David Goulet + * Copyright (C) 2016 - Jérémie Galarneau * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License, version 2 only, as @@ -116,6 +117,9 @@ struct agent { /* Contains event indexed by name. */ struct lttng_ht *events; + /* Application context list (struct agent_app_ctx). */ + struct cds_list_head app_ctx_list; + /* Node used for the hash table indexed by domain type. */ struct lttng_ht_node_u64 node; }; @@ -148,6 +152,11 @@ void agent_event_next_duplicate(const char *name, void agent_delete_event(struct agent_event *event, struct agent *agt); void agent_destroy_event(struct agent_event *event); +/* Agent context API.*/ +int agent_enable_context(struct lttng_event_context *ctx, + enum lttng_domain_type domain); +int agent_add_context(struct lttng_event_context *ctx, struct agent *agt); + /* Agent app API. */ struct agent_app *agent_create_app(pid_t pid, enum lttng_domain_type domain, struct lttcomm_sock *sock); diff --git a/src/bin/lttng-sessiond/channel.c b/src/bin/lttng-sessiond/channel.c index 06a6d616a..7c95a0d21 100644 --- a/src/bin/lttng-sessiond/channel.c +++ b/src/bin/lttng-sessiond/channel.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2011 - David Goulet + * Copyright (C) 2016 - Jérémie Galarneau * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2 only, @@ -38,6 +39,7 @@ struct lttng_channel *channel_new_default_attr(int dom, enum lttng_buffer_type type) { struct lttng_channel *chan; + const char *channel_name = DEFAULT_CHANNEL_NAME; chan = zmalloc(sizeof(struct lttng_channel)); if (chan == NULL) { @@ -45,12 +47,6 @@ struct lttng_channel *channel_new_default_attr(int dom, goto error_alloc; } - if (snprintf(chan->name, sizeof(chan->name), "%s", - DEFAULT_CHANNEL_NAME) < 0) { - PERROR("snprintf default channel name"); - goto error; - } - /* Same for all domains. */ chan->attr.overwrite = DEFAULT_CHANNEL_OVERWRITE; chan->attr.tracefile_size = DEFAULT_CHANNEL_TRACEFILE_SIZE; @@ -67,7 +63,17 @@ struct lttng_channel *channel_new_default_attr(int dom, chan->attr.read_timer_interval = DEFAULT_KERNEL_CHANNEL_READ_TIMER; chan->attr.live_timer_interval = DEFAULT_KERNEL_CHANNEL_LIVE_TIMER; break; + case LTTNG_DOMAIN_JUL: + channel_name = DEFAULT_JUL_CHANNEL_NAME; + goto common_ust; + case LTTNG_DOMAIN_LOG4J: + channel_name = DEFAULT_LOG4J_CHANNEL_NAME; + goto common_ust; + case LTTNG_DOMAIN_PYTHON: + channel_name = DEFAULT_PYTHON_CHANNEL_NAME; + goto common_ust; case LTTNG_DOMAIN_UST: +common_ust: switch (type) { case LTTNG_BUFFER_PER_UID: chan->attr.subbuf_size = default_get_ust_uid_channel_subbuf_size(); @@ -98,6 +104,11 @@ struct lttng_channel *channel_new_default_attr(int dom, goto error; /* Not implemented */ } + if (snprintf(chan->name, sizeof(chan->name), "%s", + channel_name) < 0) { + PERROR("snprintf default channel name"); + goto error; + } return chan; error: diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index 33e301c87..eca3cf439 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2012 - David Goulet + * Copyright (C) 2016 - Jérémie Galarneau * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License, version 2 only, as @@ -1359,6 +1360,12 @@ int cmd_add_context(struct ltt_session *session, enum lttng_domain_type domain, char *channel_name, struct lttng_event_context *ctx, int kwpipe) { int ret, chan_kern_created = 0, chan_ust_created = 0; + char *app_ctx_provider_name = NULL, *app_ctx_name = NULL; + + if (ctx->ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT) { + app_ctx_provider_name = ctx->u.app_ctx.provider_name; + app_ctx_name = ctx->u.app_ctx.ctx_name; + } switch (domain) { case LTTNG_DOMAIN_KERNEL: @@ -1378,6 +1385,28 @@ int cmd_add_context(struct ltt_session *session, enum lttng_domain_type domain, goto error; } break; + case LTTNG_DOMAIN_JUL: + case LTTNG_DOMAIN_LOG4J: + { + /* + * Validate channel name. + * If no channel name is given and the domain is JUL or LOG4J, + * set it to the appropriate domain-specific channel name. If + * a name is provided but does not match the expexted channel + * name, return an error. + */ + if (domain == LTTNG_DOMAIN_JUL && *channel_name && + strcmp(channel_name, + DEFAULT_JUL_CHANNEL_NAME)) { + ret = LTTNG_ERR_UST_CHAN_NOT_FOUND; + goto error; + } else if (domain == LTTNG_DOMAIN_LOG4J && *channel_name && + strcmp(channel_name, + DEFAULT_LOG4J_CHANNEL_NAME)) { + ret = LTTNG_ERR_UST_CHAN_NOT_FOUND; + goto error; + } + } case LTTNG_DOMAIN_UST: { struct ltt_ust_session *usess = session->ust_session; @@ -1405,6 +1434,10 @@ int cmd_add_context(struct ltt_session *session, enum lttng_domain_type domain, } ret = context_ust_add(usess, domain, ctx, channel_name); + free(app_ctx_provider_name); + free(app_ctx_name); + app_ctx_name = NULL; + app_ctx_provider_name = NULL; if (ret != LTTNG_OK) { goto error; } @@ -1415,7 +1448,8 @@ int cmd_add_context(struct ltt_session *session, enum lttng_domain_type domain, goto error; } - return LTTNG_OK; + ret = LTTNG_OK; + goto end; error: if (chan_kern_created) { @@ -1439,6 +1473,9 @@ error: uchan); trace_ust_destroy_channel(uchan); } +end: + free(app_ctx_provider_name); + free(app_ctx_name); return ret; } diff --git a/src/bin/lttng-sessiond/context.c b/src/bin/lttng-sessiond/context.c index ffd6e3ad5..1725c6a10 100644 --- a/src/bin/lttng-sessiond/context.c +++ b/src/bin/lttng-sessiond/context.c @@ -1,5 +1,6 @@ /* - * Copyright (C) 2011 - David Goulet + * Copyright (C) 2011 - David Goulet + * Copyright (C) 2016 - Jérémie Galarneau * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2 only, @@ -29,6 +30,7 @@ #include "kernel.h" #include "ust-app.h" #include "trace-ust.h" +#include "agent.h" /* * Add kernel context to all channel. @@ -92,12 +94,11 @@ static int add_uctx_to_channel(struct ltt_ust_session *usess, struct ltt_ust_channel *uchan, struct lttng_event_context *ctx) { int ret; - struct ltt_ust_context *uctx; + struct ltt_ust_context *uctx = NULL; assert(usess); assert(uchan); assert(ctx); - assert(domain == LTTNG_DOMAIN_UST); /* Check if context is duplicate */ cds_list_for_each_entry(uctx, &uchan->ctx_list, list) { @@ -106,6 +107,38 @@ static int add_uctx_to_channel(struct ltt_ust_session *usess, goto duplicate; } } + uctx = NULL; + + switch (domain) { + case LTTNG_DOMAIN_JUL: + case LTTNG_DOMAIN_LOG4J: + { + struct agent *agt = trace_ust_find_agent(usess, domain); + + if (!agt) { + agt = agent_create(domain); + if (!agt) { + ret = LTTNG_ERR_NOMEM; + goto error; + } + agent_add(agt, usess->agents); + } + ret = agent_add_context(ctx, agt); + if (ret != LTTNG_OK) { + goto error; + } + + ret = agent_enable_context(ctx, domain); + if (ret != LTTNG_OK) { + goto error; + } + break; + } + case LTTNG_DOMAIN_UST: + break; + default: + assert(0); + } /* Create ltt UST context */ uctx = trace_ust_create_context(ctx); @@ -246,7 +279,6 @@ int context_ust_add(struct ltt_ust_session *usess, assert(usess); assert(ctx); assert(channel_name); - assert(domain == LTTNG_DOMAIN_UST); rcu_read_lock(); diff --git a/src/bin/lttng-sessiond/lttng-ust-abi.h b/src/bin/lttng-sessiond/lttng-ust-abi.h index d4c3b60aa..7bec0c961 100644 --- a/src/bin/lttng-sessiond/lttng-ust-abi.h +++ b/src/bin/lttng-sessiond/lttng-ust-abi.h @@ -142,6 +142,7 @@ enum lttng_ust_context_type { LTTNG_UST_CONTEXT_IP = 4, LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER = 5, LTTNG_UST_CONTEXT_CPU_ID = 6, + LTTNG_UST_CONTEXT_APP_CONTEXT = 7, }; struct lttng_ust_perf_counter_ctx { @@ -158,6 +159,11 @@ struct lttng_ust_context { union { struct lttng_ust_perf_counter_ctx perf_counter; + struct { + /* Includes trailing '\0'. */ + uint32_t provider_name_len; + uint32_t ctx_name_len; + } app_ctx; char padding[LTTNG_UST_CONTEXT_PADDING2]; } u; } LTTNG_PACKED; diff --git a/src/bin/lttng-sessiond/lttng-ust-ctl.h b/src/bin/lttng-sessiond/lttng-ust-ctl.h index 73a924418..1ea7b938a 100644 --- a/src/bin/lttng-sessiond/lttng-ust-ctl.h +++ b/src/bin/lttng-sessiond/lttng-ust-ctl.h @@ -59,6 +59,17 @@ struct ustctl_consumer_channel_attr { * API used by sessiond. */ +struct lttng_ust_context_attr { + enum lttng_ust_context_type ctx; + union { + struct lttng_ust_perf_counter_ctx perf_counter; + struct { + char *provider_name; + char *ctx_name; + } app_ctx; + } u; +}; + /* * Error values: all the following functions return: * >= 0: Success (LTTNG_UST_OK) @@ -69,7 +80,7 @@ int ustctl_create_session(int sock); int ustctl_create_event(int sock, struct lttng_ust_event *ev, struct lttng_ust_object_data *channel_data, struct lttng_ust_object_data **event_data); -int ustctl_add_context(int sock, struct lttng_ust_context *ctx, +int ustctl_add_context(int sock, struct lttng_ust_context_attr *ctx, struct lttng_ust_object_data *obj_data, struct lttng_ust_object_data **context_data); int ustctl_set_filter(int sock, struct lttng_ust_filter_bytecode *bytecode, diff --git a/src/bin/lttng-sessiond/trace-ust.c b/src/bin/lttng-sessiond/trace-ust.c index 4d39e2133..4ed8fb1a5 100644 --- a/src/bin/lttng-sessiond/trace-ust.c +++ b/src/bin/lttng-sessiond/trace-ust.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2011 - David Goulet + * Copyright (C) 2016 - Jérémie Galarneau * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2 only, @@ -518,7 +519,8 @@ error: } static -int trace_ust_context_type_event_to_ust(enum lttng_event_context_type type) +int trace_ust_context_type_event_to_ust( + enum lttng_event_context_type type) { int utype; @@ -546,6 +548,9 @@ int trace_ust_context_type_event_to_ust(enum lttng_event_context_type type) utype = LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER; } break; + case LTTNG_EVENT_CONTEXT_APP_CONTEXT: + utype = LTTNG_UST_CONTEXT_APP_CONTEXT; + break; default: utype = -1; break; @@ -599,7 +604,7 @@ int trace_ust_match_context(struct ltt_ust_context *uctx, struct ltt_ust_context *trace_ust_create_context( struct lttng_event_context *ctx) { - struct ltt_ust_context *uctx; + struct ltt_ust_context *uctx = NULL; int utype; assert(ctx); @@ -607,13 +612,13 @@ struct ltt_ust_context *trace_ust_create_context( utype = trace_ust_context_type_event_to_ust(ctx->ctx); if (utype < 0) { ERR("Invalid UST context"); - return NULL; + goto end; } uctx = zmalloc(sizeof(struct ltt_ust_context)); - if (uctx == NULL) { + if (!uctx) { PERROR("zmalloc ltt_ust_context"); - goto error; + goto end; } uctx->ctx.ctx = (enum lttng_ust_context_type) utype; @@ -625,14 +630,31 @@ struct ltt_ust_context *trace_ust_create_context( LTTNG_UST_SYM_NAME_LEN); uctx->ctx.u.perf_counter.name[LTTNG_UST_SYM_NAME_LEN - 1] = '\0'; break; + case LTTNG_UST_CONTEXT_APP_CONTEXT: + { + char *provider_name = NULL, *ctx_name = NULL; + + provider_name = strdup(ctx->u.app_ctx.provider_name); + if (!provider_name) { + goto error; + } + uctx->ctx.u.app_ctx.provider_name = provider_name; + + ctx_name = strdup(ctx->u.app_ctx.ctx_name); + if (!ctx_name) { + goto error; + } + uctx->ctx.u.app_ctx.ctx_name = ctx_name; + break; + } default: break; } lttng_ht_node_init_ulong(&uctx->node, (unsigned long) uctx->ctx.ctx); - +end: return uctx; - error: + trace_ust_destroy_context(uctx); return NULL; } @@ -931,7 +953,7 @@ static void destroy_context_rcu(struct rcu_head *head) struct ltt_ust_context *ctx = caa_container_of(node, struct ltt_ust_context, node); - free(ctx); + trace_ust_destroy_context(ctx); } /* @@ -976,6 +998,20 @@ void trace_ust_destroy_event(struct ltt_ust_event *event) free(event); } +/* + * Cleanup ust context structure. + */ +void trace_ust_destroy_context(struct ltt_ust_context *ctx) +{ + assert(ctx); + + if (ctx->ctx.ctx == LTTNG_UST_CONTEXT_APP_CONTEXT) { + free(ctx->ctx.u.app_ctx.provider_name); + free(ctx->ctx.u.app_ctx.ctx_name); + } + free(ctx); +} + /* * URCU intermediate call to complete destroy event. */ diff --git a/src/bin/lttng-sessiond/trace-ust.h b/src/bin/lttng-sessiond/trace-ust.h index 04b3e027c..5a48885d8 100644 --- a/src/bin/lttng-sessiond/trace-ust.h +++ b/src/bin/lttng-sessiond/trace-ust.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2011 - David Goulet + * Copyright (C) 2016 - Jérémie Galarneau * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2 only, @@ -40,7 +41,7 @@ struct ltt_ust_ht_key { /* Context hash table nodes */ struct ltt_ust_context { - struct lttng_ust_context ctx; + struct lttng_ust_context_attr ctx; struct lttng_ht_node_ulong node; struct cds_list_head list; }; @@ -209,6 +210,7 @@ void trace_ust_delete_channel(struct lttng_ht *ht, void trace_ust_destroy_session(struct ltt_ust_session *session); void trace_ust_destroy_channel(struct ltt_ust_channel *channel); void trace_ust_destroy_event(struct ltt_ust_event *event); +void trace_ust_destroy_context(struct ltt_ust_context *ctx); int trace_ust_track_pid(struct ltt_ust_session *session, int pid); int trace_ust_untrack_pid(struct ltt_ust_session *session, int pid); diff --git a/src/bin/lttng-sessiond/ust-app.c b/src/bin/lttng-sessiond/ust-app.c index 2bd48c7f3..8c45a89a5 100644 --- a/src/bin/lttng-sessiond/ust-app.c +++ b/src/bin/lttng-sessiond/ust-app.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2011 - David Goulet + * Copyright (C) 2016 - Jérémie Galarneau * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2 only, @@ -1037,7 +1038,7 @@ error: * Alloc new UST app context. */ static -struct ust_app_ctx *alloc_ust_app_ctx(struct lttng_ust_context *uctx) +struct ust_app_ctx *alloc_ust_app_ctx(struct lttng_ust_context_attr *uctx) { struct ust_app_ctx *ua_ctx; @@ -1050,12 +1051,27 @@ struct ust_app_ctx *alloc_ust_app_ctx(struct lttng_ust_context *uctx) if (uctx) { memcpy(&ua_ctx->ctx, uctx, sizeof(ua_ctx->ctx)); + if (uctx->ctx == LTTNG_UST_CONTEXT_APP_CONTEXT) { + char *provider_name = NULL, *ctx_name = NULL; + + provider_name = strdup(uctx->u.app_ctx.provider_name); + ctx_name = strdup(uctx->u.app_ctx.ctx_name); + if (!provider_name || !ctx_name) { + free(provider_name); + free(ctx_name); + goto error; + } + + ua_ctx->ctx.u.app_ctx.provider_name = provider_name; + ua_ctx->ctx.u.app_ctx.ctx_name = ctx_name; + } } DBG3("UST app context %d allocated", ua_ctx->ctx.ctx); - -error: return ua_ctx; +error: + free(ua_ctx); + return NULL; } /* @@ -1696,7 +1712,6 @@ static void shadow_copy_channel(struct ust_app_channel *ua_chan, struct ltt_ust_event *uevent; struct ltt_ust_context *uctx; struct ust_app_event *ua_event; - struct ust_app_ctx *ua_ctx; DBG2("UST app shadow copy of channel %s started", ua_chan->name); @@ -1722,7 +1737,8 @@ static void shadow_copy_channel(struct ust_app_channel *ua_chan, ua_chan->tracing_channel_id = uchan->id; cds_list_for_each_entry(uctx, &uchan->ctx_list, list) { - ua_ctx = alloc_ust_app_ctx(&uctx->ctx); + struct ust_app_ctx *ua_ctx = alloc_ust_app_ctx(&uctx->ctx); + if (ua_ctx == NULL) { continue; } @@ -2173,7 +2189,7 @@ error: static int ht_match_ust_app_ctx(struct cds_lfht_node *node, const void *_key) { struct ust_app_ctx *ctx; - const struct lttng_ust_context *key; + const struct lttng_ust_context_attr *key; assert(node); assert(_key); @@ -2186,13 +2202,24 @@ static int ht_match_ust_app_ctx(struct cds_lfht_node *node, const void *_key) goto no_match; } - /* Check the name in the case of perf thread counters. */ - if (key->ctx == LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER) { + switch(key->ctx) { + case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER: if (strncmp(key->u.perf_counter.name, - ctx->ctx.u.perf_counter.name, - sizeof(key->u.perf_counter.name))) { + ctx->ctx.u.perf_counter.name, + sizeof(key->u.perf_counter.name))) { + goto no_match; + } + break; + case LTTNG_UST_CONTEXT_APP_CONTEXT: + if (strcmp(key->u.app_ctx.provider_name, + ctx->ctx.u.app_ctx.provider_name) || + strcmp(key->u.app_ctx.ctx_name, + ctx->ctx.u.app_ctx.ctx_name)) { goto no_match; } + break; + default: + break; } /* Match. */ @@ -2210,7 +2237,7 @@ no_match: */ static struct ust_app_ctx *find_ust_app_context(struct lttng_ht *ht, - struct lttng_ust_context *uctx) + struct lttng_ust_context_attr *uctx) { struct lttng_ht_iter iter; struct lttng_ht_node_ulong *node; @@ -2240,7 +2267,8 @@ end: */ static int create_ust_app_channel_context(struct ust_app_session *ua_sess, - struct ust_app_channel *ua_chan, struct lttng_ust_context *uctx, + struct ust_app_channel *ua_chan, + struct lttng_ust_context_attr *uctx, struct ust_app *app) { int ret = 0; diff --git a/src/bin/lttng-sessiond/ust-app.h b/src/bin/lttng-sessiond/ust-app.h index 3daccba86..4398fe241 100644 --- a/src/bin/lttng-sessiond/ust-app.h +++ b/src/bin/lttng-sessiond/ust-app.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2011 - David Goulet + * Copyright (C) 2016 - Jérémie Galarneau * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2 only, @@ -101,7 +102,7 @@ struct ust_app_stream_list { struct ust_app_ctx { int handle; - struct lttng_ust_context ctx; + struct lttng_ust_context_attr ctx; struct lttng_ust_object_data *obj; struct lttng_ht_node_ulong node; struct cds_list_head list; diff --git a/src/common/sessiond-comm/agent.h b/src/common/sessiond-comm/agent.h index e8d182515..11acc52f9 100644 --- a/src/common/sessiond-comm/agent.h +++ b/src/common/sessiond-comm/agent.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2013 - David Goulet + * Copyright (C) 2016 - Jérémie Galarneau * * This program is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License, version 2 only, as @@ -26,10 +27,12 @@ * Command value passed in the header. */ enum lttcomm_agent_command { - AGENT_CMD_LIST = 1, - AGENT_CMD_ENABLE = 2, - AGENT_CMD_DISABLE = 3, - AGENT_CMD_REG_DONE = 4, /* End registration process. */ + AGENT_CMD_LIST = 1, + AGENT_CMD_ENABLE = 2, + AGENT_CMD_DISABLE = 3, + AGENT_CMD_REG_DONE = 4, /* End registration process. */ + AGENT_CMD_APP_CTX_ENABLE = 5, + AGENT_CMD_APP_CTX_DISABLE = 6, }; /* @@ -37,11 +40,11 @@ enum lttcomm_agent_command { */ enum lttcomm_agent_ret_code { /* Success, assumed to be the first entry */ - AGENT_RET_CODE_SUCCESS = 1, + AGENT_RET_CODE_SUCCESS = 1, /* Invalid command */ - AGENT_RET_CODE_INVALID = 2, + AGENT_RET_CODE_INVALID = 2, /* Unknown logger name */ - AGENT_RET_CODE_UNKNOWN_NAME = 3, + AGENT_RET_CODE_UNKNOWN_NAME = 3, AGENT_RET_CODE_NR, }; @@ -58,7 +61,7 @@ struct lttcomm_agent_hdr { * Enable event command payload. Will be immediately followed by the * variable-length string representing the filter expression. */ -struct lttcomm_agent_enable { +struct lttcomm_agent_enable_event { uint32_t loglevel_value; uint32_t loglevel_type; char name[LTTNG_SYMBOL_NAME_LEN]; @@ -68,7 +71,7 @@ struct lttcomm_agent_enable { /* * Disable event command payload. */ -struct lttcomm_agent_disable { +struct lttcomm_agent_disable_event { char name[LTTNG_SYMBOL_NAME_LEN]; } LTTNG_PACKED; -- 2.34.1 From d5734456436e1d49a7806d0fc7b948a76d738f20 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 18 Jan 2016 17:22:25 -0500 Subject: [PATCH 09/16] Add variant type support to ust registry and metadata MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/ust-metadata.c | 188 ++++++++++++++++++++++---- src/bin/lttng-sessiond/ust-registry.c | 19 ++- 2 files changed, 175 insertions(+), 32 deletions(-) diff --git a/src/bin/lttng-sessiond/ust-metadata.c b/src/bin/lttng-sessiond/ust-metadata.c index 984d5f813..585e23501 100644 --- a/src/bin/lttng-sessiond/ust-metadata.c +++ b/src/bin/lttng-sessiond/ust-metadata.c @@ -45,6 +45,11 @@ struct offset_sample { uint64_t measure_delta; /* lower is better */ }; +static +int _lttng_field_statedump(struct ust_registry_session *session, + const struct ustctl_field *fields, size_t nr_fields, + size_t *iter_field, size_t nesting); + static inline int fls(unsigned int x) { @@ -179,13 +184,29 @@ end: return ret; } +static +int print_tabs(struct ust_registry_session *session, size_t nesting) +{ + size_t i; + + for (i = 0; i < nesting; i++) { + int ret; + + ret = lttng_metadata_printf(session, " "); + if (ret) { + return ret; + } + } + return 0; +} + /* Called with session registry mutex held. */ static int ust_metadata_enum_statedump(struct ust_registry_session *session, const char *enum_name, uint64_t enum_id, const struct ustctl_integer_type *container_type, - const char *field_name) + const char *field_name, size_t *iter_field, size_t nesting) { struct ust_registry_enum *reg_enum; const struct ustctl_enum_entry *entries; @@ -204,8 +225,12 @@ int ust_metadata_enum_statedump(struct ust_registry_session *session, entries = reg_enum->entries; nr_entries = reg_enum->nr_entries; + ret = print_tabs(session, nesting); + if (ret) { + goto end; + } ret = lttng_metadata_printf(session, - " enum : integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u; } {\n", + "enum : integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u; } {\n", container_type->size, container_type->alignment, container_type->signedness, @@ -271,29 +296,85 @@ int ust_metadata_enum_statedump(struct ust_registry_session *session, } ret = lttng_metadata_printf(session, " } _%s;\n", field_name); +end: + (*iter_field)++; + return ret; +} + + +static +int _lttng_variant_statedump(struct ust_registry_session *session, + const struct ustctl_field *fields, size_t nr_fields, + size_t *iter_field, size_t nesting) +{ + const struct ustctl_field *variant = &fields[*iter_field]; + uint32_t nr_choices, i; + int ret; + + if (variant->type.atype != ustctl_atype_variant) { + ret = -EINVAL; + goto end; + } + nr_choices = variant->type.u.variant.nr_choices; + (*iter_field)++; + ret = lttng_metadata_printf(session, + " variant <_%s> {\n", + variant->type.u.variant.tag_name); + if (ret) { + goto end; + } + + for (i = 0; i < nr_choices; i++) { + if (*iter_field >= nr_fields) { + ret = -EOVERFLOW; + goto end; + } + ret = _lttng_field_statedump(session, + fields, nr_fields, + iter_field, nesting + 1); + } + ret = lttng_metadata_printf(session, + " } _%s;\n", + variant->name); + if (ret) { + goto end; + } end: return ret; } static int _lttng_field_statedump(struct ust_registry_session *session, - const struct ustctl_field *field) + const struct ustctl_field *fields, size_t nr_fields, + size_t *iter_field, size_t nesting) { int ret = 0; const char *bo_be = " byte_order = be;"; const char *bo_le = " byte_order = le;"; const char *bo_native = ""; const char *bo_reverse; + const struct ustctl_field *field; + + if (*iter_field >= nr_fields) { + ret = -EOVERFLOW; + goto end; + } + field = &fields[*iter_field]; - if (session->byte_order == BIG_ENDIAN) + if (session->byte_order == BIG_ENDIAN) { bo_reverse = bo_le; - else + } else { bo_reverse = bo_be; + } switch (field->type.atype) { case ustctl_atype_integer: + ret = print_tabs(session, nesting); + if (ret) { + goto end; + } ret = lttng_metadata_printf(session, - " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s;\n", + "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s;\n", field->type.u.basic.integer.size, field->type.u.basic.integer.alignment, field->type.u.basic.integer.signedness, @@ -305,30 +386,40 @@ int _lttng_field_statedump(struct ust_registry_session *session, field->type.u.basic.integer.base, field->type.u.basic.integer.reverse_byte_order ? bo_reverse : bo_native, field->name); + (*iter_field)++; break; case ustctl_atype_enum: ret = ust_metadata_enum_statedump(session, field->type.u.basic.enumeration.name, field->type.u.basic.enumeration.id, &field->type.u.basic.enumeration.container_type, - field->name); + field->name, iter_field, nesting); break; case ustctl_atype_float: + ret = print_tabs(session, nesting); + if (ret) { + goto end; + } ret = lttng_metadata_printf(session, - " floating_point { exp_dig = %u; mant_dig = %u; align = %u;%s } _%s;\n", + "floating_point { exp_dig = %u; mant_dig = %u; align = %u;%s } _%s;\n", field->type.u.basic._float.exp_dig, field->type.u.basic._float.mant_dig, field->type.u.basic._float.alignment, field->type.u.basic.integer.reverse_byte_order ? bo_reverse : bo_native, field->name); + (*iter_field)++; break; case ustctl_atype_array: { const struct ustctl_basic_type *elem_type; + ret = print_tabs(session, nesting); + if (ret) { + goto end; + } elem_type = &field->type.u.array.elem_type; ret = lttng_metadata_printf(session, - " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n", + "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n", elem_type->u.basic.integer.size, elem_type->u.basic.integer.alignment, elem_type->u.basic.integer.signedness, @@ -340,6 +431,7 @@ int _lttng_field_statedump(struct ust_registry_session *session, elem_type->u.basic.integer.base, elem_type->u.basic.integer.reverse_byte_order ? bo_reverse : bo_native, field->name, field->type.u.array.length); + (*iter_field)++; break; } case ustctl_atype_sequence: @@ -349,8 +441,12 @@ int _lttng_field_statedump(struct ust_registry_session *session, elem_type = &field->type.u.sequence.elem_type; length_type = &field->type.u.sequence.length_type; + ret = print_tabs(session, nesting); + if (ret) { + goto end; + } ret = lttng_metadata_printf(session, - " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n", + "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n", length_type->u.basic.integer.size, (unsigned int) length_type->u.basic.integer.alignment, length_type->u.basic.integer.signedness, @@ -362,11 +458,16 @@ int _lttng_field_statedump(struct ust_registry_session *session, length_type->u.basic.integer.base, length_type->u.basic.integer.reverse_byte_order ? bo_reverse : bo_native, field->name); - if (ret) - return ret; + if (ret) { + goto end; + } + ret = print_tabs(session, nesting); + if (ret) { + goto end; + } ret = lttng_metadata_printf(session, - " integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n", + "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n", elem_type->u.basic.integer.size, (unsigned int) elem_type->u.basic.integer.alignment, elem_type->u.basic.integer.signedness, @@ -379,20 +480,43 @@ int _lttng_field_statedump(struct ust_registry_session *session, elem_type->u.basic.integer.reverse_byte_order ? bo_reverse : bo_native, field->name, field->name); + (*iter_field)++; break; } case ustctl_atype_string: /* Default encoding is UTF8 */ + ret = print_tabs(session, nesting); + if (ret) { + goto end; + } ret = lttng_metadata_printf(session, - " string%s _%s;\n", + "string%s _%s;\n", field->type.u.basic.string.encoding == ustctl_encode_ASCII ? " { encoding = ASCII; }" : "", field->name); + (*iter_field)++; + break; + case ustctl_atype_variant: + ret = _lttng_variant_statedump(session, fields, nr_fields, iter_field, nesting); + if (ret) { + goto end; + } + break; + case ustctl_atype_struct: + ret = print_tabs(session, nesting); + if (ret) { + goto end; + } + ret = lttng_metadata_printf(session, + "struct {} _%s;\n", + field->name); + (*iter_field)++; break; default: - return -EINVAL; + ret = -EINVAL; } +end: return ret; } @@ -402,16 +526,19 @@ int _lttng_context_metadata_statedump(struct ust_registry_session *session, struct ustctl_field *ctx) { int ret = 0; - int i; + size_t i = 0; if (!ctx) return 0; - for (i = 0; i < nr_ctx_fields; i++) { - const struct ustctl_field *field = &ctx[i]; - - ret = _lttng_field_statedump(session, field); - if (ret) - return ret; + for (;;) { + if (i >= nr_ctx_fields) { + break; + } + ret = _lttng_field_statedump(session, ctx, + nr_ctx_fields, &i, 2); + if (ret) { + break; + } } return ret; } @@ -421,14 +548,17 @@ int _lttng_fields_metadata_statedump(struct ust_registry_session *session, struct ust_registry_event *event) { int ret = 0; - int i; + size_t i = 0; - for (i = 0; i < event->nr_fields; i++) { - const struct ustctl_field *field = &event->fields[i]; - - ret = _lttng_field_statedump(session, field); - if (ret) - return ret; + for (;;) { + if (i >= event->nr_fields) { + break; + } + ret = _lttng_field_statedump(session, event->fields, + event->nr_fields, &i, 2); + if (ret) { + break; + } } return ret; } diff --git a/src/bin/lttng-sessiond/ust-registry.c b/src/bin/lttng-sessiond/ust-registry.c index 80ea2e570..1990655ef 100644 --- a/src/bin/lttng-sessiond/ust-registry.c +++ b/src/bin/lttng-sessiond/ust-registry.c @@ -188,12 +188,22 @@ int validate_event_field(struct ustctl_field *field, const char *event_name, struct ust_app *app) { + int ret = 0; + switch(field->type.atype) { case ustctl_atype_integer: case ustctl_atype_enum: case ustctl_atype_array: case ustctl_atype_sequence: case ustctl_atype_string: + case ustctl_atype_variant: + break; + case ustctl_atype_struct: + if (field->type.u._struct.nr_fields != 0) { + WARN("Unsupported non-empty struct field."); + ret = -EINVAL; + goto end; + } break; case ustctl_atype_float: @@ -205,16 +215,19 @@ int validate_event_field(struct ustctl_field *field, field->type.u.basic._float.mant_dig, field->name, event_name); - return -EINVAL; + ret = -EINVAL; + goto end; default: break; } break; default: - return -ENOENT; + ret = -ENOENT; + goto end; } - return 0; +end: + return ret; } static -- 2.34.1 From b11392a1271d6a8e552f6f509f69a2e32f0c1a2b Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 26 Jan 2016 10:14:17 -0500 Subject: [PATCH 10/16] Allow $app.provider:ctxname in filter, enum, variant identifiers MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Mathieu Desnoyers Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/ust-metadata.c | 51 ++++++++++++++++--- src/lib/lttng-ctl/filter/filter-lexer.l | 3 +- .../filter/filter-visitor-generate-ir.c | 38 ++++++-------- 3 files changed, 61 insertions(+), 31 deletions(-) diff --git a/src/bin/lttng-sessiond/ust-metadata.c b/src/bin/lttng-sessiond/ust-metadata.c index 585e23501..4fcdf2b1e 100644 --- a/src/bin/lttng-sessiond/ust-metadata.c +++ b/src/bin/lttng-sessiond/ust-metadata.c @@ -200,6 +200,24 @@ int print_tabs(struct ust_registry_session *session, size_t nesting) return 0; } +static +void sanitize_ctf_identifier(char *out, const char *in) +{ + size_t i; + + for (i = 0; i < LTTNG_UST_SYM_NAME_LEN; i++) { + switch (in[i]) { + case '.': + case '$': + case ':': + out[i] = '_'; + break; + default: + out[i] = in[i]; + } + } +} + /* Called with session registry mutex held. */ static int ust_metadata_enum_statedump(struct ust_registry_session *session, @@ -213,6 +231,7 @@ int ust_metadata_enum_statedump(struct ust_registry_session *session, size_t nr_entries; int ret = 0; size_t i; + char identifier[LTTNG_UST_SYM_NAME_LEN]; rcu_read_lock(); reg_enum = ust_registry_lookup_enum_by_id(session, enum_name, enum_id); @@ -248,8 +267,12 @@ int ust_metadata_enum_statedump(struct ust_registry_session *session, const struct ustctl_enum_entry *entry = &entries[i]; int j, len; + ret = print_tabs(session, nesting); + if (ret) { + goto end; + } ret = lttng_metadata_printf(session, - " \""); + "\""); if (ret) { goto end; } @@ -294,14 +317,18 @@ int ust_metadata_enum_statedump(struct ust_registry_session *session, goto end; } } - ret = lttng_metadata_printf(session, " } _%s;\n", - field_name); + sanitize_ctf_identifier(identifier, field_name); + ret = print_tabs(session, nesting); + if (ret) { + goto end; + } + ret = lttng_metadata_printf(session, "} _%s;\n", + identifier); end: (*iter_field)++; return ret; } - static int _lttng_variant_statedump(struct ust_registry_session *session, const struct ustctl_field *fields, size_t nr_fields, @@ -310,6 +337,7 @@ int _lttng_variant_statedump(struct ust_registry_session *session, const struct ustctl_field *variant = &fields[*iter_field]; uint32_t nr_choices, i; int ret; + char identifier[LTTNG_UST_SYM_NAME_LEN]; if (variant->type.atype != ustctl_atype_variant) { ret = -EINVAL; @@ -317,9 +345,14 @@ int _lttng_variant_statedump(struct ust_registry_session *session, } nr_choices = variant->type.u.variant.nr_choices; (*iter_field)++; + sanitize_ctf_identifier(identifier, variant->type.u.variant.tag_name); + ret = print_tabs(session, nesting); + if (ret) { + goto end; + } ret = lttng_metadata_printf(session, - " variant <_%s> {\n", - variant->type.u.variant.tag_name); + "variant <_%s> {\n", + identifier); if (ret) { goto end; } @@ -333,9 +366,11 @@ int _lttng_variant_statedump(struct ust_registry_session *session, fields, nr_fields, iter_field, nesting + 1); } + sanitize_ctf_identifier(identifier, variant->name); + ret = print_tabs(session, nesting); ret = lttng_metadata_printf(session, - " } _%s;\n", - variant->name); + "} _%s;\n", + identifier); if (ret) { goto end; } diff --git a/src/lib/lttng-ctl/filter/filter-lexer.l b/src/lib/lttng-ctl/filter/filter-lexer.l index ab887f74c..a45b6e838 100644 --- a/src/lib/lttng-ctl/filter/filter-lexer.l +++ b/src/lib/lttng-ctl/filter/filter-lexer.l @@ -49,7 +49,8 @@ HEXDIGIT [0-9A-Fa-f] OCTALDIGIT [0-7] UCHARLOWERCASE \\u{HEXDIGIT}{4} UCHARUPPERCASE \\U{HEXDIGIT}{8} -ID_NONDIGIT {NONDIGIT}|{UCHARLOWERCASE}|{UCHARUPPERCASE} +ID_EXTRA_CHAR (":"|".") +ID_NONDIGIT {NONDIGIT}|{UCHARLOWERCASE}|{UCHARUPPERCASE}|{ID_EXTRA_CHAR} IDENTIFIER {ID_NONDIGIT}({ID_NONDIGIT}|{DIGIT})* ESCSEQ \\(\'|\"|\?|\\|a|b|f|n|r|t|v|{OCTALDIGIT}{1,3}|u{HEXDIGIT}{4}|U{HEXDIGIT}{8}|x{HEXDIGIT}+) %% diff --git a/src/lib/lttng-ctl/filter/filter-visitor-generate-ir.c b/src/lib/lttng-ctl/filter/filter-visitor-generate-ir.c index d694dcc16..f734b56e3 100644 --- a/src/lib/lttng-ctl/filter/filter-visitor-generate-ir.c +++ b/src/lib/lttng-ctl/filter/filter-visitor-generate-ir.c @@ -418,36 +418,30 @@ struct ir_op *make_expression(struct filter_parser_ctx *ctx, side); case AST_EXP_GLOBAL_IDENTIFIER: { - struct filter_node *next; + const char *name; - if (node->u.expression.pre_op == AST_LINK_UNKNOWN) { - fprintf(stderr, "[error] %s: global identifiers need chained identifier \n", __func__); - return NULL; - } - /* We currently only support $ctx (context) identifiers */ + /* + * We currently only support $ctx (context) and $app + * identifiers. + */ if (strncmp(node->u.expression.u.identifier, - "$ctx", strlen("$ctx")) != 0) { - fprintf(stderr, "[error] %s: \"%s\" global identifier is unknown. Only \"$ctx\" currently implemented.\n", __func__, node->u.expression.u.identifier); - return NULL; - } - next = node->u.expression.next; - if (!next) { - fprintf(stderr, "[error] %s: Expecting a context name, e.g. \'$ctx.name\'.\n", __func__); + "$ctx.", strlen("$ctx.")) != 0 + && strncmp(node->u.expression.u.identifier, + "$app.", strlen("$app.")) != 0) { + fprintf(stderr, "[error] %s: \"%s\" global identifier is unknown. Only \"$ctx\" and \"$app\" are currently implemented.\n", __func__, node->u.expression.u.identifier); return NULL; } - if (next->type != NODE_EXPRESSION) { - fprintf(stderr, "[error] %s: Expecting expression.\n", __func__); + name = strchr(node->u.expression.u.identifier, '.'); + if (!name) { + fprintf(stderr, "[error] %s: Expecting '.'\n", __func__); return NULL; } - if (next->u.expression.type != AST_EXP_IDENTIFIER) { - fprintf(stderr, "[error] %s: Expecting identifier.\n", __func__); - return NULL; - } - if (next->u.expression.pre_op != AST_LINK_UNKNOWN) { - fprintf(stderr, "[error] %s: dotted and dereferenced identifiers not supported after identifier\n", __func__); + name++; /* Skip . */ + if (!strlen(name)) { + fprintf(stderr, "[error] %s: Expecting a context name, e.g. \'$ctx.name\'.\n", __func__); return NULL; } - return make_op_load_get_context_ref(next->u.expression.u.identifier, + return make_op_load_get_context_ref(node->u.expression.u.identifier, side); } case AST_EXP_NESTED: -- 2.34.1 From 8fb1291c63c56ea15363a2628e7a8bac9b9c035c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Wed, 3 Feb 2016 18:51:29 -0500 Subject: [PATCH 11/16] Compare provider and context names in trace_ust_match_context MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/trace-ust.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/bin/lttng-sessiond/trace-ust.c b/src/bin/lttng-sessiond/trace-ust.c index 4ed8fb1a5..1c325fb25 100644 --- a/src/bin/lttng-sessiond/trace-ust.c +++ b/src/bin/lttng-sessiond/trace-ust.c @@ -589,6 +589,15 @@ int trace_ust_match_context(struct ltt_ust_context *uctx, return 0; } break; + case LTTNG_UST_CONTEXT_APP_CONTEXT: + assert(uctx->ctx.u.app_ctx.provider_name); + assert(uctx->ctx.u.app_ctx.ctx_name); + if (strcmp(uctx->ctx.u.app_ctx.provider_name, + ctx->u.app_ctx.provider_name) || + strcmp(uctx->ctx.u.app_ctx.ctx_name, + ctx->u.app_ctx.ctx_name)) { + return 0; + } default: break; -- 2.34.1 From aa217ae263e7509be2907c1c28aebbade15da6db Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Fri, 5 Feb 2016 17:10:41 -0500 Subject: [PATCH 12/16] Enable agent application contexts if filter has such dependencies MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/cmd.c | 2 +- src/bin/lttng-sessiond/event.c | 74 +++++++++++++++++++++++- src/common/Makefile.am | 3 +- src/common/context.c | 93 ++++++++++++++++++++++++++++++ src/common/context.h | 35 ++++++++++++ src/common/filter.c | 100 +++++++++++++++++++++++++++++++++ src/common/filter.h | 46 +++++++++++++++ 7 files changed, 350 insertions(+), 3 deletions(-) create mode 100644 src/common/context.c create mode 100644 src/common/context.h create mode 100644 src/common/filter.c create mode 100644 src/common/filter.h diff --git a/src/bin/lttng-sessiond/cmd.c b/src/bin/lttng-sessiond/cmd.c index eca3cf439..83286a002 100644 --- a/src/bin/lttng-sessiond/cmd.c +++ b/src/bin/lttng-sessiond/cmd.c @@ -1790,7 +1790,7 @@ static int _cmd_enable_event(struct ltt_session *session, filter_expression = NULL; filter = NULL; exclusion = NULL; - if (ret != LTTNG_OK) { + if (ret != LTTNG_OK && ret != LTTNG_ERR_UST_EVENT_ENABLED) { goto error; } break; diff --git a/src/bin/lttng-sessiond/event.c b/src/bin/lttng-sessiond/event.c index e4c79df74..b7b80d366 100644 --- a/src/bin/lttng-sessiond/event.c +++ b/src/bin/lttng-sessiond/event.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2011 - David Goulet + * Copyright (C) 2016 - Jérémie Galarneau * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License, version 2 only, @@ -23,6 +24,8 @@ #include #include #include +#include +#include #include "channel.h" #include "event.h" @@ -416,6 +419,67 @@ error: return ret; } +/* + * Check if this event's filter requires the activation of application contexts + * and enable them in the agent. + */ +static int add_filter_app_ctx(struct lttng_filter_bytecode *bytecode, + const char *filter_expression, struct agent *agt) +{ + int ret = LTTNG_OK; + char *provider_name = NULL, *ctx_name = NULL; + struct bytecode_symbol_iterator *it = + bytecode_symbol_iterator_create(bytecode); + + if (!it) { + ret = LTTNG_ERR_NOMEM; + goto end; + } + + do { + struct lttng_event_context ctx; + const char *symbol_name = + bytecode_symbol_iterator_get_name(it); + + if (parse_application_context(symbol_name, &provider_name, + &ctx_name)) { + /* Not an application context. */ + continue; + } + + ctx.ctx = LTTNG_EVENT_CONTEXT_APP_CONTEXT; + ctx.u.app_ctx.provider_name = provider_name; + ctx.u.app_ctx.ctx_name = ctx_name; + + /* Recognized an application context. */ + DBG("Enabling event with filter expression \"%s\" requires enabling the %s:%s application context.", + filter_expression, provider_name, ctx_name); + + ret = agent_add_context(&ctx, agt); + if (ret != LTTNG_OK) { + ERR("Failed to add application context %s:%s.", + provider_name, ctx_name); + goto end; + } + + ret = agent_enable_context(&ctx, agt->domain); + if (ret != LTTNG_OK) { + ERR("Failed to enable application context %s:%s.", + provider_name, ctx_name); + goto end; + } + + free(provider_name); + free(ctx_name); + provider_name = ctx_name = NULL; + } while (bytecode_symbol_iterator_next(it) == 0); +end: + free(provider_name); + free(ctx_name); + bytecode_symbol_iterator_destroy(it); + return ret; +} + /* * Enable a single agent event for a given UST session. * @@ -439,7 +503,7 @@ int event_agent_enable(struct ltt_ust_session *usess, filter_expression ? filter_expression : "NULL"); aevent = agent_find_event(event->name, event->loglevel_type, - event->loglevel, filter_expression, agt); + event->loglevel, filter_expression, agt); if (!aevent) { aevent = agent_create_event(event->name, event->loglevel_type, event->loglevel, filter, @@ -448,6 +512,7 @@ int event_agent_enable(struct ltt_ust_session *usess, ret = LTTNG_ERR_NOMEM; goto error; } + created = 1; } @@ -456,6 +521,13 @@ int event_agent_enable(struct ltt_ust_session *usess, goto end; } + if (created && filter) { + ret = add_filter_app_ctx(filter, filter_expression, agt); + if (ret != LTTNG_OK) { + goto error; + } + } + ret = agent_enable_event(aevent, agt->domain); if (ret != LTTNG_OK) { goto error; diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 148130177..66146bb73 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -72,7 +72,8 @@ libcommon_la_SOURCES = error.h error.c utils.c utils.h runas.c runas.h \ pipe.c pipe.h readwrite.c readwrite.h \ mi-lttng.h mi-lttng.c \ daemonize.c daemonize.h \ - sessiond-comm/unix.c sessiond-comm/unix.h + sessiond-comm/unix.c sessiond-comm/unix.h \ + filter.c filter.h context.c context.h libcommon_la_LIBADD = \ -luuid \ diff --git a/src/common/context.c b/src/common/context.c new file mode 100644 index 000000000..ead6bb3f5 --- /dev/null +++ b/src/common/context.c @@ -0,0 +1,93 @@ +/* + * context.c + * + * LTTng context utilities. + * + * Copyright 2016 - Jérémie Galarneau + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License, version 2.1 only, + * as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "context.h" +#include +#include +#include +#include + +int parse_application_context(const char *str, char **out_provider_name, + char **out_ctx_name) +{ + const char app_ctx_prefix[] = "$app."; + char *provider_name = NULL, *ctx_name = NULL; + size_t i, len, colon_pos = 0, provider_name_len, ctx_name_len; + + if (!str || !out_provider_name || !out_ctx_name) { + goto not_found; + } + + len = strlen(str); + if (len <= sizeof(app_ctx_prefix) - 1) { + goto not_found; + } + + /* String starts with $app. */ + if (strncmp(str, app_ctx_prefix, sizeof(app_ctx_prefix) - 1)) { + goto not_found; + } + + /* Validate that the ':' separator is present. */ + for (i = sizeof(app_ctx_prefix); i < len; i++) { + const char c = str[i]; + + if (c == ':') { + colon_pos = i; + break; + } + } + + /* + * No colon found or no ctx name ("$app.provider:") or no provider name + * given ("$app.:..."), which is invalid. + */ + if (!colon_pos || colon_pos == len || + colon_pos == sizeof(app_ctx_prefix)) { + goto not_found; + } + + provider_name_len = colon_pos - sizeof(app_ctx_prefix) + 2; + provider_name = zmalloc(provider_name_len); + if (!provider_name) { + PERROR("malloc provider_name"); + goto not_found; + } + strncpy(provider_name, str + sizeof(app_ctx_prefix) - 1, + provider_name_len - 1); + + ctx_name_len = len - colon_pos; + ctx_name = zmalloc(ctx_name_len); + if (!ctx_name) { + PERROR("malloc ctx_name"); + goto not_found; + } + strncpy(ctx_name, str + colon_pos + 1, ctx_name_len - 1); + + *out_provider_name = provider_name; + *out_ctx_name = ctx_name; + return 0; +not_found: + free(provider_name); + free(ctx_name); + return -1; +} + diff --git a/src/common/context.h b/src/common/context.h new file mode 100644 index 000000000..5552f4da5 --- /dev/null +++ b/src/common/context.h @@ -0,0 +1,35 @@ +/* + * Copyright 2016 - Jérémie Galarneau + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License, version 2 only, as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef LTTNG_COMMON_CONTEXT_H +#define LTTNG_COMMON_CONTEXT_H + +/* + * Parse string as an application context of the form + * "$app.provider_name:context_name" and return the provider name and context + * name separately. + * + * provider_name and ctx_name are returned only if an application context name + * was successfully parsed and must be freed by the caller. + * + * Returns 0 if the string is a valid application context, else a negative + * value on error. + */ +int parse_application_context(const char *str, char **provider_name, + char **ctx_name); + +#endif /* LTTNG_COMMON_CONTEXT_H */ diff --git a/src/common/filter.c b/src/common/filter.c new file mode 100644 index 000000000..f103d240f --- /dev/null +++ b/src/common/filter.c @@ -0,0 +1,100 @@ +/* + * filter.c + * + * LTTng filter bytecode utilities. + * + * Copyright 2016 - Jérémie Galarneau + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License, version 2.1 only, + * as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "filter.h" +#include + +struct bytecode_symbol_iterator { + /* No ownership of bytecode is taken. */ + char *bytecode; + size_t offset, len; +}; + +struct bytecode_symbol_iterator *bytecode_symbol_iterator_create( + struct lttng_filter_bytecode *bytecode) +{ + struct bytecode_symbol_iterator *it = NULL; + + if (!bytecode) { + goto end; + } + + it = zmalloc(sizeof(*it)); + if (!it) { + goto end; + } + + it->bytecode = bytecode->data; + it->offset = bytecode->reloc_table_offset; + it->len = bytecode->len; +end: + return it; +} + +int bytecode_symbol_iterator_next(struct bytecode_symbol_iterator *it) +{ + int ret; + size_t len; + + if (!it || it->offset >= it->len) { + ret = -1; + goto end; + } + + len = strlen(it->bytecode + it->offset + sizeof(uint16_t)) + 1; + it->offset += len + sizeof(uint16_t); + ret = it->offset >= it->len ? -1 : 0; +end: + return ret; +} + +int bytecode_symbol_iterator_get_type(struct bytecode_symbol_iterator *it) +{ + int ret; + + if (!it) { + ret = -1; + goto end; + } + + ret = *((uint16_t *) (it->bytecode + it->offset)); +end: + return ret; + } + +const char *bytecode_symbol_iterator_get_name( + struct bytecode_symbol_iterator *it) +{ + const char *ret = NULL; + + if (!it) { + goto end; + } + + ret = it->bytecode + it->offset + sizeof(uint16_t); +end: + return ret; +} + +void bytecode_symbol_iterator_destroy(struct bytecode_symbol_iterator *it) +{ + free(it); +} diff --git a/src/common/filter.h b/src/common/filter.h new file mode 100644 index 000000000..051177a0e --- /dev/null +++ b/src/common/filter.h @@ -0,0 +1,46 @@ +/* + * Copyright 2016 - Jérémie Galarneau + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License, version 2 only, as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., 51 + * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef LTTNG_COMMON_FILTER_H +#define LTTNG_COMMON_FILTER_H + +#include + +struct bytecode_symbol_iterator; + +/* + * Create an iterator on a bytecode's symbols. The iterator points to the + * first element after creation. + */ +struct bytecode_symbol_iterator *bytecode_symbol_iterator_create( + struct lttng_filter_bytecode *bytecode); + +/* + * Advance iterator of one element. + * + * Returns 0 if a next element exists or a negative value at the end. + */ +int bytecode_symbol_iterator_next(struct bytecode_symbol_iterator *it); + +int bytecode_symbol_iterator_get_type(struct bytecode_symbol_iterator *it); + +const char *bytecode_symbol_iterator_get_name( + struct bytecode_symbol_iterator *it); + +void bytecode_symbol_iterator_destroy(struct bytecode_symbol_iterator *it); + +#endif /* LTTNG_COMMON_FILTER_H */ -- 2.34.1 From a98e27bfab122c75634b9d43164061963be60bc2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 9 Feb 2016 15:11:32 -0500 Subject: [PATCH 13/16] Fix typos in error descriptions MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- include/lttng/lttng-error.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/lttng/lttng-error.h b/include/lttng/lttng-error.h index 1340dc29b..65ec20572 100644 --- a/include/lttng/lttng-error.h +++ b/include/lttng/lttng-error.h @@ -32,7 +32,7 @@ extern "C" { enum lttng_error_code { LTTNG_OK = 10, /* Ok */ LTTNG_ERR_UNK = 11, /* Unknown Error */ - LTTNG_ERR_UND = 12, /* Undefine command */ + LTTNG_ERR_UND = 12, /* Undefined command */ LTTNG_ERR_SESSION_STARTED = 13, /* Session is running */ LTTNG_ERR_UNKNOWN_DOMAIN = 14, /* Tracing domain not known */ LTTNG_ERR_NOT_SUPPORTED = 15, /* Operation not supported */ @@ -106,7 +106,7 @@ enum lttng_error_code { LTTNG_ERR_NEED_CHANNEL_NAME = 83, /* Non-default channel exists within session: channel name needs to be specified with '-c name' */ LTTNG_ERR_NO_UST = 84, /* LTTng-UST tracer is not supported. Please rebuild lttng-tools with lttng-ust support enabled. */ LTTNG_ERR_SAVE_FILE_EXIST = 85, /* Session file already exists. */ - LTTNG_ERR_SAVE_IO_FAIL = 86, /* IO error while writting session configuration */ + LTTNG_ERR_SAVE_IO_FAIL = 86, /* IO error while writing session configuration */ LTTNG_ERR_LOAD_INVALID_CONFIG = 87, /* Invalid session configuration */ LTTNG_ERR_LOAD_IO_FAIL = 88, /* IO error while reading a session configuration */ LTTNG_ERR_LOAD_SESSION_NOENT = 89, /* Session file not found */ -- 2.34.1 From a44b83a535d147f8c04441a3e465996bb6b83903 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 9 Feb 2016 15:12:33 -0500 Subject: [PATCH 14/16] Introduce application contexts to session configuration schema MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Session configuration schema version is bumped to 2.8. Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/save.c | 195 +++++++++++++++++-------- src/common/config/config-session-abi.h | 6 +- src/common/config/session-config.c | 45 +++++- src/common/config/session.xsd | 11 +- 4 files changed, 193 insertions(+), 64 deletions(-) diff --git a/src/bin/lttng-sessiond/save.c b/src/bin/lttng-sessiond/save.c index a6fea46ce..b33287855 100644 --- a/src/bin/lttng-sessiond/save.c +++ b/src/bin/lttng-sessiond/save.c @@ -261,6 +261,9 @@ const char *get_ust_context_type_string( case LTTNG_UST_CONTEXT_PTHREAD_ID: context_type_string = config_event_context_pthread_id; break; + case LTTNG_UST_CONTEXT_APP_CONTEXT: + context_type_string = config_event_context_app; + break; case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER: /* * Error, should not be stored in the XML, perf contexts @@ -845,7 +848,8 @@ int save_kernel_context(struct config_writer *writer, } if (ctx->ctx == LTTNG_KERNEL_CONTEXT_PERF_CPU_COUNTER) { - ret = config_writer_open_element(writer, config_element_perf); + ret = config_writer_open_element(writer, + config_element_context_perf); if (ret) { ret = LTTNG_ERR_SAVE_IO_FAIL; goto end; @@ -942,6 +946,124 @@ end: return ret; } +static +int save_ust_context_perf_thread_counter(struct config_writer *writer, + struct ltt_ust_context *ctx) +{ + int ret; + + assert(writer); + assert(ctx); + + /* Perf contexts are saved as event_perf_context_type */ + ret = config_writer_open_element(writer, config_element_context_perf); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + + ret = config_writer_write_element_unsigned_int(writer, + config_element_type, ctx->ctx.u.perf_counter.type); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + + ret = config_writer_write_element_unsigned_int(writer, + config_element_config, ctx->ctx.u.perf_counter.config); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + + ret = config_writer_write_element_string(writer, config_element_name, + ctx->ctx.u.perf_counter.name); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + + /* /perf */ + ret = config_writer_close_element(writer); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } +end: + return ret; +} + +static +int save_ust_context_app_ctx(struct config_writer *writer, + struct ltt_ust_context *ctx) +{ + int ret; + + assert(writer); + assert(ctx); + + /* Application contexts are saved as application_context_type */ + ret = config_writer_open_element(writer, config_element_context_app); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + + ret = config_writer_write_element_string(writer, + config_element_context_app_provider_name, + ctx->ctx.u.app_ctx.provider_name); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + + ret = config_writer_write_element_string(writer, + config_element_context_app_ctx_name, + ctx->ctx.u.app_ctx.ctx_name); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + + /* /app */ + ret = config_writer_close_element(writer); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } +end: + return ret; +} + +static +int save_ust_context_generic(struct config_writer *writer, + struct ltt_ust_context *ctx) +{ + int ret; + const char *context_type_string; + + assert(writer); + assert(ctx); + + /* Save context as event_context_type_type */ + context_type_string = get_ust_context_type_string( + ctx->ctx.ctx); + if (!context_type_string) { + ERR("Unsupported UST context type."); + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } + + ret = config_writer_write_element_string(writer, + config_element_type, context_type_string); + if (ret) { + ret = LTTNG_ERR_SAVE_IO_FAIL; + goto end; + } +end: + return ret; +} + static int save_ust_context(struct config_writer *writer, struct cds_list_head *ctx_list) @@ -959,9 +1081,6 @@ int save_ust_context(struct config_writer *writer, } cds_list_for_each_entry(ctx, ctx_list, list) { - const char *context_type_string; - - ret = config_writer_open_element(writer, config_element_context); if (ret) { @@ -969,61 +1088,19 @@ int save_ust_context(struct config_writer *writer, goto end; } - if (ctx->ctx.ctx == LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER) { - /* Perf contexts are saved as event_perf_context_type */ - ret = config_writer_open_element(writer, - config_element_perf); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; - } - - ret = config_writer_write_element_unsigned_int(writer, - config_element_type, - ctx->ctx.u.perf_counter.type); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; - } - - ret = config_writer_write_element_unsigned_int(writer, - config_element_config, - ctx->ctx.u.perf_counter.config); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; - } - - ret = config_writer_write_element_string(writer, - config_element_name, - ctx->ctx.u.perf_counter.name); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; - } - - /* /perf */ - ret = config_writer_close_element(writer); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; - } - } else { - /* Save context as event_context_type_type */ - context_type_string = get_ust_context_type_string( - ctx->ctx.ctx); - if (!context_type_string) { - ERR("Unsupported UST context type.") - ret = LTTNG_ERR_INVALID; - goto end; - } - - ret = config_writer_write_element_string(writer, - config_element_type, context_type_string); - if (ret) { - ret = LTTNG_ERR_SAVE_IO_FAIL; - goto end; - } + switch (ctx->ctx.ctx) { + case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER: + ret = save_ust_context_perf_thread_counter(writer, ctx); + break; + case LTTNG_UST_CONTEXT_APP_CONTEXT: + ret = save_ust_context_app_ctx(writer, ctx); + break; + default: + /* Save generic context. */ + ret = save_ust_context_generic(writer, ctx); + } + if (ret) { + goto end; } /* /context */ diff --git a/src/common/config/config-session-abi.h b/src/common/config/config-session-abi.h index 9251b22fc..23f8c8416 100644 --- a/src/common/config/config-session-abi.h +++ b/src/common/config/config-session-abi.h @@ -50,7 +50,10 @@ extern const char * const config_element_type; extern const char * const config_element_buffer_type; extern const char * const config_element_session; extern const char * const config_element_sessions; -extern const char * const config_element_perf; +extern const char * const config_element_context_perf; +extern const char * const config_element_context_app; +extern const char * const config_element_context_app_provider_name; +extern const char * const config_element_context_app_ctx_name; extern const char * const config_element_config; extern const char * const config_element_started; extern const char * const config_element_snapshot_mode; @@ -116,5 +119,6 @@ extern const char * const config_event_context_pthread_id; extern const char * const config_event_context_hostname; extern const char * const config_event_context_ip; extern const char * const config_event_context_perf_thread_counter; +extern const char * const config_event_context_app; #endif /* CONFIG_SESSION_INTERNAL_H */ diff --git a/src/common/config/session-config.c b/src/common/config/session-config.c index 87e9c03c8..ba938d9f1 100644 --- a/src/common/config/session-config.c +++ b/src/common/config/session-config.c @@ -99,7 +99,10 @@ const char * const config_element_type = "type"; const char * const config_element_buffer_type = "buffer_type"; const char * const config_element_session = "session"; const char * const config_element_sessions = "sessions"; -const char * const config_element_perf = "perf"; +const char * const config_element_context_perf = "perf"; +const char * const config_element_context_app = "app"; +const char * const config_element_context_app_provider_name = "provider_name"; +const char * const config_element_context_app_ctx_name = "ctx_name"; const char * const config_element_config = "config"; const char * const config_element_started = "started"; const char * const config_element_snapshot_mode = "snapshot_mode"; @@ -165,6 +168,8 @@ const char * const config_event_context_pthread_id = "PTHREAD_ID"; const char * const config_event_context_hostname = "HOSTNAME"; const char * const config_event_context_ip = "IP"; const char * const config_event_context_perf_thread_counter = "PERF_THREAD_COUNTER"; +const char * const config_event_context_app = "APP"; + struct consumer_output { int enabled; @@ -1991,6 +1996,7 @@ int process_context_node(xmlNodePtr context_node, config_element_type)) { /* type */ xmlChar *content = xmlNodeGetContent(context_child_node); + if (!content) { ret = -LTTNG_ERR_NOMEM; goto end; @@ -2004,10 +2010,11 @@ int process_context_node(xmlNodePtr context_node, } context.ctx = ret; - } else { + } else if (!strcmp((const char *) context_child_node->name, + config_element_context_perf)) { + /* perf */ xmlNodePtr perf_attr_node; - /* perf */ context.ctx = handle->domain.type == LTTNG_DOMAIN_KERNEL ? LTTNG_EVENT_CONTEXT_PERF_CPU_COUNTER : LTTNG_EVENT_CONTEXT_PERF_THREAD_COUNTER; @@ -2085,9 +2092,41 @@ int process_context_node(xmlNodePtr context_node, free(content); } } + } else if (!strcmp((const char *) context_child_node->name, + config_element_context_app)) { + /* application context */ + xmlNodePtr app_ctx_node; + + context.ctx = LTTNG_EVENT_CONTEXT_APP_CONTEXT; + for (app_ctx_node = xmlFirstElementChild(context_child_node); + app_ctx_node; app_ctx_node = + xmlNextElementSibling(app_ctx_node)) { + xmlChar *content; + char **target = strcmp( + (const char *) app_ctx_node->name, + config_element_context_app_provider_name) == 0 ? + &context.u.app_ctx.provider_name : + &context.u.app_ctx.ctx_name; + + content = xmlNodeGetContent(app_ctx_node); + if (!content) { + ret = -LTTNG_ERR_NOMEM; + goto end; + } + + *target = (char *) content; + } + } else { + /* Unrecognized context type */ + ret = -LTTNG_ERR_LOAD_INVALID_CONFIG; + goto end; } ret = lttng_add_context(handle, &context, NULL, channel_name); + if (context.ctx == LTTNG_EVENT_CONTEXT_APP_CONTEXT) { + free(context.u.app_ctx.provider_name); + free(context.u.app_ctx.ctx_name); + } end: return ret; } diff --git a/src/common/config/session.xsd b/src/common/config/session.xsd index 49b7cd112..550fea0ee 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.8"> @@ -136,6 +136,13 @@ elementFormDefault="qualified" version="2.7"> + + + + + + + @@ -151,6 +158,7 @@ elementFormDefault="qualified" version="2.7"> + @@ -158,6 +166,7 @@ elementFormDefault="qualified" version="2.7"> + -- 2.34.1 From cac5ee8ff005c9e6871cadd0068bf9ea88a34b31 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 9 Feb 2016 15:16:38 -0500 Subject: [PATCH 15/16] Create agent on channel creation MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/channel.c | 40 +++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/src/bin/lttng-sessiond/channel.c b/src/bin/lttng-sessiond/channel.c index 7c95a0d21..8ceb4e893 100644 --- a/src/bin/lttng-sessiond/channel.c +++ b/src/bin/lttng-sessiond/channel.c @@ -31,6 +31,7 @@ #include "ust-ctl.h" #include "utils.h" #include "ust-app.h" +#include "agent.h" /* * Return allocated channel attributes. @@ -272,6 +273,7 @@ int channel_ust_create(struct ltt_ust_session *usess, int ret = LTTNG_OK; struct ltt_ust_channel *uchan = NULL; struct lttng_channel *defattr = NULL; + enum lttng_domain_type domain = LTTNG_DOMAIN_UST; assert(usess); @@ -283,6 +285,18 @@ int channel_ust_create(struct ltt_ust_session *usess, goto error; } attr = defattr; + } else { + /* + * HACK: Set the channel's subdomain (JUL, Log4j, Python, etc.) + * based on the default name. + */ + if (!strcmp(attr->name, DEFAULT_JUL_CHANNEL_NAME)) { + domain = LTTNG_DOMAIN_JUL; + } else if (!strcmp(attr->name, DEFAULT_LOG4J_CHANNEL_NAME)) { + domain = LTTNG_DOMAIN_LOG4J; + } else if (!strcmp(attr->name, DEFAULT_PYTHON_CHANNEL_NAME)) { + domain = LTTNG_DOMAIN_PYTHON; + } } if (usess->snapshot_mode) { @@ -343,24 +357,12 @@ int channel_ust_create(struct ltt_ust_session *usess, } /* Create UST channel */ - uchan = trace_ust_create_channel(attr, LTTNG_DOMAIN_UST); + uchan = trace_ust_create_channel(attr, domain); if (uchan == NULL) { ret = LTTNG_ERR_FATAL; goto error; } - /* - * HACK: Set the channel's subdomain (JUL, Log4j, Python, etc.) - * based on the default name. - */ - if (!strcmp(uchan->name, DEFAULT_JUL_CHANNEL_NAME)) { - uchan->domain = LTTNG_DOMAIN_JUL; - } else if (!strcmp(uchan->name, DEFAULT_LOG4J_CHANNEL_NAME)) { - uchan->domain = LTTNG_DOMAIN_LOG4J; - } else if (!strcmp(uchan->name, DEFAULT_PYTHON_CHANNEL_NAME)) { - uchan->domain = LTTNG_DOMAIN_PYTHON; - } - uchan->enabled = 1; if (trace_ust_is_max_id(usess->used_channel_id)) { ret = LTTNG_ERR_UST_CHAN_FAIL; @@ -405,6 +407,18 @@ int channel_ust_create(struct ltt_ust_session *usess, rcu_read_unlock(); DBG2("Channel %s created successfully", uchan->name); + if (domain != LTTNG_DOMAIN_UST) { + struct agent *agt = trace_ust_find_agent(usess, domain); + + if (!agt) { + agt = agent_create(domain); + if (!agt) { + ret = LTTNG_ERR_NOMEM; + goto error_free_chan; + } + agent_add(agt, usess->agents); + } + } free(defattr); return LTTNG_OK; -- 2.34.1 From be35e7ae07cba3fb5ce34a0e2b9db5597632a50f Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Tue, 9 Feb 2016 15:16:49 -0500 Subject: [PATCH 16/16] Fix: Don't notify agent of non-app context addition MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/bin/lttng-sessiond/context.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/bin/lttng-sessiond/context.c b/src/bin/lttng-sessiond/context.c index 1725c6a10..9a5738799 100644 --- a/src/bin/lttng-sessiond/context.c +++ b/src/bin/lttng-sessiond/context.c @@ -113,7 +113,13 @@ static int add_uctx_to_channel(struct ltt_ust_session *usess, case LTTNG_DOMAIN_JUL: case LTTNG_DOMAIN_LOG4J: { - struct agent *agt = trace_ust_find_agent(usess, domain); + struct agent *agt; + + if (ctx->ctx != LTTNG_EVENT_CONTEXT_APP_CONTEXT) { + /* Other contexts are not needed by the agent. */ + break; + } + agt = trace_ust_find_agent(usess, domain); if (!agt) { agt = agent_create(domain); -- 2.34.1