X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=lttng%2Fcommands%2Fadd_context.c;h=edc8f37ac3724a488b1935c48ad4ff60eb892156;hb=6e2d116c6138874c0357b1afb1db5aa7cd80ceb6;hp=afec9dab73ee469c754f53d2dd6734ec2401125d;hpb=d65106b1011efccf8fa5f9d7c8f2dfb0de38f5e8;p=lttng-tools.git diff --git a/lttng/commands/add_context.c b/lttng/commands/add_context.c index afec9dab7..edc8f37ac 100644 --- a/lttng/commands/add_context.c +++ b/lttng/commands/add_context.c @@ -3,8 +3,8 @@ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. + * as published by the Free Software Foundation; only version 2 + * of the License. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -25,17 +25,17 @@ #include #include -#include "cmd.h" -#include "conf.h" -#include "utils.h" +#include "../cmd.h" +#include "../conf.h" +#include "../utils.h" static char *opt_event_name; static char *opt_channel_name; static char *opt_perf_name; +static char *opt_session_name; static int *opt_kernel; static int opt_pid_all; static int opt_userspace; -static int opt_ctx_type; static int opt_perf_type; static int opt_perf_id; static pid_t opt_pid; @@ -48,6 +48,7 @@ enum { static struct poptOption long_options[] = { /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */ {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0}, + {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0}, {"channel", 'c', POPT_ARG_STRING, &opt_channel_name, 0, 0, 0}, {"event", 'e', POPT_ARG_STRING, &opt_event_name, 0, 0, 0}, {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0}, @@ -70,6 +71,7 @@ static void usage(FILE *ofp) fprintf(ofp, "\n"); fprintf(ofp, "Options:\n"); fprintf(ofp, " -h, --help Show this help\n"); + fprintf(ofp, " -s, --session Apply on session name\n"); fprintf(ofp, " -c, --channel NAME Apply on channel\n"); fprintf(ofp, " -e, --event NAME Apply on event\n"); fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n"); @@ -118,18 +120,19 @@ static void usage(FILE *ofp) * * Add context to channel or event. */ -static int add_context(void) +static int add_context(int type) { int ret = CMD_SUCCESS; - struct lttng_kernel_context context; + struct lttng_event_context context; + struct lttng_domain dom; - if (set_session_name() < 0) { + if (set_session_name(opt_session_name) < 0) { ret = CMD_ERROR; goto error; } - context.ctx = opt_ctx_type; - if (opt_ctx_type == LTTNG_KERNEL_CONTEXT_PERF_COUNTER) { + context.ctx = type; + if (type == LTTNG_KERNEL_CONTEXT_PERF_COUNTER) { context.u.perf_counter.type = opt_perf_type; context.u.perf_counter.config = opt_perf_id; strncpy(context.u.perf_counter.name, opt_perf_name, @@ -137,8 +140,12 @@ static int add_context(void) } if (opt_kernel) { - DBG("Adding kernel context\n"); - ret = lttng_kernel_add_context(&context, opt_event_name, opt_channel_name); + /* Create kernel domain */ + dom.type = LTTNG_DOMAIN_KERNEL; + + DBG("Adding kernel context"); + ret = lttng_add_context(&dom, &context, opt_event_name, + opt_channel_name); if (ret < 0) { goto error; } else { @@ -169,10 +176,15 @@ error: */ int cmd_add_context(int argc, const char **argv) { - int opt, ret; + int opt, ret = CMD_SUCCESS; char *tmp; static poptContext pc; + if (argc < 2) { + usage(stderr); + goto end; + } + pc = poptGetContext(NULL, argc, argv, long_options, 0); poptReadDefaultConfig(pc, 0); @@ -188,9 +200,15 @@ int cmd_add_context(int argc, const char **argv) if (tmp == NULL) { usage(stderr); ret = CMD_ERROR; + free(tmp); goto end; } - opt_ctx_type = atoi(tmp); + ret = add_context(atoi(tmp)); + if (ret < 0) { + free(tmp); + goto end; + } + free(tmp); break; default: usage(stderr); @@ -199,8 +217,6 @@ int cmd_add_context(int argc, const char **argv) } } - ret = add_context(); - end: return ret; }