Mi fix: basic formatting
[lttng-tools.git] / src / common / mi-lttng.c
index 515f16941b52cb881ad2644991b8b592d4eb4766..cd5c082fd316bb867216be8acf40c2e60ee6a387 100644 (file)
 
 #include <include/config.h>
 #include <common/config/config.h>
+#include <lttng/snapshot-internal.h>
 #include "mi-lttng.h"
 
 #include <assert.h>
 
 /* Strings related to command */
 const char * const mi_lttng_element_command = "command";
-const char * const mi_lttng_element_command_name = "name";
-const char * const mi_lttng_element_command_version = "version";
+const char * const mi_lttng_element_command_action = "snapshot_action";
+const char * const mi_lttng_element_command_add_context = "add-context";
+const char * const mi_lttng_element_command_calibrate = "calibrate";
+const char * const mi_lttng_element_command_create = "create";
+const char * const mi_lttng_element_command_destroy = "destroy";
+const char * const mi_lttng_element_command_disable_channel = "disable-channel";
+const char * const mi_lttng_element_command_disable_event = "disable-event";
+const char * const mi_lttng_element_command_enable_channels = "enable-channel";
+const char * const mi_lttng_element_command_enable_event = "enable-event";
 const char * const mi_lttng_element_command_list = "list";
-const char * const mi_lttng_element_command_save = "save";
 const char * const mi_lttng_element_command_load = "load";
+const char * const mi_lttng_element_command_name = "name";
+const char * const mi_lttng_element_command_output = "output";
+const char * const mi_lttng_element_command_save = "save";
+const char * const mi_lttng_element_command_set_session = "set-session";
+const char * const mi_lttng_element_command_snapshot = "snapshot";
+const char * const mi_lttng_element_command_snapshot_add = "add_snapshot";
+const char * const mi_lttng_element_command_snapshot_del = "del_snapshot";
+const char * const mi_lttng_element_command_snapshot_list = "list_snapshot";
+const char * const mi_lttng_element_command_snapshot_record = "record_snapshot";
 const char * const mi_lttng_element_command_start = "start";
 const char * const mi_lttng_element_command_stop = "stop";
-const char * const mi_lttng_element_command_create = "create";
-const char * const mi_lttng_element_command_destroy = "destroy";
-const char * const mi_lttng_element_command_calibrate = "calibrate";
-const char * const mi_lttng_element_command_add_context = "add-context";
-const char * const mi_lttng_element_command_output = "output";
 const char * const mi_lttng_element_command_success = "success";
+const char * const mi_lttng_element_command_version = "version";
 
 /* Strings related to version command */
 const char * const mi_lttng_element_version = "version";
-const char * const mi_lttng_element_version_str = "string";
-const char * const mi_lttng_element_version_web = "url";
-const char * const mi_lttng_element_version_major = "major";
-const char * const mi_lttng_element_version_minor = "minor";
 const char * const mi_lttng_element_version_commit = "commit";
+const char * const mi_lttng_element_version_description = "description";
 const char * const mi_lttng_element_version_license = "license";
+const char * const mi_lttng_element_version_major = "major";
+const char * const mi_lttng_element_version_minor = "minor";
 const char * const mi_lttng_element_version_patch_level = "patchLevel";
-const char * const mi_lttng_element_version_description = "description";
-
-/* Strings related to pid */
-const char * const mi_lttng_element_pids = "pids";
-const char * const mi_lttng_element_pid = "pid";
-const char * const mi_lttng_element_pid_id = "id";
-
-/* Strings related to save command */
-const char * const mi_lttng_element_save = "save";
-
-/* Strings related to load command */
-const char * const mi_lttng_element_load = "load";
+const char * const mi_lttng_element_version_str = "string";
+const char * const mi_lttng_element_version_web = "url";
 
 /* String related to a lttng_event_field */
 const char * const mi_lttng_element_event_field = "event_field";
@@ -73,14 +74,27 @@ const char * const mi_lttng_context_type_perf_thread_counter = "PERF_THREAD_COUN
 /* String related to lttng_event_perf_counter_ctx */
 const char * const mi_lttng_element_perf_counter_context = "perf_counter_context";
 
