goto end;
}
- /* Open pids element */
- ret = mi_lttng_pids_open(writer);
+ /* Open processes element */
+ ret = mi_lttng_processes_open(writer);
if (ret) {
goto end;
}
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;
}
}
}
- /* Close pids */
+ /* Close processes */
ret = mi_lttng_writer_close_element(writer);
if (ret) {
goto end;
goto end;
}
- /* Open pids element */
- ret = mi_lttng_pids_open(writer);
+ /* Open processes element */
+ ret = mi_lttng_processes_open(writer);
if (ret) {
goto end;
}
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;
}
}
}
- /* Close pids, domain, domains */
+ /* Close processes, domain, domains */
ret = mi_lttng_close_multi_element(writer, 3);
end:
return ret;
*/
static int list_tracker_pids(void)
{
- int enabled, ret;
+ int ret = 0;
+ int enabled;
int *pids = NULL;
size_t nr_pids;
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;
}
/*
}
- ret = list_tracker_pids();
+
+ /* Trackers */
+ ret = list_trackers();
if (ret) {
goto end;
}
+ /* Channels */
ret = list_channels(opt_channel);
if (ret) {
goto end;
switch (domains[i].type) {
case LTTNG_DOMAIN_KERNEL:
case LTTNG_DOMAIN_UST:
- ret = list_tracker_pids();
+ ret = list_trackers();
if (ret) {
goto end;
}
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;
}
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;
}
}
- /* SUCCESS */
end:
if (handle) {
lttng_destroy_handle(handle);
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;
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";
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 */
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)
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:
return ret;
}
-/* TODO: mi tracker */
-
LTTNG_HIDDEN
int mi_lttng_context(struct mi_writer *writer,
struct lttng_event_context *context, int is_open)
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 */
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.
*
*/
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.
*
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.
* 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.
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;