From 8c9ae521a34f2d83c42ced6b00a599518e8473e8 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Thu, 22 Sep 2011 16:22:02 -0400 Subject: [PATCH] Fix enable all syscalls The -a -k --syscall was enabling all syscalls and all tracepoints. Fix this issues by adding the enabel_kernel_event_syscalls. At this commit, there is a problem with the list event that does not list correctly all syscalls. Signed-off-by: David Goulet --- liblttngctl/lttngctl.c | 6 ++--- ltt-sessiond/event.c | 37 +++++++++++++++++++++++++++ ltt-sessiond/event.h | 2 ++ ltt-sessiond/main.c | 19 +++++++++++--- lttng/commands/enable_events.c | 36 +++++++++++++++----------- tests/lttng/kernel_all_events_basic.c | 6 ++++- 6 files changed, 83 insertions(+), 23 deletions(-) diff --git a/liblttngctl/lttngctl.c b/liblttngctl/lttngctl.c index bec1dbb85..0442a4f02 100644 --- a/liblttngctl/lttngctl.c +++ b/liblttngctl/lttngctl.c @@ -492,7 +492,7 @@ int lttng_enable_event(struct lttng_handle *handle, { struct lttcomm_session_msg lsm; - if (!handle) { + if (!handle || ev == NULL) { return -1; } @@ -506,12 +506,12 @@ int lttng_enable_event(struct lttng_handle *handle, copy_lttng_domain(&lsm.domain, &handle->domain); - if (ev && ev->name[0] != '\0') { + if (ev->name[0] != '\0') { lsm.cmd_type = LTTNG_ENABLE_EVENT; - memcpy(&lsm.u.enable.event, ev, sizeof(lsm.u.enable.event)); } else { lsm.cmd_type = LTTNG_ENABLE_ALL_EVENT; } + memcpy(&lsm.u.enable.event, ev, sizeof(lsm.u.enable.event)); copy_string(lsm.session.name, handle->session_name, sizeof(lsm.session.name)); diff --git a/ltt-sessiond/event.c b/ltt-sessiond/event.c index 3e3ecd320..66e134e46 100644 --- a/ltt-sessiond/event.c +++ b/ltt-sessiond/event.c @@ -25,6 +25,19 @@ #include "event.h" #include "kernel-ctl.h" +/* + * Setup a lttng_event used to enable *all* syscall tracing. + */ +static void init_syscalls_kernel_event(struct lttng_event *event) +{ + event->name[0] = '\0'; + /* + * We use LTTNG_EVENT* here since the trace kernel creation will make the + * right changes for the kernel. + */ + event->type = LTTNG_EVENT_SYSCALL; +} + /* * Disable kernel event for a channel from the kernel session. */ @@ -153,3 +166,27 @@ int event_kernel_enable_all(struct ltt_kernel_session *ksession, error: return ret; } + +/* + * Enable all kernel syscalls tracing. + */ +int event_kernel_enable_syscalls(struct ltt_kernel_session *ksession, + struct ltt_kernel_channel *kchan, int kernel_tracer_fd) +{ + int ret; + struct lttng_event event; + + init_syscalls_kernel_event(&event); + + DBG("Enabling all syscall tracing"); + + ret = kernel_create_event(&event, kchan); + if (ret < 0) { + goto error; + } + + ret = LTTCOMM_OK; + +error: + return ret; +} diff --git a/ltt-sessiond/event.h b/ltt-sessiond/event.h index 3399466cf..0ef52fe7b 100644 --- a/ltt-sessiond/event.h +++ b/ltt-sessiond/event.h @@ -30,5 +30,7 @@ int event_kernel_enable(struct ltt_kernel_session *ksession, struct ltt_kernel_channel *kchan, struct lttng_event *event); int event_kernel_enable_all(struct ltt_kernel_session *ksession, struct ltt_kernel_channel *kchan, int kernel_tracer_fd); +int event_kernel_enable_syscalls(struct ltt_kernel_session *ksession, + struct ltt_kernel_channel *kchan, int kernel_tracer_fd); #endif /* _LTT_EVENT_H */ diff --git a/ltt-sessiond/main.c b/ltt-sessiond/main.c index 867ba4188..a1c7ff89e 100644 --- a/ltt-sessiond/main.c +++ b/ltt-sessiond/main.c @@ -1950,7 +1950,7 @@ error: * Command LTTNG_ENABLE_ALL_EVENT processed by the client thread. */ static int cmd_enable_event_all(struct ltt_session *session, int domain, - char *channel_name) + char *channel_name, int event_type) { int ret; struct ltt_kernel_channel *kchan; @@ -1977,8 +1977,18 @@ static int cmd_enable_event_all(struct ltt_session *session, int domain, goto error; } - ret = event_kernel_enable_all(session->kernel_session, - kchan, kernel_tracer_fd); + if (event_type == LTTNG_KERNEL_SYSCALL) { + ret = event_kernel_enable_syscalls(session->kernel_session, + kchan, kernel_tracer_fd); + } else { + /* + * This call enables all LTTNG_KERNEL_TRACEPOINTS and events + * already registered to the channel. + */ + ret = event_kernel_enable_all(session->kernel_session, + kchan, kernel_tracer_fd); + } + if (ret != LTTCOMM_OK) { goto error; } @@ -2501,7 +2511,8 @@ static int process_client_msg(struct command_ctx *cmd_ctx) DBG("Enabling all kernel event"); ret = cmd_enable_event_all(cmd_ctx->session, cmd_ctx->lsm->domain.type, - cmd_ctx->lsm->u.enable.channel_name); + cmd_ctx->lsm->u.enable.channel_name, + cmd_ctx->lsm->u.enable.event.type); break; } case LTTNG_LIST_TRACEPOINTS: diff --git a/lttng/commands/enable_events.c b/lttng/commands/enable_events.c index 85fd86a08..78227be1f 100644 --- a/lttng/commands/enable_events.c +++ b/lttng/commands/enable_events.c @@ -213,33 +213,38 @@ static int enable_events(char *session_name) } if (opt_enable_all) { + /* Default setup for enable all */ + ev.name[0] = '\0'; + ev.type = opt_event_type; + + ret = lttng_enable_event(handle, &ev, channel_name); + if (ret < 0) { + goto error; + } + switch (opt_event_type) { case LTTNG_EVENT_TRACEPOINT: if (opt_kernel) { - ret = lttng_enable_event(handle, NULL, channel_name); - if (ret == 0) { - MSG("All kernel events are enabled in channel %s", channel_name); - } - goto error; + MSG("All kernel events are enabled in channel %s", + channel_name); } - /* TODO: User-space tracer */ break; case LTTNG_EVENT_SYSCALL: if (opt_kernel) { - ev.name[0] = '\0'; - ev.type = opt_event_type; - - ret = lttng_enable_event(handle, &ev, channel_name); - if (ret == 0) { - MSG("All kernel system calls are enabled in channel %s", channel_name); - } - goto error; + MSG("All kernel system calls are enabled in channel %s", + channel_name); } break; default: - MSG("Enable all not supported for this instrumentation type."); + /* + * We should not be here since lttng_enable_event should had failed + * on the event type. + */ goto error; + } + + goto end; } /* Strip event list */ @@ -310,6 +315,7 @@ static int enable_events(char *session_name) event_name = strtok(NULL, ","); } +end: error: if (opt_channel_name == NULL) { free(channel_name); diff --git a/tests/lttng/kernel_all_events_basic.c b/tests/lttng/kernel_all_events_basic.c index 65a710e5a..215fa6837 100644 --- a/tests/lttng/kernel_all_events_basic.c +++ b/tests/lttng/kernel_all_events_basic.c @@ -33,11 +33,15 @@ int main(int argc, char **argv) { struct lttng_handle *handle = NULL; struct lttng_domain dom; + struct lttng_event event; char *channel_name = "mychan"; int ret = 0; dom.type = LTTNG_DOMAIN_KERNEL; + memset(&event, 0, sizeof(struct lttng_event)); + event.type = LTTNG_EVENT_TRACEPOINT; + printf("\nTesting tracing all kernel events:\n"); printf("-----------\n"); /* Check if root */ @@ -66,7 +70,7 @@ int main(int argc, char **argv) PRINT_OK(); printf("Enabling all kernel events: "); - if ((ret = lttng_enable_event(handle, NULL, channel_name)) < 0) { + if ((ret = lttng_enable_event(handle, &event, channel_name)) < 0) { printf("error enabling event: %s\n", lttng_get_readable_code(ret)); goto enable_fail; } -- 2.34.1