X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fconfig%2Fsession-config.c;h=804b77818d269cd5af82e5d1807d2f5545ccb696;hb=91744e14248d52e0a696df7d94024dce79fdd665;hp=ed836f17e9d70e3d9cc5e0d3ea9eaf8d7e386b55;hpb=9a2df626a4991d5560cbc4fafd98d9b1120e89ed;p=lttng-tools.git diff --git a/src/common/config/session-config.c b/src/common/config/session-config.c index ed836f17e..804b77818 100644 --- a/src/common/config/session-config.c +++ b/src/common/config/session-config.c @@ -133,9 +133,11 @@ const char * const config_element_trackers = "trackers"; const char * const config_element_targets = "targets"; const char * const config_element_target_pid = "pid_target"; -LTTNG_HIDDEN const char * const config_element_rotation_timer_interval = "rotation_schedule_timer_period"; -LTTNG_HIDDEN const char * const config_element_rotation_size = "rotation_schedule_size"; -LTTNG_HIDDEN const char * const config_element_rotation_schedule = "rotation_schedule"; +LTTNG_HIDDEN const char * const config_element_rotation_schedules = "rotation_schedules"; +LTTNG_HIDDEN const char * const config_element_rotation_schedule_periodic = "periodic"; +LTTNG_HIDDEN const char * const config_element_rotation_schedule_periodic_time_us = "time_us"; +LTTNG_HIDDEN const char * const config_element_rotation_schedule_size_threshold = "size_threshold"; +LTTNG_HIDDEN const char * const config_element_rotation_schedule_size_threshold_bytes = "bytes"; const char * const config_domain_type_kernel = "KERNEL"; const char * const config_domain_type_ust = "UST"; @@ -185,6 +187,8 @@ LTTNG_HIDDEN const char * const config_event_context_interruptible = "INTERRUPTI LTTNG_HIDDEN const char * const config_event_context_preemptible = "PREEMPTIBLE"; LTTNG_HIDDEN const char * const config_event_context_need_reschedule = "NEED_RESCHEDULE"; LTTNG_HIDDEN const char * const config_event_context_migratable = "MIGRATABLE"; +LTTNG_HIDDEN const char * const config_event_context_callstack_user= "CALLSTACK_USER"; +LTTNG_HIDDEN const char * const config_event_context_callstack_kernel = "CALLSTACK_KERNEL"; /* Deprecated symbols */ const char * const config_element_perf; @@ -1018,6 +1022,12 @@ int get_context_type(xmlChar *context_type) } else if (!strcmp((char *) context_type, config_event_context_migratable)) { ret = LTTNG_EVENT_CONTEXT_MIGRATABLE; + } else if (!strcmp((char *) context_type, + config_event_context_callstack_user)) { + ret = LTTNG_EVENT_CONTEXT_CALLSTACK_USER; + } else if (!strcmp((char *) context_type, + config_event_context_callstack_kernel)) { + ret = LTTNG_EVENT_CONTEXT_CALLSTACK_KERNEL; } else { goto error; } @@ -1529,7 +1539,7 @@ int process_event_node(xmlNodePtr event_node, struct lttng_handle *handle, { int ret = 0, i; xmlNodePtr node; - struct lttng_event event; + struct lttng_event *event; char **exclusions = NULL; unsigned long exclusion_count = 0; char *filter_expression = NULL; @@ -1538,23 +1548,27 @@ int process_event_node(xmlNodePtr event_node, struct lttng_handle *handle, assert(handle); assert(channel_name); - memset(&event, 0, sizeof(event)); + event = lttng_event_create(); + if (!event) { + ret = -LTTNG_ERR_NOMEM; + goto end; + } /* Initialize default log level which varies by domain */ switch (handle->domain.type) { case LTTNG_DOMAIN_JUL: - event.loglevel = LTTNG_LOGLEVEL_JUL_ALL; + event->loglevel = LTTNG_LOGLEVEL_JUL_ALL; break; case LTTNG_DOMAIN_LOG4J: - event.loglevel = LTTNG_LOGLEVEL_LOG4J_ALL; + event->loglevel = LTTNG_LOGLEVEL_LOG4J_ALL; break; case LTTNG_DOMAIN_PYTHON: - event.loglevel = LTTNG_LOGLEVEL_PYTHON_DEBUG; + event->loglevel = LTTNG_LOGLEVEL_PYTHON_DEBUG; break; case LTTNG_DOMAIN_UST: case LTTNG_DOMAIN_KERNEL: - event.loglevel = LTTNG_LOGLEVEL_DEBUG; + event->loglevel = LTTNG_LOGLEVEL_DEBUG; break; default: assert(0); @@ -1572,7 +1586,7 @@ int process_event_node(xmlNodePtr event_node, struct lttng_handle *handle, goto end; } - ret = lttng_strncpy(event.name, + ret = lttng_strncpy(event->name, (const char *) content, LTTNG_SYMBOL_NAME_LEN); if (ret == -1) { @@ -1595,7 +1609,7 @@ int process_event_node(xmlNodePtr event_node, struct lttng_handle *handle, goto end; } - ret = parse_bool(content, &event.enabled); + ret = parse_bool(content, &event->enabled); free(content); if (ret) { ret = -LTTNG_ERR_LOAD_INVALID_CONFIG; @@ -1618,7 +1632,7 @@ int process_event_node(xmlNodePtr event_node, struct lttng_handle *handle, goto end; } - event.type = ret; + event->type = ret; } else if (!strcmp((const char *) node->name, config_element_loglevel_type)) { xmlChar *content = xmlNodeGetContent(node); @@ -1636,7 +1650,7 @@ int process_event_node(xmlNodePtr event_node, struct lttng_handle *handle, goto end; } - event.loglevel_type = ret; + event->loglevel_type = ret; } else if (!strcmp((const char *) node->name, config_element_loglevel)) { xmlChar *content; @@ -1662,7 +1676,7 @@ int process_event_node(xmlNodePtr event_node, struct lttng_handle *handle, goto end; } - event.loglevel = loglevel; + event->loglevel = loglevel; } else if (!strcmp((const char *) node->name, config_element_filter)) { xmlChar *content = @@ -1727,7 +1741,7 @@ int process_event_node(xmlNodePtr event_node, struct lttng_handle *handle, exclusion_index++; } - event.exclusion = 1; + event->exclusion = 1; } else if (!strcmp((const char *) node->name, config_element_attributes)) { xmlNodePtr attribute_node = xmlFirstElementChild(node); @@ -1749,7 +1763,7 @@ int process_event_node(xmlNodePtr event_node, struct lttng_handle *handle, probe_attribute_node)) { ret = process_probe_attribute_node(probe_attribute_node, - &event.attr.probe); + &event->attr.probe); if (ret) { goto end; } @@ -1775,7 +1789,7 @@ int process_event_node(xmlNodePtr event_node, struct lttng_handle *handle, } ret = lttng_strncpy( - event.attr.ftrace.symbol_name, + event->attr.ftrace.symbol_name, (char *) content, sym_len); if (ret == -1) { ret = -LTTNG_ERR_LOAD_INVALID_CONFIG; @@ -1787,11 +1801,11 @@ int process_event_node(xmlNodePtr event_node, struct lttng_handle *handle, } } - if ((event.enabled && phase == ENABLE) || phase == CREATION) { - ret = lttng_enable_event_with_exclusions(handle, &event, channel_name, + if ((event->enabled && phase == ENABLE) || phase == CREATION) { + ret = lttng_enable_event_with_exclusions(handle, event, channel_name, filter_expression, exclusion_count, exclusions); if (ret < 0) { - WARN("Enabling event (name:%s) on load failed.", event.name); + WARN("Enabling event (name:%s) on load failed.", event->name); ret = -LTTNG_ERR_LOAD_INVALID_CONFIG; goto end; } @@ -2546,6 +2560,153 @@ end: return ret; } +static +int add_periodic_rotation(const char *name, uint64_t time_us) +{ + int ret; + enum lttng_rotation_status status; + struct lttng_rotation_schedule *periodic = + lttng_rotation_schedule_periodic_create(); + + if (!periodic) { + ret = -LTTNG_ERR_NOMEM; + goto error; + } + + status = lttng_rotation_schedule_periodic_set_period(periodic, + time_us); + if (status != LTTNG_ROTATION_STATUS_OK) { + ret = -LTTNG_ERR_INVALID; + goto error; + } + + status = lttng_session_add_rotation_schedule(name, periodic); + switch (status) { + case LTTNG_ROTATION_STATUS_OK: + ret = 0; + break; + case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET: + case LTTNG_ROTATION_STATUS_INVALID: + ret = -LTTNG_ERR_LOAD_INVALID_CONFIG; + break; + default: + ret = -LTTNG_ERR_UNK; + break; + } +error: + lttng_rotation_schedule_destroy(periodic); + return ret; +} + +static +int add_size_rotation(const char *name, uint64_t size_bytes) +{ + int ret; + enum lttng_rotation_status status; + struct lttng_rotation_schedule *size = + lttng_rotation_schedule_size_threshold_create(); + + if (!size) { + ret = -LTTNG_ERR_NOMEM; + goto error; + } + + status = lttng_rotation_schedule_size_threshold_set_threshold(size, + size_bytes); + if (status != LTTNG_ROTATION_STATUS_OK) { + ret = -LTTNG_ERR_INVALID; + goto error; + } + + status = lttng_session_add_rotation_schedule(name, size); + switch (status) { + case LTTNG_ROTATION_STATUS_OK: + ret = 0; + break; + case LTTNG_ROTATION_STATUS_SCHEDULE_ALREADY_SET: + case LTTNG_ROTATION_STATUS_INVALID: + ret = -LTTNG_ERR_LOAD_INVALID_CONFIG; + break; + default: + ret = -LTTNG_ERR_UNK; + break; + } +error: + lttng_rotation_schedule_destroy(size); + return ret; +} + +static +int process_session_rotation_schedules_node( + xmlNodePtr schedules_node, + uint64_t *rotation_timer_interval, + uint64_t *rotation_size) +{ + int ret = 0; + xmlNodePtr child; + + for (child = xmlFirstElementChild(schedules_node); + child; + child = xmlNextElementSibling(child)) { + if (!strcmp((const char *) child->name, + config_element_rotation_schedule_periodic)) { + xmlChar *content; + xmlNodePtr time_us_node; + + /* periodic rotation schedule */ + time_us_node = xmlFirstElementChild(child); + if (!time_us_node || + strcmp((const char *) time_us_node->name, + config_element_rotation_schedule_periodic_time_us)) { + ret = -LTTNG_ERR_LOAD_INVALID_CONFIG; + goto end; + } + + /* time_us child */ + content = xmlNodeGetContent(time_us_node); + if (!content) { + ret = -LTTNG_ERR_NOMEM; + goto end; + } + ret = parse_uint(content, rotation_timer_interval); + free(content); + if (ret) { + ret = -LTTNG_ERR_LOAD_INVALID_CONFIG; + goto end; + } + } else if (!strcmp((const char *) child->name, + config_element_rotation_schedule_size_threshold)) { + xmlChar *content; + xmlNodePtr bytes_node; + + /* size_threshold rotation schedule */ + bytes_node = xmlFirstElementChild(child); + if (!bytes_node || + strcmp((const char *) bytes_node->name, + config_element_rotation_schedule_size_threshold_bytes)) { + ret = -LTTNG_ERR_LOAD_INVALID_CONFIG; + goto end; + } + + /* bytes child */ + content = xmlNodeGetContent(bytes_node); + if (!content) { + ret = -LTTNG_ERR_NOMEM; + goto end; + } + ret = parse_uint(content, rotation_size); + free(content); + if (ret) { + ret = -LTTNG_ERR_LOAD_INVALID_CONFIG; + goto end; + } + } + } + +end: + return ret; +} + static int process_session_node(xmlNodePtr session_node, const char *session_name, int overwrite, @@ -2651,40 +2812,17 @@ int process_session_node(xmlNodePtr session_node, const char *session_name, ret = -LTTNG_ERR_LOAD_INVALID_CONFIG; goto error; } - } - if (!strcmp((const char *) attributes_child->name, - config_element_rotation_timer_interval)) { - /* rotation_timer_interval */ - xmlChar *timer_interval_content = - xmlNodeGetContent(attributes_child); - if (!timer_interval_content) { - ret = -LTTNG_ERR_NOMEM; - goto error; - } - - ret = parse_uint(timer_interval_content, &rotation_timer_interval); - free(timer_interval_content); + } else if (!strcmp((const char *) attributes_child->name, + config_element_rotation_schedules)) { + ret = process_session_rotation_schedules_node( + attributes_child, + &rotation_timer_interval, + &rotation_size); if (ret) { ret = -LTTNG_ERR_LOAD_INVALID_CONFIG; goto error; } - } - if (!strcmp((const char *) attributes_child->name, - config_element_rotation_size)) { - /* rotation_size */ - xmlChar *rotation_size_content = - xmlNodeGetContent(attributes_child); - if (!rotation_size_content) { - ret = -LTTNG_ERR_NOMEM; - goto error; - } - ret = parse_uint(rotation_size_content, &rotation_size); - free(rotation_size_content); - if (ret) { - ret = -LTTNG_ERR_LOAD_INVALID_CONFIG; - goto error; - } } } } @@ -2822,23 +2960,17 @@ domain_init_error: } } - if (rotation_timer_interval || rotation_size) { - struct lttng_rotation_schedule_attr *rotation_attr = lttng_rotation_schedule_attr_create(); - - if (!rotation_attr) { - goto error; - } - ret = lttng_rotation_schedule_attr_set_session_name(rotation_attr, (const char *) name); - if (ret) { - lttng_rotation_schedule_attr_destroy(rotation_attr); + if (rotation_timer_interval) { + ret = add_periodic_rotation((const char *) name, + rotation_timer_interval); + if (ret < 0) { goto error; } - lttng_rotation_schedule_attr_set_timer_period(rotation_attr, - rotation_timer_interval); - lttng_rotation_schedule_attr_set_size(rotation_attr, rotation_size); - ret = lttng_rotation_set_schedule(rotation_attr); - lttng_rotation_schedule_attr_destroy(rotation_attr); - if (ret) { + } + if (rotation_size) { + ret = add_size_rotation((const char *) name, + rotation_size); + if (ret < 0) { goto error; } } @@ -3032,7 +3164,7 @@ int load_session_from_path(const char *path, const char *session_name, errno = 0; result = readdir(directory); - /* Reached end of dir stream or error out */ + /* Reached end of dir stream or error out. */ if (!result) { if (errno) { PERROR("Failed to enumerate the contents of path \"%s\" while loading session, readdir returned", path);