X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fenable_events.c;h=6a536976636e6d4f5729ccc9333f6ec066da4b48;hp=356fef4a0732c394b188f363c24ea0a8f990bd2f;hb=502bbe892dc4cc5e105293cc774942a13170c098;hpb=1940b29e34a4e77db05fbee32fbcc1118e6e8215 diff --git a/src/bin/lttng/commands/enable_events.c b/src/bin/lttng/commands/enable_events.c index 356fef4a0..6a5369766 100644 --- a/src/bin/lttng/commands/enable_events.c +++ b/src/bin/lttng/commands/enable_events.c @@ -15,13 +15,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#define _GNU_SOURCE #define _LGPL_SOURCE #include #include #include #include -#include #include #include #include @@ -29,6 +27,7 @@ #include #include +#include /* Mi dependancy */ #include @@ -101,7 +100,7 @@ static struct poptOption long_options[] = { */ static void usage(FILE *ofp) { - fprintf(ofp, "usage: lttng enable-event NAME[,NAME2,...] [-k|-u] [OPTIONS] \n"); + fprintf(ofp, "usage: lttng enable-event NAME[,NAME2,...] (-k | -u | -j | -l | -p) [OPTIONS] \n"); fprintf(ofp, "\n"); fprintf(ofp, "Options:\n"); fprintf(ofp, " -h, --help Show this help\n"); @@ -109,9 +108,9 @@ static void usage(FILE *ofp) fprintf(ofp, " -s, --session NAME Apply to session name\n"); fprintf(ofp, " -c, --channel NAME Apply to this channel\n"); fprintf(ofp, " -a, --all Enable all tracepoints and syscalls\n"); - fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n"); + fprintf(ofp, " -k, --kernel Apply to 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, " -j, --jul Apply to Java application using JUL\n"); fprintf(ofp, " -l, --log4j Apply for Java application using LOG4j\n"); fprintf(ofp, " -p, --python Apply for Python application\n"); fprintf(ofp, "\n"); @@ -134,7 +133,7 @@ static void usage(FILE *ofp) fprintf(ofp, "\n"); fprintf(ofp, " --loglevel name\n"); fprintf(ofp, " Tracepoint loglevel range from 0 to loglevel.\n"); - fprintf(ofp, " For JUL/LOG4j domain, see the table below for the range values.\n"); + fprintf(ofp, " For JUL/LOG4j/Python domains, see the table below for the range values.\n"); fprintf(ofp, " --loglevel-only name\n"); fprintf(ofp, " Tracepoint loglevel (only this loglevel)\n"); fprintf(ofp, "\n"); @@ -626,9 +625,9 @@ int check_exclusion_subsets(const char *event_name, char **new_exclusion_list; /* Excluder is a proper subset of event */ - string = strndup(next_excluder, excluder_length); + string = lttng_strndup(next_excluder, excluder_length); if (!string) { - PERROR("strndup error"); + PERROR("lttng_strndup error"); goto error; } new_exclusion_list = realloc(exclusion_list, @@ -677,6 +676,24 @@ end: *exclusion_list_ptr = exclusion_list; return ret; } + +static void warn_on_truncated_exclusion_names(char **exclusion_list, + int exclusion_count, int *warn) +{ + size_t i = 0; + + for (i = 0; i < exclusion_count; ++i) { + const char *name = exclusion_list[i]; + size_t len = strlen(name); + + if (len >= LTTNG_SYMBOL_NAME_LEN) { + WARN("Event exclusion \"%s\" will be truncated", + name); + *warn = 1; + } + } +} + /* * Enabling event using the lttng API. * Note: in case of error only the last error code will be return. @@ -721,15 +738,26 @@ static int enable_events(char *session_name) /* Default. */ dom.buf_type = LTTNG_BUFFER_PER_UID; } else { - print_missing_domain(); - ret = CMD_ERROR; - goto error; + /* Checked by the caller. */ + assert(0); } - if (opt_kernel && opt_exclude) { - ERR("Event name exclusions are not yet implemented for kernel events"); - ret = CMD_ERROR; - goto error; + if (opt_exclude) { + switch (dom.type) { + case LTTNG_DOMAIN_KERNEL: + case LTTNG_DOMAIN_JUL: + case LTTNG_DOMAIN_LOG4J: + case LTTNG_DOMAIN_PYTHON: + ERR("Event name exclusions are not yet implemented for %s events", + get_domain_str(dom.type)); + ret = CMD_ERROR; + goto error; + case LTTNG_DOMAIN_UST: + /* Exclusions supported */ + break; + default: + assert(0); + } } channel_name = opt_channel_name; @@ -781,8 +809,10 @@ static int enable_events(char *session_name) assert(opt_userspace || opt_jul || opt_log4j || opt_python); if (opt_userspace) { ev.loglevel = -1; - } else if (opt_jul || opt_log4j) { + } else if (opt_jul) { ev.loglevel = LTTNG_LOGLEVEL_JUL_ALL; + } else if (opt_log4j) { + ev.loglevel = LTTNG_LOGLEVEL_LOG4J_ALL; } else if (opt_python) { ev.loglevel = LTTNG_LOGLEVEL_PYTHON_DEBUG; } @@ -796,6 +826,9 @@ static int enable_events(char *session_name) goto error; } ev.exclusion = 1; + + warn_on_truncated_exclusion_names(exclusion_list, + exclusion_count, &warn); } if (!opt_filter) { ret = lttng_enable_event_with_exclusions(handle, @@ -1088,6 +1121,9 @@ static int enable_events(char *session_name) if (ret == CMD_ERROR) { goto error; } + + warn_on_truncated_exclusion_names( + exclusion_list, exclusion_count, &warn); } ev.loglevel_type = opt_loglevel_type; @@ -1136,9 +1172,7 @@ static int enable_events(char *session_name) strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN); ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0'; } else { - print_missing_domain(); - ret = CMD_ERROR; - goto error; + assert(0); } if (!opt_filter) { @@ -1187,17 +1221,29 @@ static int enable_events(char *session_name) } error_holder = command_ret; } else { - /* So we don't print the default channel name for agent domain. */ - if (dom.type == LTTNG_DOMAIN_JUL || - dom.type == LTTNG_DOMAIN_LOG4J) { - MSG("%s event %s%s enabled.", - get_domain_str(dom.type), event_name, - exclusion_string); - } else { + switch (dom.type) { + case LTTNG_DOMAIN_KERNEL: + case LTTNG_DOMAIN_UST: MSG("%s event %s%s created in channel %s", - get_domain_str(dom.type), event_name, - exclusion_string, - print_channel_name(channel_name)); + get_domain_str(dom.type), + event_name, + exclusion_string, + print_channel_name(channel_name)); + break; + case LTTNG_DOMAIN_JUL: + case LTTNG_DOMAIN_LOG4J: + case LTTNG_DOMAIN_PYTHON: + /* + * Don't print the default channel + * name for agent domains. + */ + MSG("%s event %s%s enabled", + get_domain_str(dom.type), + event_name, + exclusion_string); + break; + default: + assert(0); } } free(exclusion_string); @@ -1405,6 +1451,13 @@ int cmd_enable_events(int argc, const char **argv) } } + ret = print_missing_or_multiple_domains( + opt_kernel + opt_userspace + opt_jul + opt_log4j + opt_python); + if (ret) { + ret = CMD_ERROR; + goto end; + } + /* Mi check */ if (lttng_opt_mi) { writer = mi_lttng_writer_create(fileno(stdout), lttng_opt_mi);