From b9dfb1671626365019a72318fb131eb321244245 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Mon, 30 Sep 2013 12:23:16 -0400 Subject: [PATCH] Add -j/--jul to lttng UI and ABI The JUL domain is set as unsupported in the session daemon so only the client side is implemented with help updated. Again, on the session daemon side, this is set as unsupported. Signed-off-by: David Goulet --- include/lttng/lttng-error.h | 2 +- include/lttng/lttng.h | 15 +++-------- src/bin/lttng-sessiond/main.c | 6 +++++ src/bin/lttng/commands/add_context.c | 2 +- src/bin/lttng/commands/calibrate.c | 2 +- src/bin/lttng/commands/disable_channels.c | 4 +-- src/bin/lttng/commands/disable_events.c | 12 ++++++--- src/bin/lttng/commands/enable_channels.c | 10 ++++---- src/bin/lttng/commands/enable_events.c | 31 ++++++++++++++++++----- src/bin/lttng/utils.c | 27 ++++++++++++++++++++ src/bin/lttng/utils.h | 10 ++++++++ src/common/error.c | 1 + src/lib/lttng-ctl/lttng-ctl.c | 1 + 13 files changed, 90 insertions(+), 33 deletions(-) diff --git a/include/lttng/lttng-error.h b/include/lttng/lttng-error.h index b43c88fbe..7631dbcc2 100644 --- a/include/lttng/lttng-error.h +++ b/include/lttng/lttng-error.h @@ -92,7 +92,7 @@ enum lttng_error_code { LTTNG_ERR_UST_CHAN_NOT_FOUND = 59, /* UST channel not found */ LTTNG_ERR_UST_CHAN_DISABLE_FAIL = 60, /* UST disable channel failed */ LTTNG_ERR_UST_CHAN_ENABLE_FAIL = 61, /* UST enable channel failed */ - /* 62 */ + LTTNG_ERR_CHAN_EXIST = 62, /* Channel already exists. */ LTTNG_ERR_UST_ENABLE_FAIL = 63, /* UST enable event failed */ LTTNG_ERR_UST_DISABLE_FAIL = 64, /* UST disable event failed */ LTTNG_ERR_UST_META_FAIL = 65, /* UST open metadata failed */ diff --git a/include/lttng/lttng.h b/include/lttng/lttng.h index 8f55a889e..0307536d3 100644 --- a/include/lttng/lttng.h +++ b/include/lttng/lttng.h @@ -47,18 +47,9 @@ extern "C" { * Domain types: the different possible tracers. */ enum lttng_domain_type { - LTTNG_DOMAIN_KERNEL = 1, - LTTNG_DOMAIN_UST = 2, - - /* - * For now, the domains below are not implemented. However, we keep them - * here in order to retain their enum values for future development. Note - * that it is on the roadmap to implement them. - * - LTTNG_DOMAIN_UST_EXEC_NAME = 3, - LTTNG_DOMAIN_UST_PID = 4, - LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN = 5, - */ + LTTNG_DOMAIN_KERNEL = 1, /* Linux Kernel tracer. */ + LTTNG_DOMAIN_UST = 2, /* Global Userspace tracer. */ + LTTNG_DOMAIN_JUL = 3, /* Java Util Logging. */ }; /* diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index eccc33a7b..028f5f9d2 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -2744,6 +2744,11 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int sock, } break; + case LTTNG_DOMAIN_JUL: + { + ret = LTTNG_ERR_UNKNOWN_DOMAIN; + goto error; + } case LTTNG_DOMAIN_UST: { if (!ust_app_supported()) { @@ -2835,6 +2840,7 @@ skip_domain: if (cmd_ctx->lsm->cmd_type == LTTNG_START_TRACE || cmd_ctx->lsm->cmd_type == LTTNG_STOP_TRACE) { switch (cmd_ctx->lsm->domain.type) { + case LTTNG_DOMAIN_JUL: case LTTNG_DOMAIN_UST: if (uatomic_read(&ust_consumerd_state) != CONSUMER_STARTED) { ret = LTTNG_ERR_NO_USTCONSUMERD; diff --git a/src/bin/lttng/commands/add_context.c b/src/bin/lttng/commands/add_context.c index 6286ed8a0..3cd00f3d3 100644 --- a/src/bin/lttng/commands/add_context.c +++ b/src/bin/lttng/commands/add_context.c @@ -368,7 +368,7 @@ static int add_context(char *session_name) } else if (opt_userspace) { dom.type = LTTNG_DOMAIN_UST; } else { - ERR("Please specify a tracer (-k/--kernel or -u/--userspace)"); + print_missing_domain(); ret = CMD_ERROR; goto error; } diff --git a/src/bin/lttng/commands/calibrate.c b/src/bin/lttng/commands/calibrate.c index 7014fdd58..092632cd7 100644 --- a/src/bin/lttng/commands/calibrate.c +++ b/src/bin/lttng/commands/calibrate.c @@ -128,7 +128,7 @@ static int calibrate_lttng(void) } else if (opt_userspace) { dom.type = LTTNG_DOMAIN_UST; } else { - ERR("Please specify a tracer (-k/--kernel or -u/--userspace)"); + print_missing_domain(); ret = CMD_ERROR; goto error; } diff --git a/src/bin/lttng/commands/disable_channels.c b/src/bin/lttng/commands/disable_channels.c index 50b132eeb..1aa3916ae 100644 --- a/src/bin/lttng/commands/disable_channels.c +++ b/src/bin/lttng/commands/disable_channels.c @@ -93,7 +93,7 @@ static int disable_channels(char *session_name) } else if (opt_userspace) { dom.type = LTTNG_DOMAIN_UST; } else { - ERR("Please specify a tracer (-k/--kernel or -u/--userspace)"); + print_missing_domain(); ret = CMD_ERROR; goto error; } @@ -116,7 +116,7 @@ static int disable_channels(char *session_name) warn = 1; } else { MSG("%s channel %s disabled for session %s", - opt_kernel ? "Kernel" : "UST", channel_name, session_name); + get_domain_str(dom.type), channel_name, session_name); } /* Next channel */ diff --git a/src/bin/lttng/commands/disable_events.c b/src/bin/lttng/commands/disable_events.c index f9dc3396b..e71234342 100644 --- a/src/bin/lttng/commands/disable_events.c +++ b/src/bin/lttng/commands/disable_events.c @@ -32,6 +32,7 @@ static char *opt_channel_name; static char *opt_session_name; static int opt_userspace; static int opt_disable_all; +static int opt_jul; #if 0 /* Not implemented yet */ static char *opt_cmd_name; @@ -52,6 +53,7 @@ static struct poptOption long_options[] = { {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0}, {"all-events", 'a', POPT_ARG_VAL, &opt_disable_all, 1, 0, 0}, {"channel", 'c', POPT_ARG_STRING, &opt_channel_name, 0, 0, 0}, + {"jul", 'j', POPT_ARG_VAL, &opt_jul, 1, 0, 0}, {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, #if 0 /* Not implemented yet */ @@ -79,6 +81,7 @@ static void usage(FILE *ofp) fprintf(ofp, " -a, --all-events Disable all tracepoints\n"); fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n"); fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n"); + fprintf(ofp, " -j, --jul Apply for Java application using JUL\n"); fprintf(ofp, "\n"); } @@ -112,8 +115,10 @@ static int disable_events(char *session_name) dom.type = LTTNG_DOMAIN_KERNEL; } else if (opt_userspace) { dom.type = LTTNG_DOMAIN_UST; + } else if (opt_jul) { + dom.type = LTTNG_DOMAIN_JUL; } else { - ERR("Please specify a tracer (-k/--kernel or -u/--userspace)"); + print_missing_domain(); ret = CMD_ERROR; goto error; } @@ -134,8 +139,7 @@ static int disable_events(char *session_name) } MSG("All %s events are disabled in channel %s", - opt_kernel ? "kernel" : "UST", - print_channel_name(channel_name)); + get_domain_str(dom.type), print_channel_name(channel_name)); goto end; } @@ -155,7 +159,7 @@ static int disable_events(char *session_name) warn = 1; } else { MSG("%s event %s disabled in channel %s for session %s", - opt_kernel ? "kernel" : "UST", event_name, + get_domain_str(dom.type), event_name, print_channel_name(channel_name), session_name); } diff --git a/src/bin/lttng/commands/enable_channels.c b/src/bin/lttng/commands/enable_channels.c index 10c1d3d57..18f8d020e 100644 --- a/src/bin/lttng/commands/enable_channels.c +++ b/src/bin/lttng/commands/enable_channels.c @@ -130,8 +130,8 @@ static void usage(FILE *ofp) DEFAULT_UST_PID_CHANNEL_OUTPUT == LTTNG_EVENT_MMAP ? output_mmap : output_splice, DEFAULT_KERNEL_CHANNEL_OUTPUT == LTTNG_EVENT_MMAP ? output_mmap : output_splice, DEFAULT_METADATA_OUTPUT == LTTNG_EVENT_MMAP ? output_mmap : output_splice); - fprintf(ofp, " --buffers-uid Use per UID buffer (-u only)\n"); - fprintf(ofp, " --buffers-pid Use per PID buffer (-u only)\n"); + fprintf(ofp, " --buffers-uid Use per UID buffer (-u/-j only)\n"); + fprintf(ofp, " --buffers-pid Use per PID buffer (-u/-j only)\n"); fprintf(ofp, " --buffers-global Use shared buffer for the whole system (-k only)\n"); fprintf(ofp, " -C, --tracefile-size SIZE\n"); fprintf(ofp, " Maximum size of each tracefile within a stream (in bytes). 0 means unlimited.\n"); @@ -213,7 +213,7 @@ static int enable_channel(char *session_name) dom.buf_type = LTTNG_BUFFER_PER_UID; } } else { - ERR("Please specify a tracer (-k/--kernel or -u/--userspace)"); + print_missing_domain(); ret = CMD_ERROR; goto error; } @@ -269,6 +269,7 @@ static int enable_channel(char *session_name) switch (-ret) { case LTTNG_ERR_KERN_CHAN_EXIST: case LTTNG_ERR_UST_CHAN_EXIST: + case LTTNG_ERR_CHAN_EXIST: WARN("Channel %s: %s (session %s)", channel_name, lttng_strerror(ret), session_name); goto error; @@ -280,8 +281,7 @@ static int enable_channel(char *session_name) warn = 1; } else { MSG("%s channel %s enabled for session %s", - opt_kernel ? "Kernel" : "UST", channel_name, - session_name); + get_domain_str(dom.type), channel_name, session_name); } /* Next event */ diff --git a/src/bin/lttng/commands/enable_events.c b/src/bin/lttng/commands/enable_events.c index 36ee84f39..a7b70c3f9 100644 --- a/src/bin/lttng/commands/enable_events.c +++ b/src/bin/lttng/commands/enable_events.c @@ -36,6 +36,7 @@ static int opt_loglevel_type; static int opt_kernel; static char *opt_session_name; static int opt_userspace; +static int opt_jul; static int opt_enable_all; static char *opt_probe; static char *opt_function; @@ -72,6 +73,7 @@ static struct poptOption long_options[] = { {"channel", 'c', POPT_ARG_STRING, &opt_channel_name, 0, 0, 0}, {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0}, + {"jul", 'j', POPT_ARG_VAL, &opt_jul, 1, 0, 0}, {"tracepoint", 0, POPT_ARG_NONE, 0, OPT_TRACEPOINT, 0, 0}, {"probe", 0, POPT_ARG_STRING, &opt_probe, OPT_PROBE, 0, 0}, {"function", 0, POPT_ARG_STRING, &opt_function, OPT_FUNCTION, 0, 0}, @@ -105,6 +107,7 @@ static void usage(FILE *ofp) fprintf(ofp, " -a, --all Enable all tracepoints and syscalls\n"); fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n"); fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n"); + fprintf(ofp, " -j, --jul Apply for Java application using JUL\n"); fprintf(ofp, "\n"); fprintf(ofp, "Event options:\n"); fprintf(ofp, " --tracepoint Tracepoint event (default)\n"); @@ -353,8 +356,12 @@ static int enable_events(char *session_name) dom.type = LTTNG_DOMAIN_UST; /* Default. */ dom.buf_type = LTTNG_BUFFER_PER_UID; + } else if (opt_jul) { + dom.type = LTTNG_DOMAIN_JUL; + /* Default. */ + dom.buf_type = LTTNG_BUFFER_PER_UID; } else { - ERR("Please specify a tracer (-k/--kernel or -u/--userspace)"); + print_missing_domain(); ret = CMD_ERROR; goto error; } @@ -414,12 +421,12 @@ static int enable_events(char *session_name) case LTTNG_EVENT_TRACEPOINT: if (opt_loglevel) { MSG("All %s tracepoints are enabled in channel %s for loglevel %s", - opt_kernel ? "kernel" : "UST", + get_domain_str(dom.type), print_channel_name(channel_name), opt_loglevel); } else { MSG("All %s tracepoints are enabled in channel %s", - opt_kernel ? "kernel" : "UST", + get_domain_str(dom.type), print_channel_name(channel_name)); } @@ -433,12 +440,12 @@ static int enable_events(char *session_name) case LTTNG_EVENT_ALL: if (opt_loglevel) { MSG("All %s events are enabled in channel %s for loglevel %s", - opt_kernel ? "kernel" : "UST", + get_domain_str(dom.type), print_channel_name(channel_name), opt_loglevel); } else { MSG("All %s events are enabled in channel %s", - opt_kernel ? "kernel" : "UST", + get_domain_str(dom.type), print_channel_name(channel_name)); } break; @@ -576,8 +583,18 @@ static int enable_events(char *session_name) } else { ev.loglevel = -1; } + } else if (opt_jul) { + if (opt_event_type != LTTNG_EVENT_ALL && + opt_event_type != LTTNG_EVENT_TRACEPOINT) { + ERR("Event type not supported for JUL domain."); + ret = CMD_UNSUPPORTED; + goto error; + } + ev.type = LTTNG_EVENT_TRACEPOINT; + strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN); + ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; } else { - ERR("Please specify a tracer (-k/--kernel or -u/--userspace)"); + print_missing_domain(); ret = CMD_ERROR; goto error; } @@ -604,7 +621,7 @@ static int enable_events(char *session_name) warn = 1; } else { MSG("%s event %s created in channel %s", - opt_kernel ? "kernel": "UST", event_name, + get_domain_str(dom.type), event_name, print_channel_name(channel_name)); } } diff --git a/src/bin/lttng/utils.c b/src/bin/lttng/utils.c index e40c3fd70..556728da2 100644 --- a/src/bin/lttng/utils.c +++ b/src/bin/lttng/utils.c @@ -16,6 +16,7 @@ */ #define _GNU_SOURCE +#include #include #include #include @@ -27,6 +28,10 @@ #include "utils.h" #include "command.h" +static const char *str_kernel = "Kernel"; +static const char *str_ust = "UST"; +static const char *str_jul = "JUL"; + /* * get_session_name * @@ -249,3 +254,25 @@ int get_count_order_ulong(unsigned long x) return fls_ulong(x - 1); } + +const char *get_domain_str(enum lttng_domain_type domain) +{ + const char *str_dom; + + switch (domain) { + case LTTNG_DOMAIN_KERNEL: + str_dom = str_kernel; + break; + case LTTNG_DOMAIN_UST: + str_dom = str_ust; + break; + case LTTNG_DOMAIN_JUL: + str_dom = str_jul; + break; + default: + /* Should not have an unknown domain or else define it. */ + assert(0); + } + + return str_dom; +} diff --git a/src/bin/lttng/utils.h b/src/bin/lttng/utils.h index fb973caa5..9dacbb20f 100644 --- a/src/bin/lttng/utils.h +++ b/src/bin/lttng/utils.h @@ -20,6 +20,8 @@ #include +#include + struct cmd_struct; char *get_session_name(void); @@ -44,4 +46,12 @@ int get_count_order_u64(uint64_t x); */ int get_count_order_ulong(unsigned long x); +const char *get_domain_str(enum lttng_domain_type domain); + +static inline +void print_missing_domain(void) +{ + ERR("Please specify a domain (-k/-u/-j)."); +} + #endif /* _LTTNG_UTILS_H */ diff --git a/src/common/error.c b/src/common/error.c index 911baea3e..2733d0d11 100644 --- a/src/common/error.c +++ b/src/common/error.c @@ -113,6 +113,7 @@ static const char *error_string_array[] = { [ ERROR_INDEX(LTTNG_ERR_SNAPSHOT_OUTPUT_EXIST) ] = "Snapshot output already exists", [ ERROR_INDEX(LTTNG_ERR_START_SESSION_ONCE) ] = "Session needs to be started once", [ ERROR_INDEX(LTTNG_ERR_SNAPSHOT_FAIL) ] = "Snapshot record failed", + [ ERROR_INDEX(LTTNG_ERR_CHAN_EXIST) ] = "Channel already exists", /* Last element */ [ ERROR_INDEX(LTTNG_ERR_NR) ] = "Unknown error code" diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index 540e24590..83a46a45d 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -103,6 +103,7 @@ void lttng_ctl_copy_lttng_domain(struct lttng_domain *dst, switch (src->type) { case LTTNG_DOMAIN_KERNEL: case LTTNG_DOMAIN_UST: + case LTTNG_DOMAIN_JUL: memcpy(dst, src, sizeof(struct lttng_domain)); break; default: -- 2.34.1