X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng%2Fcommands%2Fadd_context.c;h=d9121b02a8a53783195507a651d4446210160aea;hb=d68c9a04537b683991a7355b812b0af954008cf1;hp=2f43dc7ff203e53a411d7178e649d80dd590d824;hpb=62a7b8edf965b89d3ca57da120dcedfcf36dfe02;p=lttng-tools.git diff --git a/src/bin/lttng/commands/add_context.c b/src/bin/lttng/commands/add_context.c index 2f43dc7ff..d9121b02a 100644 --- a/src/bin/lttng/commands/add_context.c +++ b/src/bin/lttng/commands/add_context.c @@ -41,6 +41,12 @@ static int opt_jul; static int opt_log4j; static char *opt_type; +#ifdef LTTNG_EMBED_HELP +static const char help_msg[] = +#include +; +#endif + enum { OPT_HELP = 1, OPT_TYPE, @@ -87,6 +93,7 @@ enum perf_type { PERF_TYPE_HARDWARE = 0, PERF_TYPE_SOFTWARE = 1, PERF_TYPE_HW_CACHE = 3, + PERF_TYPE_RAW = 4, }; enum perf_count_hard { @@ -661,7 +668,9 @@ void destroy_ctx_type(struct ctx_type *type) if (!type) { return; } - free(type->opt->symbol); + if (type->opt) { + free(type->opt->symbol); + } free(type->opt); free(type); } @@ -687,10 +696,101 @@ end: return type; } +static +int find_ctx_type_perf_raw(const char *ctx, struct ctx_type *type) +{ + int ret; + int field_pos = 0; + char *tmp_list, *cur_list; + + cur_list = tmp_list = strdup(ctx); + if (!tmp_list) { + PERROR("strdup temp list"); + ret = -ENOMEM; + goto end; + } + + /* Looking for "perf:[cpu|thread]:raw::". */ + for (;;) { + char *next; + + next = strtok(cur_list, ":"); + if (!next) { + break; + } + cur_list = NULL; + switch (field_pos) { + case 0: + if (strncmp(next, "perf", 4) != 0) { + ret = -1; + goto end; + } + break; + case 1: + if (strncmp(next, "cpu", 3) == 0) { + type->opt->ctx_type = CONTEXT_PERF_CPU_COUNTER; + } else if (strncmp(next, "thread", 4) == 0) { + type->opt->ctx_type = CONTEXT_PERF_THREAD_COUNTER; + } else { + ret = -1; + goto end; + } + break; + case 2: + if (strncmp(next, "raw", 3) != 0) { + ret = -1; + goto end; + } + break; + case 3: + { + char *endptr; + + if (strlen(next) < 2 || next[0] != 'r') { + ERR("Wrong perf raw mask format: expected rNNN"); + ret = -1; + goto end; + } + errno = 0; + type->opt->u.perf.config = strtoll(next + 1, &endptr, 16); + if (errno != 0 || !endptr || *endptr) { + ERR("Wrong perf raw mask format: expected rNNN"); + ret = -1; + goto end; + } + break; + } + case 4: + /* name */ + break; + case 5: + ERR("Too many ':' in perf raw format"); + ret = -1; + goto end; + }; + field_pos++; + } + + if (field_pos < 5) { + ERR("Invalid perf counter specifier, expected a specifier of " + "the form perf:cpu:raw:rNNN: or " + "perf:thread:raw:rNNN:"); + ret = -1; + goto end; + } + + ret = 0; + goto end; + +end: + free(tmp_list); + return ret; +} + static struct ctx_type *get_context_type(const char *ctx) { - int opt_index; + int opt_index, ret; struct ctx_type *type = NULL; const char app_ctx_prefix[] = "$app."; char *provider_name = NULL, *ctx_name = NULL; @@ -713,6 +813,18 @@ struct ctx_type *get_context_type(const char *ctx) goto found; } + /* Check if ctx is a raw perf context. */ + ret = find_ctx_type_perf_raw(ctx, type); + if (ret == 0) { + type->opt->u.perf.type = PERF_TYPE_RAW; + type->opt->symbol = strdup(ctx); + if (!type->opt->symbol) { + PERROR("Copy perf field name"); + goto not_found; + } + goto found; + } + /* * No match found against static contexts; check if it is an app * context. @@ -786,6 +898,7 @@ int cmd_add_context(int argc, const char **argv) static poptContext pc; struct ctx_type *type, *tmptype; char *session_name = NULL; + const char *leftover = NULL; if (argc < 2) { ret = CMD_ERROR; @@ -832,6 +945,13 @@ int cmd_add_context(int argc, const char **argv) } } + leftover = poptGetArg(pc); + if (leftover) { + ERR("Unknown argument: %s", leftover); + ret = CMD_ERROR; + goto end; + } + ret = print_missing_or_multiple_domains(opt_kernel + opt_userspace + opt_jul + opt_log4j); if (ret) {