+/* Strings related to pid */
+const char * const mi_lttng_element_pids = "pids";
+const char * const mi_lttng_element_pid = "pid";
+const char * const mi_lttng_element_pid_id = "id";
+
+/* Strings related to save command */
+const char * const mi_lttng_element_save = "save";
+
+/* Strings related to load command */
+const char * const mi_lttng_element_load = "load";
+
 /* General elements of mi_lttng */
-const char * const mi_lttng_element_type_other = "OTHER";
-const char * const mi_lttng_element_type_integer = "INTEGER";
+const char * const mi_lttng_element_empty = "";
+const char * const mi_lttng_element_id = "id";
+const char * const mi_lttng_element_nowrite = "nowrite";
+const char * const mi_lttng_element_success = "success";
 const char * const mi_lttng_element_type_enum = "ENUM";
 const char * const mi_lttng_element_type_float = "FLOAT";
+const char * const mi_lttng_element_type_integer = "INTEGER";
+const char * const mi_lttng_element_type_other = "OTHER";
 const char * const mi_lttng_element_type_string = "STRING";
-const char * const mi_lttng_element_nowrite = "nowrite";
-const char * const mi_lttng_element_success = "success";
 
 /* String related to loglevel */
 const char * const mi_lttng_loglevel_str_alert = "TRACE_ALERT";
@@ -110,7 +124,13 @@ const char * const mi_lttng_loglevel_type_unknown = "UNKNOWN";
 const char * const mi_lttng_element_calibrate = "calibrate";
 const char * const mi_lttng_element_calibrate_function = "FUNCTION";
 
