X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=liblttngctl%2Fliblttngctl.c;h=c851ce6ad70bdf847cd2b8f26ae715b31d527c8e;hp=d8230c618170a15219a96e9e5776d437d17a17af;hb=65beb5ffdbe6e17dbd0268aad3c32b02322cd9ad;hpb=2ef84c95c5158ce40e77229fb5705524ff22be7b diff --git a/liblttngctl/liblttngctl.c b/liblttngctl/liblttngctl.c index d8230c618..c851ce6ad 100644 --- a/liblttngctl/liblttngctl.c +++ b/liblttngctl/liblttngctl.c @@ -28,6 +28,7 @@ #include "liblttsessiondcomm.h" #include "lttngerr.h" +#include "lttng-share.h" /* Socket to session daemon for communication */ static int sessiond_socket; @@ -88,70 +89,9 @@ end: } /* - * ask_sessiond - * - * Ask the session daemon a specific command and put the data into buf. - * - * Return size of data (only payload, not header). - */ -static int ask_sessiond(enum lttcomm_sessiond_command lct, void **buf) -{ - int ret; - size_t size; - void *data = NULL; - - ret = lttng_connect_sessiond(); - if (ret < 0) { - goto end; - } - - lsm.cmd_type = lct; - - /* Send command to session daemon */ - ret = send_data_sessiond(); - if (ret < 0) { - goto end; - } - - /* Get header from data transmission */ - ret = recv_data_sessiond(&llm, sizeof(llm)); - if (ret < 0) { - goto end; - } - - /* Check error code if OK */ - if (llm.ret_code != LTTCOMM_OK) { - ret = -llm.ret_code; - goto end; - } - - size = llm.trace_name_offset + llm.data_size; - if (size == 0) { - goto end; - } - - data = (void*) malloc(size); - - /* Get payload data */ - ret = recv_data_sessiond(data, size); - if (ret < 0) { - free(data); - goto end; - } - - *buf = data; - ret = size; - -end: - lttng_disconnect_sessiond(); - return ret; -} - -/* - * check_tracing_group - * * Check if the specified group name exist. - * If yes, 0, else -1 + * + * If yes return 0, else return -1. */ static int check_tracing_group(const char *grp_name) { @@ -200,10 +140,8 @@ end: } /* - * set_session_daemon_path - * - * Set sessiond socket path by putting it in - * the global sessiond_sock_path variable. + * Set sessiond socket path by putting it in the global sessiond_sock_path + * variable. */ static int set_session_daemon_path(void) { @@ -225,153 +163,261 @@ static int set_session_daemon_path(void) } /* - * BEGIN KERNEL CONTROL - */ - -/* - * lttng_kernel_enable_event + * Connect to the LTTng session daemon. * - * Enable an event in the kernel tracer. + * On success, return 0. On error, return -1. */ -int lttng_kernel_enable_event(char *event_name) +static int connect_sessiond(void) { - strncpy(lsm.u.event.event_name, event_name, NAME_MAX); - return ask_sessiond(KERNEL_ENABLE_EVENT, NULL); + int ret; + + ret = set_session_daemon_path(); + if (ret < 0) { + return ret; + } + + /* Connect to the sesssion daemon */ + ret = lttcomm_connect_unix_sock(sessiond_sock_path); + if (ret < 0) { + return ret; + } + + sessiond_socket = ret; + connected = 1; + + return 0; } /* - * lttng_kernel_disable_event - * - * Disable an event in the kernel tracer. + * Clean disconnect the session daemon. */ -int lttng_kernel_disable_event(char *event_name) +static int disconnect_sessiond(void) { - strncpy(lsm.u.event.event_name, event_name, NAME_MAX); - return ask_sessiond(KERNEL_DISABLE_EVENT, NULL); + int ret = 0; + + if (connected) { + ret = lttcomm_close_unix_sock(sessiond_socket); + sessiond_socket = 0; + connected = 0; + } + + return ret; } /* - * lttng_kernel_create_session + * ask_sessiond + * + * Ask the session daemon a specific command and put the data into buf. * - * Create a session in the kernel tracer. + * Return size of data (only payload, not header). */ -int lttng_kernel_create_session(void) +static int ask_sessiond(enum lttcomm_sessiond_command lct, void **buf) { - return ask_sessiond(KERNEL_CREATE_SESSION, NULL); + int ret; + size_t size; + void *data = NULL; + + ret = connect_sessiond(); + if (ret < 0) { + goto end; + } + + lsm.cmd_type = lct; + + /* Send command to session daemon */ + ret = send_data_sessiond(); + if (ret < 0) { + goto end; + } + + /* Get header from data transmission */ + ret = recv_data_sessiond(&llm, sizeof(llm)); + if (ret < 0) { + goto end; + } + + /* Check error code if OK */ + if (llm.ret_code != LTTCOMM_OK) { + ret = -llm.ret_code; + goto end; + } + + size = llm.data_size; + if (size == 0) { + goto end; + } + + data = (void*) malloc(size); + + /* Get payload data */ + ret = recv_data_sessiond(data, size); + if (ret < 0) { + free(data); + goto end; + } + + *buf = data; + ret = size; + +end: + disconnect_sessiond(); + return ret; } /* - * lttng_kernel_create_channel + * lttng_start_tracing * - * Create a channel in the kernel tracer. + * Start tracing for all trace of the session. */ -int lttng_kernel_create_channel(void) +int lttng_start_tracing(char *session_name) { - return ask_sessiond(KERNEL_CREATE_CHANNEL, NULL); + strncpy(lsm.session_name, session_name, NAME_MAX); + return ask_sessiond(LTTNG_START_TRACE, NULL); } /* - * lttng_kernel_open_metadata + * lttng_stop_tracing * - * Open metadata in the kernel tracer. + * Stop tracing for all trace of the session. */ -int lttng_kernel_open_metadata(void) +int lttng_stop_tracing(char *session_name) { - return ask_sessiond(KERNEL_OPEN_METADATA, NULL); + strncpy(lsm.session_name, session_name, NAME_MAX); + return ask_sessiond(LTTNG_STOP_TRACE, NULL); } /* - * lttng_kernel_create_stream - * - * Create stream in the kernel tracer. + * BEGIN Kernel control API */ -int lttng_kernel_create_stream(void) -{ - return ask_sessiond(KERNEL_CREATE_STREAM, NULL); -} /* - * lttng_kernel_list_events - * - * List all available events in the kernel. - * - * Return the size (bytes) of the list and set the event_list array. - * On error, return negative value. + * lttng_kernel_add_context */ -int lttng_kernel_list_events(char **event_list) +int lttng_kernel_add_context(struct lttng_kernel_context *ctx, + char *event_name, char *channel_name) { - return ask_sessiond(KERNEL_LIST_EVENTS, (void **) event_list); + if (channel_name != NULL) { + strncpy(lsm.u.context.channel_name, channel_name, NAME_MAX); + } + + if (event_name != NULL) { + strncpy(lsm.u.context.event_name, event_name, NAME_MAX); + } + + memcpy(&lsm.u.context.ctx, ctx, sizeof(struct lttng_kernel_context)); + return ask_sessiond(LTTNG_KERNEL_ADD_CONTEXT, NULL); } /* - * lttng_kernel_start_tracing - * - * Start kernel tracing. + * lttng_kernel_enable_event */ -int lttng_kernel_start_tracing(void) +int lttng_kernel_enable_event(struct lttng_event *ev, char *channel_name) { - return ask_sessiond(KERNEL_START_TRACE, NULL); + int ret; + + if (channel_name == NULL) { + strncpy(lsm.u.enable.channel_name, DEFAULT_CHANNEL_NAME, NAME_MAX); + } else { + strncpy(lsm.u.enable.channel_name, channel_name, NAME_MAX); + } + + if (ev == NULL) { + ret = ask_sessiond(LTTNG_KERNEL_ENABLE_ALL_EVENT, NULL); + } else { + memcpy(&lsm.u.enable.event, ev, sizeof(struct lttng_event)); + ret = ask_sessiond(LTTNG_KERNEL_ENABLE_EVENT, NULL); + } + + return ret; } /* - * lttng_kernel_stop_tracing + * lttng_kernel_disable_event * - * Stop kernel tracing. + * Disable an event in the kernel tracer. */ -int lttng_kernel_stop_tracing(void) +int lttng_kernel_disable_event(char *name, char *channel_name) { - return ask_sessiond(KERNEL_STOP_TRACE, NULL); + int ret; + + if (channel_name == NULL) { + strncpy(lsm.u.disable.channel_name, DEFAULT_CHANNEL_NAME, NAME_MAX); + } else { + strncpy(lsm.u.disable.channel_name, channel_name, NAME_MAX); + } + + if (name == NULL) { + ret = ask_sessiond(LTTNG_KERNEL_DISABLE_ALL_EVENT, NULL); + } else { + strncpy(lsm.u.disable.name, name, NAME_MAX); + ret = ask_sessiond(LTTNG_KERNEL_DISABLE_EVENT, NULL); + } + + return ret; } /* - * END KERNEL CONTROL + * lttng_kernel_enable_channel + * + * Enable recording for a channel for the kernel tracer. */ +int lttng_kernel_enable_channel(char *name) +{ + strncpy(lsm.u.enable.channel_name, name, NAME_MAX); + return ask_sessiond(LTTNG_KERNEL_ENABLE_CHANNEL, NULL); +} /* - * lttng_get_readable_code + * lttng_kernel_disable_channel * - * Return a human readable string of code + * Disable recording for the channel for the kernel tracer. */ -const char *lttng_get_readable_code(int code) +int lttng_kernel_disable_channel(char *name) { - if (code > -LTTCOMM_OK) { - return "Ended with errors"; - } - - return lttcomm_get_readable_code(code); + strncpy(lsm.u.disable.channel_name, name, NAME_MAX); + return ask_sessiond(LTTNG_KERNEL_DISABLE_CHANNEL, NULL); } /* - * lttng_ust_start_trace + * lttng_kernel_create_channel * - * Request a trace start for pid. + * Create a channel in the kernel tracer. */ -int lttng_ust_start_trace(pid_t pid) +int lttng_kernel_create_channel(struct lttng_channel *chan) { - lsm.pid = pid; - return ask_sessiond(UST_START_TRACE, NULL); + memcpy(&lsm.u.channel.chan, chan, sizeof(struct lttng_channel)); + return ask_sessiond(LTTNG_KERNEL_CREATE_CHANNEL, NULL); } /* - * lttng_ust_stop_trace + * lttng_list_events + * + * List all available events in the kernel. * - * Request a trace stop for pid. + * Return the size (bytes) of the list and set the event_list array. + * On error, return negative value. */ -int lttng_ust_stop_trace(pid_t pid) +int lttng_kernel_list_events(char **event_list) { - lsm.pid = pid; - return ask_sessiond(UST_STOP_TRACE, NULL); + return ask_sessiond(LTTNG_KERNEL_LIST_EVENTS, (void **) event_list); } /* - * lttng_ust_create_trace + * END Kernel control API + */ + +/* + * lttng_get_readable_code * - * Request a trace creation for pid. + * Return a human readable string of code */ -int lttng_ust_create_trace(pid_t pid) +const char *lttng_get_readable_code(int code) { - lsm.pid = pid; - return ask_sessiond(UST_CREATE_TRACE, NULL); + if (code > -LTTCOMM_OK) { + return "Ended with errors"; + } + + return lttcomm_get_readable_code(code); } /* @@ -382,11 +428,11 @@ int lttng_ust_create_trace(pid_t pid) * Return the number of pids. * On error, return negative value. */ -int lttng_ust_list_apps(pid_t **pids) +int lttng_ust_list_traceable_apps(pid_t **pids) { int ret; - ret = ask_sessiond(UST_LIST_APPS, (void**) pids); + ret = ask_sessiond(LTTNG_LIST_TRACEABLE_APPS, (void**) pids); if (ret < 0) { return ret; } @@ -398,16 +444,17 @@ int lttng_ust_list_apps(pid_t **pids) * lttng_list_traces * * Ask the session daemon for all traces (kernel and ust) for the session - * identified by uuid. + * identified by name. * * Return the number of traces. * On error, return negative value. */ -int lttng_list_traces(uuid_t *uuid, struct lttng_trace **traces) +/* +int lttng_list_traces(char *session_name, struct lttng_trace **traces) { int ret; - uuid_copy(lsm.session_uuid, *uuid); + strncpy(lsm.session_name, session_name, NAME_MAX); ret = ask_sessiond(LTTNG_LIST_TRACES, (void **) traces); if (ret < 0) { @@ -416,15 +463,17 @@ int lttng_list_traces(uuid_t *uuid, struct lttng_trace **traces) return ret / sizeof(struct lttng_trace); } +*/ /* * lttng_create_session * * Create a brand new session using name. */ -int lttng_create_session(char *name) +int lttng_create_session(char *name, char *path) { strncpy(lsm.session_name, name, NAME_MAX); + strncpy(lsm.path, path, PATH_MAX); return ask_sessiond(LTTNG_CREATE_SESSION, NULL); } @@ -433,9 +482,9 @@ int lttng_create_session(char *name) * * Destroy session using name. */ -int lttng_destroy_session(uuid_t *uuid) +int lttng_destroy_session(char *name) { - uuid_copy(lsm.session_uuid, *uuid); + strncpy(lsm.session_name, name, NAME_MAX); return ask_sessiond(LTTNG_DESTROY_SESSION, NULL); } @@ -459,60 +508,9 @@ int lttng_list_sessions(struct lttng_session **sessions) return ret / sizeof(struct lttng_session); } -/* - * lttng_connect_sessiond - * - * Connect to the LTTng session daemon. - * On success, return 0 - * On error, return a negative value - */ -int lttng_connect_sessiond(void) -{ - int ret; - - ret = set_session_daemon_path(); - if (ret < 0) { - return ret; - } - - /* Connect to the sesssion daemon */ - ret = lttcomm_connect_unix_sock(sessiond_sock_path); - if (ret < 0) { - return ret; - } - - sessiond_socket = ret; - connected = 1; - - return 0; -} - -/* - * lttng_disconnect_sessiond - * - * Clean disconnect the session daemon. - */ -int lttng_disconnect_sessiond(void) -{ - int ret = 0; - - if (connected) { - ret = lttcomm_close_unix_sock(sessiond_socket); - sessiond_socket = 0; - connected = 0; - } - - return ret; -} - -/* - * lttng_set_current_session_uuid - * - * Set the session uuid for current lsm. - */ -void lttng_set_current_session_uuid(uuid_t *uuid) +void lttng_set_session_name(char *name) { - uuid_copy(lsm.session_uuid, *uuid); + strncpy(lsm.session_name, name, NAME_MAX); } /*