Mi: track/untrack/listing
authorJonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Tue, 11 Aug 2015 19:14:11 +0000 (15:14 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 11 Aug 2015 19:15:01 +0000 (15:15 -0400)
Signed-off-by: Jonathan Rajotte <jonathan.rajotte-julien@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng/commands/list.c
src/bin/lttng/commands/track-untrack.c
src/common/config/config-session-abi.h
src/common/config/config.c
src/common/mi-lttng.c
src/common/mi-lttng.h
src/lib/lttng-ctl/lttng-ctl.c

index 15f8a728d9e61f88d44e3030f73290f5bc35ca5b..f43ee167ab535fd190fbedc75b60db7e8ebc5381 100644 (file)
@@ -340,8 +340,8 @@ static int mi_list_agent_ust_events(struct lttng_event *events, int count,
                goto end;
        }
 
-       /* Open pids element */
-       ret = mi_lttng_pids_open(writer);
+       /* Open processes element */
+       ret = mi_lttng_processes_open(writer);
        if (ret) {
                goto end;
        }
@@ -366,7 +366,7 @@ static int mi_list_agent_ust_events(struct lttng_event *events, int count,
 
                        if (!pid_element_open) {
                                /* Open and write a pid element */
-                               ret = mi_lttng_pid(writer, cur_pid, cmdline, 1);
+                               ret = mi_lttng_process(writer, cur_pid, cmdline, 1);
                                if (ret) {
                                        goto error;
                                }
@@ -389,7 +389,7 @@ static int mi_list_agent_ust_events(struct lttng_event *events, int count,
                }
        }
 
-       /* Close pids */
+       /* Close processes */
        ret = mi_lttng_writer_close_element(writer);
        if (ret) {
                goto end;
@@ -577,8 +577,8 @@ static int mi_list_ust_event_fields(struct lttng_event_field *fields, int count,
                goto end;
        }
 
-       /* Open pids element */
-       ret = mi_lttng_pids_open(writer);
+       /* Open processes element */
+       ret = mi_lttng_processes_open(writer);
        if (ret) {
                goto end;
        }
@@ -606,8 +606,8 @@ static int mi_list_ust_event_fields(struct lttng_event_field *fields, int count,
                        cur_pid = fields[i].event.pid;
                        cmdline = get_cmdline_by_pid(cur_pid);
                        if (!pid_element_open) {
-                               /* Open and write a pid element */
-                               ret = mi_lttng_pid(writer, cur_pid, cmdline, 1);
+                               /* Open and write a process element */
+                               ret = mi_lttng_process(writer, cur_pid, cmdline, 1);
                                if (ret) {
                                        goto error;
                                }
@@ -661,7 +661,7 @@ static int mi_list_ust_event_fields(struct lttng_event_field *fields, int count,
                }
        }
 
-       /* Close pids, domain, domains */
+       /* Close processes, domain, domains */
        ret = mi_lttng_close_multi_element(writer, 3);
 end:
        return ret;
@@ -1243,7 +1243,8 @@ error_channels:
  */
 static int list_tracker_pids(void)
 {
-       int enabled, ret;
+       int ret = 0;
+       int enabled;
        int *pids = NULL;
        size_t nr_pids;
 
@@ -1256,16 +1257,76 @@ static int list_tracker_pids(void)
                int i;
                _MSG("PID tracker: [");
 
+               /* Mi tracker_pid element*/
+               if (writer) {
+                       /* Open tracker_pid and targets elements */
+                       ret = mi_lttng_pid_tracker_open(writer);
+                       if (ret) {
+                               goto end;
+                       }
+               }
+
                for (i = 0; i < nr_pids; i++) {
                        if (i) {
                                _MSG(",");
                        }
                        _MSG(" %d", pids[i]);
+
+                       /* Mi */
+                       if (writer) {
+                               ret = mi_lttng_pid_target(writer, pids[i], 0);
+                               if (ret) {
+                                       goto end;
+                               }
+                       }
                }
                _MSG(" ]\n\n");
+
+               /* Mi close tracker_pid and targets */
+               if (writer) {
+                       ret = mi_lttng_close_multi_element(writer,2);
+                       if (ret) {
+                               goto end;
+                       }
+               }
        }
+end:
        free(pids);
-       return 0;
+       return ret;
+
+}
+
+/*
+ * List all tracker of a domain
+ */
+static int list_trackers(void)
+{
+       int ret;
+
+       /* Trackers listing */
+       if (lttng_opt_mi) {
+               ret = mi_lttng_trackers_open(writer);
+               if (ret) {
+                       goto end;
+               }
+       }
+
+       /* pid tracker */
+       ret = list_tracker_pids();
+       if (ret) {
+               goto end;
+       }
+
+       if (lttng_opt_mi) {
+               /* Close trackers element */
+               ret = mi_lttng_writer_close_element(writer);
+               if (ret) {
+                       goto end;
+               }
+       }
+
+end:
+       return ret;
 }
 
 /*
@@ -1692,11 +1753,14 @@ int cmd_list(int argc, const char **argv)
 
                        }
 
-                       ret = list_tracker_pids();
+
+                       /* Trackers */
+                       ret = list_trackers();
                        if (ret) {
                                goto end;
                        }
 
+                       /* Channels */
                        ret = list_channels(opt_channel);
                        if (ret) {
                                goto end;
@@ -1787,7 +1851,7 @@ int cmd_list(int argc, const char **argv)
                                switch (domains[i].type) {
                                case LTTNG_DOMAIN_KERNEL:
                                case LTTNG_DOMAIN_UST:
-                                       ret = list_tracker_pids();
+                                       ret = list_trackers();
                                        if (ret) {
                                                goto end;
                                        }
index 639e18481cf9571a21fce26b8bf00319ae77296c..e9a6677b000579f8a3ce14aa3c9096d2d148ad52 100644 (file)
@@ -202,7 +202,7 @@ int track_untrack_pid(enum cmd_type cmd_type, const char *cmd_str,
                const char *session_name, const char *pid_string,
                int all, struct mi_writer *writer)
 {
-       int ret, retval = CMD_SUCCESS, i;
+       int ret, retval = CMD_SUCCESS, success = 1 , i;
        int *pid_list = NULL;
        int nr_pids;
        struct lttng_domain dom;
@@ -248,26 +248,49 @@ int track_untrack_pid(enum cmd_type cmd_type, const char *cmd_str,
        }
 
        if (writer) {
-               /* Open pids element */
-               ret = mi_lttng_writer_open_element(writer, config_element_pids);
+               /* Open process element */
+               ret = mi_lttng_targets_open(writer);
                if (ret) {
                        retval = CMD_ERROR;
                        goto end;
                }
        }
 
-       /* TODO: MI */
        for (i = 0; i < nr_pids; i++) {
                DBG("%s PID %d", cmd_str, pid_list[i]);
                ret = lib_func(handle, pid_list[i]);
                if (ret) {
+                       success = 0;
                        retval = CMD_ERROR;
-                       goto end;
+               } else {
+                       success = 1;
+               }
+
+               /* Mi */
+               if (writer) {
+                       ret = mi_lttng_pid_target(writer, pid_list[i], 1);
+                       if (ret) {
+                               retval = CMD_ERROR;
+                               goto end;
+                       }
+
+                       ret = mi_lttng_writer_write_element_bool(writer,
+                                       mi_lttng_element_success, success);
+                       if (ret) {
+                               retval = CMD_ERROR;
+                               goto end;
+                       }
+
+                       ret = mi_lttng_writer_close_element(writer);
+                       if (ret) {
+                               retval = CMD_ERROR;
+                               goto end;
+                       }
                }
        }
 
        if (writer) {
-               /* Close pids element */
+               /* Close targets element */
                ret = mi_lttng_writer_close_element(writer);
                if (ret) {
                        retval = CMD_ERROR;
@@ -275,7 +298,6 @@ int track_untrack_pid(enum cmd_type cmd_type, const char *cmd_str,
                }
        }
 
-       /* SUCCESS */
 end:
        if (handle) {
                lttng_destroy_handle(handle);
index c578af7e9183e565a47c03cbfde429cbc429b6a1..b2e939718f47986d03833507f8e384b585d5b318 100644 (file)
@@ -68,6 +68,8 @@ extern const char * const config_element_max_size;
 extern const char * const config_element_pid;
 extern const char * const config_element_pids;
 extern const char * const config_element_shared_memory_path;
+extern const char * const config_element_pid_tracker;
+extern const char * const config_element_trackers;
 
 extern const char * const config_domain_type_kernel;
 extern const char * const config_domain_type_ust;
index 8608faf980be0b8d988ea761051eb17c28ab2828..783e784b2481b4e6ed04e5b247678c0649abc4ba 100644 (file)
@@ -118,6 +118,8 @@ const char * const config_element_max_size = "max_size";
 const char * const config_element_pid = "pid";
 const char * const config_element_pids = "pids";
 const char * const config_element_shared_memory_path = "shared_memory_path";
+const char * const config_element_pid_tracker = "pid_tracker";
+const char * const config_element_trackers = "trackers";
 
 const char * const config_domain_type_kernel = "KERNEL";
 const char * const config_domain_type_ust = "UST";
index 44ff56f1e4ccf16aee5d097b39faa4d233d0f04c..f2d223f86d95878693996e8fadc48a2b2b320515 100644 (file)
@@ -78,8 +78,8 @@ const char * const mi_lttng_context_type_perf_thread_counter = "PERF_THREAD_COUN
 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_processes = "processes";
+const char * const mi_lttng_element_process = "process";
 const char * const mi_lttng_element_pid_id = "id";
 
 /* Strings related to save command */
@@ -164,6 +164,12 @@ 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";
 
+/* String related to track/untrack command */
+const char * const mi_lttng_element_track_untrack_targets = "targets";
+const char * const mi_lttng_element_track_untrack_pid_target = "pid_target";
+const char * const mi_lttng_element_track_untrack_all_wildcard = "*";
+
+
 /* This is a merge of jul loglevel and regular loglevel
  * Those should never overlap by definition
  * (see struct lttng_event loglevel)
@@ -1119,41 +1125,117 @@ end:
        return ret;
 }
 
+LTTNG_HIDDEN
+int mi_lttng_trackers_open(struct mi_writer *writer)
+{
+       return mi_lttng_writer_open_element(writer, config_element_trackers);
+}
+
+LTTNG_HIDDEN
+int mi_lttng_pid_tracker_open(struct mi_writer *writer)
+{
+       int ret;
+
+       /* Open element pid_tracker */
+       ret = mi_lttng_writer_open_element(writer, config_element_pid_tracker);
+       if (ret) {
+               goto end;
+       }
+
+       /* Open targets element */
+       ret = mi_lttng_targets_open(writer);
+end:
+       return ret;
+}
+
 LTTNG_HIDDEN
 int mi_lttng_pids_open(struct mi_writer *writer)
 {
-       return mi_lttng_writer_open_element(writer, mi_lttng_element_pids);
+       return mi_lttng_writer_open_element(writer, config_element_pids);
+}
+
+LTTNG_HIDDEN
+int mi_lttng_processes_open(struct mi_writer *writer)
+{
+       return mi_lttng_writer_open_element(writer, mi_lttng_element_processes);
 }
 
 LTTNG_HIDDEN
-int mi_lttng_pid(struct mi_writer *writer, pid_t pid , const char *cmdline,
+int mi_lttng_process(struct mi_writer *writer, pid_t pid , const char *name,
                int is_open)
 {
        int ret;
 
-       /* Open element pid */
-       ret = mi_lttng_writer_open_element(writer, mi_lttng_element_pid);
+       /* Open element process */
+       ret = mi_lttng_writer_open_element(writer, mi_lttng_element_process);
        if (ret) {
                goto end;
        }
 
        /* Writing pid number */
        ret = mi_lttng_writer_write_element_signed_int(writer,
-                       mi_lttng_element_pid_id, (int)pid);
+                       config_element_pid, (int)pid);
        if (ret) {
                goto end;
        }
 
        /* Writing name of the process */
-       ret = mi_lttng_writer_write_element_string(writer, config_element_name,
-                       cmdline);
+       if (name) {
+               ret = mi_lttng_writer_write_element_string(writer, config_element_name,
+                               name);
+               if (ret) {
+                       goto end;
+               }
+       }
+
+       if (!is_open) {
+               /* Closing Pid */
+               ret = mi_lttng_writer_close_element(writer);
+       }
+
+end:
+       return ret;
+}
+
+LTTNG_HIDDEN
+int mi_lttng_targets_open(struct mi_writer *writer)
+{
+       return mi_lttng_writer_open_element(writer,
+                       mi_lttng_element_track_untrack_targets);
+}
+
+LTTNG_HIDDEN
+int mi_lttng_pid_target(struct mi_writer *writer, pid_t pid, int is_open)
+{
+       int ret;
+
+       ret = mi_lttng_writer_open_element(writer,
+                       mi_lttng_element_track_untrack_pid_target);
+       if (ret) {
+               goto end;
+       }
+
+       /* Writing pid number
+        * Special case for element all on track untrack command
+        * All pid is represented as wildcard *
+        */
+       if ((int) pid == -1) {
+               ret = mi_lttng_writer_write_element_string(writer,
+                               config_element_pid,
+                               mi_lttng_element_track_untrack_all_wildcard);
+       } else {
+               ret = mi_lttng_writer_write_element_signed_int(writer,
+                               config_element_pid, (int) pid);
+       }
        if (ret) {
                goto end;
        }
 
        if (!is_open) {
-               /* Closing Pid */
                ret = mi_lttng_writer_close_element(writer);
+               if (ret) {
+                       goto end;
+               }
        }
 
 end:
@@ -1241,8 +1323,6 @@ end:
        return ret;
 }
 
-/* TODO: mi tracker */
-
 LTTNG_HIDDEN
 int mi_lttng_context(struct mi_writer *writer,
                struct lttng_event_context *context, int is_open)
index deab4e41ca786326f6437cc1761c3d6fbff3b29d..23b7810c4680de3b50d694d5b5ae7afa43f5ba0b 100644 (file)
@@ -101,8 +101,8 @@ extern const char * const mi_lttng_context_type_perf_thread_counter;
 extern const char * const mi_lttng_element_perf_counter_context;
 
 /* Strings related to pid */
-extern const char * const mi_lttng_element_pids;
-extern const char * const mi_lttng_element_pid;
+extern const char * const mi_lttng_element_processes;
+extern const char * const mi_lttng_element_process;
 extern const char * const mi_lttng_element_pid_id;
 
 /* Strings related to save command */
@@ -195,6 +195,11 @@ const char *mi_lttng_domaintype_string(enum lttng_domain_type value);
 const char *mi_lttng_buffertype_string(enum lttng_buffer_type value);
 const char *mi_lttng_calibratetype_string(enum lttng_calibrate_type val);
 
+/* String related to track/untrack command */
+const char * const mi_lttng_element_track_untrack_targets;
+const char * const mi_lttng_element_track_untrack_pid_target;
+const char * const mi_lttng_element_track_untrack_all_wildcard;
+
 /*
  * Create an instance of a machine interface writer.
  *
@@ -555,6 +560,28 @@ int mi_lttng_event_field(struct mi_writer *writer,
  */
 int mi_lttng_event_fields_open(struct mi_writer *writer);
 
+/*
+ * Machine interface: open a trackers element.
+ *
+ * writer An instance of a machine interface writer.
+ *
+ * Returns zero if the element's value could be written.
+ * Negative values indicate an error.
+ */
+int mi_lttng_trackers_open(struct mi_writer *writer);
+
+/*
+ * Machine interface: open a pid_tracker element.
+ *
+ * writer An instance of a machine interface writer.
+ *
+ * Returns zero if the element's value could be written.
+ * Negative values indicate an error.
+ *
+ * Note: A targets element is also opened for each tracker definition
+ */
+int mi_lttng_pid_tracker_open(struct mi_writer *writer);
+
 /*
  * Machine interface: open a PIDs element.
  *
@@ -566,7 +593,17 @@ int mi_lttng_event_fields_open(struct mi_writer *writer);
 int mi_lttng_pids_open(struct mi_writer *writer);
 
 /*
- * Machine interface of a PID.
+ * Machine interface: open a processes element.
+ *
+ * writer An instance of a machine interface writer.
+ *
+ * Returns zero if the element's value could be written.
+ * Negative values indicate an error.
+ */
+int mi_lttng_processes_open(struct mi_writer *writer);
+
+/*
+ * Machine interface of a Process.
  *
  * writer An instance of a machine interface writer.
  * pid A PID.
@@ -580,8 +617,27 @@ int mi_lttng_pids_open(struct mi_writer *writer);
  * Returns zero if the element's value could be written.
  * Negative values indicate an error.
  */
-int mi_lttng_pid(struct mi_writer *writer, pid_t pid , const char *cmdline,
+int mi_lttng_process(struct mi_writer *writer, pid_t pid , const char *name,
                int is_open);
+/*
+ * Machine interface: open a targets element.
+ *
+ * writer An instance of a machine interface writer.
+ *
+ * Returns zero if the element's value could be written.
+ * Negative values indicate an error.
+ */
+int mi_lttng_targets_open(struct mi_writer *writer);
+
+/*
+ * Machine interface for track/untrack a pid_target
+ *
+ * writer An instance of a machine interface writer.
+ *
+ * Returns zero if the element's value could be written.
+ * Negative values indicate an error.
+ */
+int mi_lttng_pid_target(struct mi_writer *writer, pid_t pid, int is_open);
 
 /*
  * Machine interface for struct lttng_calibrate.
index 5f078c94ad67b4fbf635d77f493084d970e63cb2..27588f2047c7f3061c4af3fa2f0853066d11bf05 100644 (file)
@@ -2004,7 +2004,8 @@ end:
 int lttng_list_tracker_pids(struct lttng_handle *handle,
                int *_enabled, int32_t **_pids, size_t *_nr_pids)
 {
-       int ret, enabled = 1;
+       int ret;
+       int enabled = 1;
        struct lttcomm_session_msg lsm;
        size_t nr_pids;
        int32_t *pids;
This page took 0.033893 seconds and 4 git commands to generate.