From e6ddca715d6dedb6ee25fe4392a6e1f9626b2544 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Mon, 18 Jul 2011 10:37:48 -0400 Subject: [PATCH] Fix tracing events data structure Make lttng_kernel_output generic to user-space and kernel becoming lttng_event_output. Renaming enum to fit kernel ABI. Add comments. Signed-off-by: David Goulet --- include/lttng-kernel.h | 14 ++++++-- include/lttng-share.h | 5 ++- include/lttng/lttng.h | 64 ++++++++++++++++++++++------------ ltt-sessiond/main.c | 2 +- ltt-sessiond/trace.c | 8 ++--- lttng/commands/enable_events.c | 10 +++--- 6 files changed, 67 insertions(+), 36 deletions(-) diff --git a/include/lttng-kernel.h b/include/lttng-kernel.h index 6fa4e3925..3259bff84 100644 --- a/include/lttng-kernel.h +++ b/include/lttng-kernel.h @@ -26,9 +26,17 @@ #define LTTNG_SYM_NAME_LEN 128 enum lttng_kernel_instrumentation { - LTTNG_KERNEL_TRACEPOINTS, - LTTNG_KERNEL_KPROBES, - LTTNG_KERNEL_FUNCTION, + LTTNG_KERNEL_TRACEPOINT = 0, + LTTNG_KERNEL_KPROBE = 1, + LTTNG_KERNEL_FUNCTION = 2, +}; + +/* + * LTTng consumer mode + */ +enum lttng_kernel_output { + LTTNG_KERNEL_SPLICE = 0, + LTTNG_KERNEL_MMAP = 1, }; /* diff --git a/include/lttng-share.h b/include/lttng-share.h index 825456c56..30aa23cd3 100644 --- a/include/lttng-share.h +++ b/include/lttng-share.h @@ -38,9 +38,12 @@ typedef __s64 s64; #define DEFAULT_CHANNEL_SUBBUF_NUM 8 #define DEFAULT_CHANNEL_SWITCH_TIMER 0 /* usec */ #define DEFAULT_CHANNEL_READ_TIMER 200 /* usec */ -/* See lttng.h enum lttng_kernel_output for channel output */ +/* See lttng-kernel.h enum lttng_kernel_output for channel output */ #define DEFAULT_KERNEL_CHANNEL_OUTPUT LTTNG_KERNEL_SPLICE + +/* == NOT IMPLEMENTED == #define DEFAULT_UST_CHANNEL_OUTPUT LTTNG_UST_MMAP +*/ /* * lttng user-space instrumentation type diff --git a/include/lttng/lttng.h b/include/lttng/lttng.h index b5b799fc6..448bd9fdc 100644 --- a/include/lttng/lttng.h +++ b/include/lttng/lttng.h @@ -37,16 +37,33 @@ #define LTTNG_DEFAULT_TRACE_DIR_NAME "lttng-traces" /* - * Event symbol length. + * Event symbol length. Copied from LTTng kernel ABI. */ #define LTTNG_SYMBOL_NAME_LEN 128 +/* + * Every lttng_event_* structure both apply to kernel event and user-space + * event. + * + * Every lttng_kernel_* is copied from the LTTng kernel ABI. + */ + enum lttng_event_type { - LTTNG_EVENT_TRACEPOINTS, - LTTNG_EVENT_KPROBES, + LTTNG_EVENT_TRACEPOINT, + LTTNG_EVENT_KPROBE, LTTNG_EVENT_FUNCTION, }; +/* + * LTTng consumer mode + */ +enum lttng_event_output { + /* Using splice(2) */ + LTTNG_EVENT_SPLICE = 0, + /* Using mmap(2) */ + LTTNG_EVENT_MMAP = 1, +}; + /* Kernel context possible type */ enum lttng_kernel_context_type { LTTNG_KERNEL_CONTEXT_PID = 0, @@ -76,14 +93,6 @@ struct lttng_kernel_context { } u; }; -/* - * LTTng consumer mode - */ -enum lttng_kernel_output { - LTTNG_KERNEL_SPLICE = 0, - LTTNG_KERNEL_MMAP = 1, -}; - /* * Either addr is used or symbol_name and offset. */ @@ -114,28 +123,37 @@ struct lttng_event { } attr; }; -/* Tracer channel attributes */ +/* + * Tracer channel attributes. For both kernel and user-space. + */ struct lttng_channel_attr { int overwrite; /* 1: overwrite, 0: discard */ uint64_t subbuf_size; /* bytes */ uint64_t num_subbuf; /* power of 2 */ unsigned int switch_timer_interval; /* usec */ unsigned int read_timer_interval; /* usec */ - enum lttng_kernel_output output; /* splice, mmap */ + enum lttng_event_output output; /* splice, mmap */ }; /* - * Basic session information. + * Channel information structure. For both kernel and user-space. */ -struct lttng_session { +struct lttng_channel { char name[NAME_MAX]; - char path[PATH_MAX]; + struct lttng_channel_attr attr; }; -/* Channel information structure */ -struct lttng_channel { +/* + * Basic session information. + * + * This is an 'output data' meaning that it only comes *from* the session + * daemon *to* the lttng client. It's basically a 'human' representation of + * tracing entities (here a session). + */ +struct lttng_session { char name[NAME_MAX]; - struct lttng_channel_attr attr; + /* The path where traces are written */ + char path[PATH_MAX]; }; /* @@ -149,7 +167,9 @@ extern int lttng_destroy_session(char *name); extern int lttng_disconnect_sessiond(void); -/* Return an allocated array of lttng_session */ +/* + * Return a "lttng_session" array. Caller must free(3) the returned data. + */ extern int lttng_list_sessions(struct lttng_session **sessions); extern int lttng_session_daemon_alive(void); @@ -165,8 +185,6 @@ extern int lttng_start_tracing(char *session_name); extern int lttng_stop_tracing(char *session_name); -//extern int lttng_ust_list_traceable_apps(pid_t **pids); - /* * LTTng Kernel tracer control */ @@ -189,4 +207,6 @@ extern int lttng_kernel_list_events(char **event_list); * LTTng User-space tracer control */ +//extern int lttng_ust_list_traceable_apps(pid_t **pids); + #endif /* _LTTNG_H */ diff --git a/ltt-sessiond/main.c b/ltt-sessiond/main.c index f99513a2b..39dfbc41d 100644 --- a/ltt-sessiond/main.c +++ b/ltt-sessiond/main.c @@ -1663,7 +1663,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx) if (ev == NULL) { strncpy(ev_attr.name, event, LTTNG_SYM_NAME_LEN); /* Default event type for enable all */ - ev_attr.type = LTTNG_EVENT_TRACEPOINTS; + ev_attr.type = LTTNG_EVENT_TRACEPOINT; /* Enable each single tracepoint event */ ret = kernel_create_event(&ev_attr, chan); if (ret < 0) { diff --git a/ltt-sessiond/trace.c b/ltt-sessiond/trace.c index 25276696a..e0aeac685 100644 --- a/ltt-sessiond/trace.c +++ b/ltt-sessiond/trace.c @@ -175,8 +175,8 @@ struct ltt_kernel_event *trace_create_kernel_event(struct lttng_event *ev) } switch (ev->type) { - case LTTNG_EVENT_KPROBES: - attr->instrumentation = LTTNG_KERNEL_KPROBES; + case LTTNG_EVENT_KPROBE: + attr->instrumentation = LTTNG_KERNEL_KPROBE; attr->u.kprobe.addr = ev->attr.kprobe.addr; attr->u.kprobe.offset = ev->attr.kprobe.offset; strncpy(attr->u.kprobe.symbol_name, @@ -187,8 +187,8 @@ struct ltt_kernel_event *trace_create_kernel_event(struct lttng_event *ev) strncpy(attr->u.ftrace.symbol_name, ev->attr.ftrace.symbol_name, LTTNG_SYM_NAME_LEN); break; - case LTTNG_EVENT_TRACEPOINTS: - attr->instrumentation = LTTNG_KERNEL_TRACEPOINTS; + case LTTNG_EVENT_TRACEPOINT: + attr->instrumentation = LTTNG_KERNEL_TRACEPOINT; break; default: ERR("Unknown kernel instrumentation type (%d)", ev->type); diff --git a/lttng/commands/enable_events.c b/lttng/commands/enable_events.c index ce8d60241..65bd19575 100644 --- a/lttng/commands/enable_events.c +++ b/lttng/commands/enable_events.c @@ -191,13 +191,13 @@ static int enable_events(void) ev.type = opt_event_type; switch (opt_event_type) { - case LTTNG_EVENT_TRACEPOINTS: + case LTTNG_EVENT_TRACEPOINT: ret = lttng_kernel_enable_event(&ev, channel_name); if (ret < 0) { ERR("Unable to find event %s", ev.name); } break; - case LTTNG_EVENT_KPROBES: + case LTTNG_EVENT_KPROBE: ret = parse_kprobe_opts(&ev, opt_kprobe); if (ret < 0) { ERR("Unable to parse kprobe options"); @@ -258,7 +258,7 @@ int cmd_enable_events(int argc, const char **argv) poptReadDefaultConfig(pc, 0); /* Default event type */ - opt_event_type = LTTNG_KERNEL_TRACEPOINTS; + opt_event_type = LTTNG_EVENT_TRACEPOINT; while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { @@ -271,13 +271,13 @@ int cmd_enable_events(int argc, const char **argv) opt_cmd_name = poptGetOptArg(pc); break; case OPT_TRACEPOINT: - opt_event_type = LTTNG_EVENT_TRACEPOINTS; + opt_event_type = LTTNG_EVENT_TRACEPOINT; break; case OPT_MARKER: ret = CMD_NOT_IMPLEMENTED; goto end; case OPT_KPROBE: - opt_event_type = LTTNG_EVENT_KPROBES; + opt_event_type = LTTNG_EVENT_KPROBE; opt_kprobe = poptGetOptArg(pc); break; case OPT_FUNCTION: -- 2.34.1