Add session name option to all command
[lttng-tools.git] / lttng / commands / enable_channels.c
... / ...
CommitLineData
1/*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#define _GNU_SOURCE
20#include <popt.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <sys/stat.h>
25#include <sys/types.h>
26#include <unistd.h>
27
28#include "cmd.h"
29#include "conf.h"
30#include "utils.h"
31
32static char *opt_channels;
33static char *opt_kernel;
34static char *opt_session_name;
35static int opt_pid_all;
36static int opt_userspace;
37static pid_t opt_pid;
38
39enum {
40 OPT_HELP = 1,
41 OPT_USERSPACE,
42};
43
44static struct poptOption long_options[] = {
45 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
46 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
47 {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0},
48 {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
49 {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
50 {"all", 0, POPT_ARG_VAL, &opt_pid_all, 1, 0, 0},
51 {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
52 {0, 0, 0, 0, 0, 0, 0}
53};
54
55/*
56 * usage
57 */
58static void usage(FILE *ofp)
59{
60 fprintf(ofp, "usage: lttng enable-channel NAME[,NAME2,...] [options]\n");
61 fprintf(ofp, "\n");
62 fprintf(ofp, " -h, --help Show this help\n");
63 fprintf(ofp, " -s, --session Apply on session name\n");
64 fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n");
65 fprintf(ofp, " -u, --userspace Apply for the user-space tracer\n");
66 fprintf(ofp, " --all If -u, apply on all traceable apps\n");
67 fprintf(ofp, " -p, --pid PID If -u, apply on a specific PID\n");
68 fprintf(ofp, "\n");
69}
70
71/*
72 * enable_channels
73 *
74 * Enabling channel using the lttng API.
75 */
76static int enable_channels(void)
77{
78 int ret = CMD_SUCCESS;
79 char *channel_name;
80
81 if (set_session_name(opt_session_name) < 0) {
82 ret = CMD_ERROR;
83 goto error;
84 }
85
86 /* Strip event list */
87 channel_name = strtok(opt_channels, ",");
88 while (channel_name != NULL) {
89 /* Kernel tracer action */
90 if (opt_kernel) {
91 DBG("Enabling kernel channel %s", channel_name);
92 ret = lttng_kernel_enable_channel(channel_name);
93 if (ret < 0) {
94 goto error;
95 } else {
96 MSG("Kernel channel enabled %s", channel_name);
97 }
98 } else if (opt_userspace) { /* User-space tracer action */
99 /*
100 * TODO: Waiting on lttng UST 2.0
101 */
102 if (opt_pid_all) {
103 } else if (opt_pid != 0) {
104 }
105 ret = CMD_NOT_IMPLEMENTED;
106 goto error;
107 } else {
108 ERR("Please specify a tracer (kernel or user-space)");
109 goto error;
110 }
111
112 /* Next event */
113 channel_name = strtok(NULL, ",");
114 }
115
116error:
117 return ret;
118}
119
120/*
121 * cmd_enable_channels
122 *
123 * Enable channel to trace session
124 */
125int cmd_enable_channels(int argc, const char **argv)
126{
127 int opt, ret;
128 static poptContext pc;
129
130 pc = poptGetContext(NULL, argc, argv, long_options, 0);
131 poptReadDefaultConfig(pc, 0);
132
133 while ((opt = poptGetNextOpt(pc)) != -1) {
134 switch (opt) {
135 case OPT_HELP:
136 usage(stderr);
137 ret = CMD_SUCCESS;
138 goto end;
139 case OPT_USERSPACE:
140 opt_userspace = 1;
141 break;
142 default:
143 usage(stderr);
144 ret = CMD_UNDEFINED;
145 goto end;
146 }
147 }
148
149 opt_channels = (char*) poptGetArg(pc);
150 if (opt_channels == NULL) {
151 ERR("Missing channel name(s).\n");
152 usage(stderr);
153 ret = CMD_SUCCESS;
154 goto end;
155 }
156
157 ret = enable_channels();
158
159end:
160 return ret;
161}
This page took 0.023267 seconds and 4 git commands to generate.