rotation-api: introduce rotation schedule descriptors
[lttng-tools.git] / src / common / config / session-config.c
index ed836f17e9d70e3d9cc5e0d3ea9eaf8d7e386b55..ffe7b14ed59cb0cca2dd23fe4075e5bc48a637ae 100644 (file)
@@ -185,6 +185,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 +1020,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;
        }
@@ -2546,6 +2554,82 @@ 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 = LTTNG_OK;
+               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 = LTTNG_OK;
+               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_node(xmlNodePtr session_node, const char *session_name,
                int overwrite,
@@ -2822,23 +2906,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 +3110,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);
This page took 0.026287 seconds and 5 git commands to generate.