From: David Goulet Date: Tue, 24 May 2011 15:32:17 +0000 (-0400) Subject: Add kernel enable event support X-Git-Tag: v2.0-pre1~126 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=f34daff7d0139d162e949f1b4fbb4cd003746b15;p=lttng-tools.git Add kernel enable event support Signed-off-by: David Goulet --- diff --git a/liblttsessiondcomm/liblttsessiondcomm.c b/liblttsessiondcomm/liblttsessiondcomm.c index 19bda8388..5cd0f1203 100644 --- a/liblttsessiondcomm/liblttsessiondcomm.c +++ b/liblttsessiondcomm/liblttsessiondcomm.c @@ -51,6 +51,8 @@ static const char *lttcomm_readable_code[] = { [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_NA) ] = "Kernel tracer not available", [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_SESS_FAIL) ] = "Kernel create session failed", [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CHAN_FAIL) ] = "Kernel create channel failed", + [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_ENABLE_FAIL) ] = "Enable kernel event failed", + [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_DISABLE_FAIL) ] = "Disable kernel event failed", [ LTTCOMM_ERR_INDEX(KCONSUMERD_COMMAND_SOCK_READY) ] = "Kconsumerd command socket ready", [ LTTCOMM_ERR_INDEX(KCONSUMERD_SUCCESS_RECV_FD) ] = "Kconsumerd success on receiving fds", [ LTTCOMM_ERR_INDEX(KCONSUMERD_ERROR_RECV_FD) ] = "Kconsumerd error on receiving fds", diff --git a/liblttsessiondcomm/liblttsessiondcomm.h b/liblttsessiondcomm/liblttsessiondcomm.h index 580d4c2c7..879982101 100644 --- a/liblttsessiondcomm/liblttsessiondcomm.h +++ b/liblttsessiondcomm/liblttsessiondcomm.h @@ -103,6 +103,8 @@ enum lttcomm_return_code { LTTCOMM_KERN_NA, /* Kernel tracer unavalable */ LTTCOMM_KERN_SESS_FAIL, /* Kernel create session failed */ LTTCOMM_KERN_CHAN_FAIL, /* Kernel create channel failed */ + LTTCOMM_KERN_ENABLE_FAIL, /* Kernel enable event failed */ + LTTCOMM_KERN_DISABLE_FAIL, /* Kernel disable event failed */ KCONSUMERD_COMMAND_SOCK_READY, /* when kconsumerd command socket ready */ KCONSUMERD_SUCCESS_RECV_FD, /* success on receiving fds */ KCONSUMERD_ERROR_RECV_FD, /* error on receiving fds */ diff --git a/ltt-sessiond/kernel-ctl.c b/ltt-sessiond/kernel-ctl.c index 5d70296ea..02e87e340 100644 --- a/ltt-sessiond/kernel-ctl.c +++ b/ltt-sessiond/kernel-ctl.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "ltt-sessiond.h" #include "libkernelctl.h" @@ -101,3 +102,42 @@ int kernel_create_channel(struct command_ctx *cmd_ctx) error: return ret; } + +/* + * kernel_enable_event + * + * Enable kernel event. + */ +int kernel_enable_event(struct ltt_kernel_channel *channel, char *name) +{ + int ret; + struct ltt_kernel_event *event; + struct lttng_kernel_event *lke; + + event = malloc(sizeof(struct ltt_kernel_event)); + lke = malloc(sizeof(struct lttng_kernel_event)); + + if (event == NULL || lke == NULL) { + perror("kernel enable event malloc"); + ret = -errno; + goto error; + } + + /* Setting up a kernel event */ + strncpy(lke->name, name, LTTNG_SYM_NAME_LEN); + lke->instrumentation = LTTNG_KERNEL_TRACEPOINTS; + event->event = lke; + + ret = kernctl_create_event(channel->fd, lke); + if (ret < 0) { + goto error; + } + + /* Add event to event list */ + cds_list_add(&event->list, &channel->events_list.head); + + return 0; + +error: + return ret; +} diff --git a/ltt-sessiond/kernel-ctl.h b/ltt-sessiond/kernel-ctl.h index 35057be08..b8f41e7d9 100644 --- a/ltt-sessiond/kernel-ctl.h +++ b/ltt-sessiond/kernel-ctl.h @@ -19,7 +19,10 @@ #ifndef _LTT_KERNEL_CTL_H #define _LTT_KERNEL_CTL_H +#include "trace.h" + int kernel_create_session(struct command_ctx *cmd_ctx, int tracer_fd); int kernel_create_channel(struct command_ctx *cmd_ctx); +int kernel_enable_event(struct ltt_kernel_channel *channel, char *name); #endif /* _LTT_KERNEL_CTL_H */ diff --git a/ltt-sessiond/main.c b/ltt-sessiond/main.c index 5b7fb0c21..88a43d968 100644 --- a/ltt-sessiond/main.c +++ b/ltt-sessiond/main.c @@ -526,6 +526,12 @@ static int process_client_msg(struct command_ctx *cmd_ctx) DBG("Enabling kernel event %s", cmd_ctx->lsm->u.event.event_name); + ret = kernel_enable_event(cmd_ctx->session->kernel_session->channel, cmd_ctx->lsm->u.event.event_name); + if (ret < 0) { + ret = LTTCOMM_KERN_ENABLE_FAIL; + goto error; + } + ret = LTTCOMM_OK; break; } diff --git a/ltt-sessiond/trace.h b/ltt-sessiond/trace.h index 9cfbd84ab..5b4ff68ff 100644 --- a/ltt-sessiond/trace.h +++ b/ltt-sessiond/trace.h @@ -30,8 +30,8 @@ struct ltt_kernel_event_list { /* Kernel event */ struct ltt_kernel_event { - char name[NAME_MAX]; int fd; + struct lttng_kernel_event *event; struct cds_list_head list; }; diff --git a/lttng/lttng.c b/lttng/lttng.c index beb67ffb4..c7c88f631 100644 --- a/lttng/lttng.c +++ b/lttng/lttng.c @@ -131,11 +131,12 @@ static int process_client_opt(void) if (opt_event_list != NULL) { ret = process_opt_kernel_event(); + if (ret < 0) { + goto end; + } } else { // Enable all events } - - goto error; } if (opt_trace_pid != 0) { @@ -521,7 +522,7 @@ static int validate_options(void) } /* If start trace, auto start tracing */ - if (opt_start_trace) { + if (opt_start_trace || opt_event_list != NULL) { DBG("Requesting auto tracing"); auto_trace = 1; }