-const char * const mi_lttng_element_empty = "";
+/* String related to a lttng_snapshot_output */
+const char * const mi_lttng_element_snapshot_ctrl_url = "ctrl_url";
+const char * const mi_lttng_element_snapshot_data_url = "data_url";
+const char * const mi_lttng_element_snapshot_max_size = "max_size";
+const char * const mi_lttng_element_snapshot_n_ptr = "n_ptr";
+const char * const mi_lttng_element_snapshot_session_name = "session_name";
+const char * const mi_lttng_element_snapshots = "snapshots";
 
 const char *mi_lttng_loglevel_string(int value)
 {
@@ -779,28 +799,28 @@ int mi_lttng_event_common_attributes(struct mi_writer *writer,
                goto end;
        }
 
-       /* event name */
+       /* Event name */
        ret = mi_lttng_writer_write_element_string(writer,
                        config_element_name, event->name);
        if (ret) {
                goto end;
        }
 
-       /* event type */
+       /* Event type */
        ret = mi_lttng_writer_write_element_string(writer,
                        config_element_type, mi_lttng_eventtype_string(event->type));
        if (ret) {
                goto end;
        }
 
-       /* is event enabled */
+       /* Is event enabled */
        ret = mi_lttng_writer_write_element_bool(writer,
                        config_element_enabled, event->enabled);
        if (ret) {
                goto end;
        }
 
-       /* event filter enabled? */
+       /* Event filter enabled? */
        ret = mi_lttng_writer_write_element_bool(writer,
                        config_element_filter, event->filter);
 
@@ -814,13 +834,14 @@ int mi_lttng_event_tracepoint_loglevel(struct mi_writer *writer,
 {
        int ret;
 
-       /* event loglevel */
+       /* Event loglevel */
        ret = mi_lttng_writer_write_element_string(writer,
                        config_element_loglevel, mi_lttng_loglevel_string(event->loglevel));
        if (ret) {
                goto end;
        }
 
+       /* Log level type */
        ret = mi_lttng_writer_write_element_string(writer,
                        config_element_loglevel_type,
                        mi_lttng_logleveltype_string(event->loglevel_type));
@@ -907,10 +928,6 @@ int mi_lttng_event(struct mi_writer *writer,
        }
 
        switch (event->type) {
-       case LTTNG_EVENT_ALL:
-               /* We should never have "all" events in list. */
-               assert(0);
-               break;
        case LTTNG_EVENT_TRACEPOINT:
        {
                if (event->loglevel != -1) {
@@ -926,6 +943,8 @@ int mi_lttng_event(struct mi_writer *writer,
        case LTTNG_EVENT_FUNCTION_ENTRY:
                ret = mi_lttng_event_function_entry(writer, event);
                break;
+       case LTTNG_EVENT_ALL:
+               /* Fallthrough */
        default:
                break;
        }
@@ -992,9 +1011,6 @@ int mi_lttng_event_field(struct mi_writer *writer,
        int ret;
 
        if (!field->field_name[0]) {
-               /* To Review: not sure if legal david ?
-                * how should this be handle ?
-                */
                ret = 0;
                goto end;
        }
@@ -1149,3 +1165,238 @@ int mi_lttng_perf_counter_context(struct mi_writer *writer,
 end:
        return ret;
 }
+
+LTTNG_HIDDEN
+int mi_lttng_snapshot_output_session_name(struct mi_writer *writer,
+               const char *session_name)
+{
+       int ret;
+
+       /* Open session element */
+       ret = mi_lttng_writer_open_element(writer, config_element_session);
+       if (ret) {
+               goto end;
+       }
+
+       /* Snapshot output list for current session name */
+       ret = mi_lttng_writer_write_element_string(writer, config_element_name,
+                       session_name);
+
+       /* Open element snapshots (sequence one snapshot) */
+       ret = mi_lttng_writer_open_element(writer, mi_lttng_element_snapshots);
+       if (ret) {
+               goto end;
+       }
+
+end:
+       return ret;
+}
+
+LTTNG_HIDDEN
+int mi_lttng_snapshot_list_output(struct mi_writer *writer,
+               struct lttng_snapshot_output *output)
+{
+       int ret;
+
+       /* Open element snapshot output */
+       ret = mi_lttng_writer_open_element(writer,
+                       mi_lttng_element_command_snapshot);
+       if (ret) {
+               goto end;
+       }
+
+       /* ID of the snapshot output */
+       ret = mi_lttng_writer_write_element_unsigned_int(writer,
+                       mi_lttng_element_id, output->id);
+       if (ret) {
+               goto end;
+       }
+
+       /* Name of the output */
+       ret = mi_lttng_writer_write_element_string(writer, config_element_name,
+                       output->name);
+       if (ret) {
+               goto end;
+       }
+
+       /* Destination of the output (ctrl_url)*/
+       ret = mi_lttng_writer_write_element_string(writer,
+                       mi_lttng_element_snapshot_ctrl_url, output->ctrl_url);
+       if (ret) {
+               goto end;
+       }
+
+       /* Destination of the output (data_url) */
+       ret = mi_lttng_writer_write_element_string(writer,
+                       mi_lttng_element_snapshot_data_url, output->data_url);
+       if (ret) {
+               goto end;
+       }
+
+       /* total size of all stream combined */
+       ret = mi_lttng_writer_write_element_unsigned_int(writer,
+                       mi_lttng_element_snapshot_max_size, output->max_size);
+       if (ret) {
+               goto end;
+       }
+
+       /* Close snapshot output element */
+       ret = mi_lttng_writer_close_element(writer);
+
+end:
+       return ret;
+}
+
+LTTNG_HIDDEN
+int mi_lttng_snapshot_del_output(struct mi_writer *writer, int id,
+               const char *name, const char *current_session_name)
+{
+       int ret;
+
+       /* Open element del_snapshot */
+       ret = mi_lttng_writer_open_element(writer,
+                       mi_lttng_element_command_snapshot);
+       if (ret) {
+               goto end;
+       }
+
+
+       if (id != UINT32_MAX) {
+               /* "Snapshot output "id" successfully deleted
+                * for "current_session_name"
+                * ID of the snapshot output
+                */
+               ret = mi_lttng_writer_write_element_unsigned_int(writer,
+                               mi_lttng_element_id, id);
+               if (ret) {
+                       goto end;
+               }
+       } else {
+               /* "Snapshot output "name" successfully deleted
+                * for session "current_session_name"
+                * Name of the output
+                */
+               ret = mi_lttng_writer_write_element_string(writer, config_element_name,
+                               name);
+               if (ret) {
+                       goto end;
+               }
+       }
+
+       /* Snapshot was deleted for session "current_session_name"*/
+       ret = mi_lttng_writer_write_element_string(writer,
+                       mi_lttng_element_snapshot_session_name,
+                       current_session_name);
+       if (ret) {
+               goto end;
+       }
+
+       /* Close snapshot element */
+       ret = mi_lttng_writer_close_element(writer);
+
+end:
+       return ret;
+}
+
+LTTNG_HIDDEN
+int mi_lttng_snapshot_add_output(struct mi_writer *writer,
+               const char *current_session_name, const char *n_ptr,
+               struct lttng_snapshot_output *output)
+{
+       int ret;
+
+       /* Open element snapshot */
+       ret = mi_lttng_writer_open_element(writer,
+                       mi_lttng_element_command_snapshot);
+       if (ret) {
+               goto end;
+       }
+
+       /* Snapshot output id */
+       ret = mi_lttng_writer_write_element_unsigned_int(writer,
+                       mi_lttng_element_id, output->id);
+       if (ret) {
+               goto end;
+       }
+
+       /* Snapshot output names */
+       ret = mi_lttng_writer_write_element_string(writer,
+                       config_element_name, n_ptr);
+       if (ret) {
+               goto end;
+       }
+
+       /* Destination of the output (ctrl_url)*/
+       ret = mi_lttng_writer_write_element_string(writer,
+                       mi_lttng_element_snapshot_ctrl_url, output->ctrl_url);
+       if (ret) {
+               goto end;
+       }
+
+       /* Snapshot added for session "current_session_name"*/
+       ret = mi_lttng_writer_write_element_string(writer,
+                       mi_lttng_element_snapshot_session_name, current_session_name);
+       if (ret) {
+               goto end;
+       }
+
+       /* total size of all stream combined */
+       ret = mi_lttng_writer_write_element_unsigned_int(writer,
+                       mi_lttng_element_snapshot_max_size, output->max_size);
+       if (ret) {
+               goto end;
+       }
+
+       /* Close snapshot element */
+       ret = mi_lttng_writer_close_element(writer);
+
+end:
+       return ret;
+}
+
+LTTNG_HIDDEN
+int mi_lttng_snapshot_record(struct mi_writer *writer,
+               const char *current_session_name, const char *url,
+               const char *cmdline_ctrl_url, const char *cmdline_data_url)
+{
+       int ret;
+
+       /* Open element snapshot */
+       ret = mi_lttng_writer_open_element(writer,
+                       mi_lttng_element_command_snapshot);
+       if (ret) {
+               goto end;
+       }
+
+       /*
+        * If a valid an URL was given, serialize it,
+        * else take the command line data and ctrl urls*/
+       if (url) {
+               /* Destination of the output (ctrl_url)*/
+               ret = mi_lttng_writer_write_element_string(writer,
+                               mi_lttng_element_snapshot_ctrl_url, url);
+               if (ret) {
+                       goto end;
+               }
+       } else if (cmdline_ctrl_url) {
+               /* Destination of the output (ctrl_url)*/
+               ret = mi_lttng_writer_write_element_string(writer,
+                               mi_lttng_element_snapshot_ctrl_url, cmdline_ctrl_url);
+               if (ret) {
+                       goto end;
+               }
+
+               /* Destination of the output (data_url) */
+               ret = mi_lttng_writer_write_element_string(writer,
+                               mi_lttng_element_snapshot_data_url, cmdline_data_url);
+               if (ret) {
+                       goto end;
+               }
+       }
+
+       /* Close record_snapshot element */
+       ret = mi_lttng_writer_close_element(writer);
+
+end:
+       return ret;
+}
This page took 0.02988 seconds and 5 git commands to generate.