From: Jonathan Rajotte Date: Tue, 11 Aug 2015 19:14:11 +0000 (-0400) Subject: Mi: track/untrack/listing X-Git-Tag: v2.7.0-rc2~156 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=a585578f837d992f00eba4f090c8ba251d9de94e;p=lttng-tools.git Mi: track/untrack/listing Signed-off-by: Jonathan Rajotte Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng/commands/list.c b/src/bin/lttng/commands/list.c index cc776dd42..f7f3852b3 100644 --- a/src/bin/lttng/commands/list.c +++ b/src/bin/lttng/commands/list.c @@ -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; } diff --git a/src/bin/lttng/commands/track-untrack.c b/src/bin/lttng/commands/track-untrack.c index 639e18481..e9a6677b0 100644 --- a/src/bin/lttng/commands/track-untrack.c +++ b/src/bin/lttng/commands/track-untrack.c @@ -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); diff --git a/src/common/config/config-session-abi.h b/src/common/config/config-session-abi.h index c578af7e9..b2e939718 100644 --- a/src/common/config/config-session-abi.h +++ b/src/common/config/config-session-abi.h @@ -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; diff --git a/src/common/config/config.c b/src/common/config/config.c index 8608faf98..783e784b2 100644 --- a/src/common/config/config.c +++ b/src/common/config/config.c @@ -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"; diff --git a/src/common/mi-lttng.c b/src/common/mi-lttng.c index 44ff56f1e..f2d223f86 100644 --- a/src/common/mi-lttng.c +++ b/src/common/mi-lttng.c @@ -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) diff --git a/src/common/mi-lttng.h b/src/common/mi-lttng.h index deab4e41c..23b7810c4 100644 --- a/src/common/mi-lttng.h +++ b/src/common/mi-lttng.h @@ -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. diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 42c9d1390..19b9e5117 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -2003,7 +2003,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;