Loglevel fixes
[lttng-tools.git] / src / bin / lttng / commands / disable_events.c
CommitLineData
e953ef25
DG
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
82a3637f
DG
6 * as published by the Free Software Foundation; only version 2
7 * of the License.
e953ef25
DG
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
c399183f 28#include "../command.h"
e953ef25
DG
29
30static char *opt_event_list;
9730260e 31static int opt_kernel;
e953ef25 32static char *opt_channel_name;
5440dc42 33static char *opt_session_name;
e953ef25
DG
34static int opt_userspace;
35static int opt_disable_all;
d78d6610
DG
36#if 0
37/* Not implemented yet */
38static char *opt_cmd_name;
e953ef25 39static pid_t opt_pid;
d78d6610 40#endif
e953ef25
DG
41
42enum {
43 OPT_HELP = 1,
44 OPT_USERSPACE,
679b4943 45 OPT_LIST_OPTIONS,
e953ef25
DG
46};
47
cd80958d
DG
48static struct lttng_handle *handle;
49
e953ef25
DG
50static struct poptOption long_options[] = {
51 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
52 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
5440dc42 53 {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0},
e953ef25
DG
54 {"all-events", 'a', POPT_ARG_VAL, &opt_disable_all, 1, 0, 0},
55 {"channel", 'c', POPT_ARG_STRING, &opt_channel_name, 0, 0, 0},
56 {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
d78d6610
DG
57#if 0
58 /* Not implemented yet */
6caa2bcc 59 {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0},
e953ef25 60 {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
d78d6610
DG
61#else
62 {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
63#endif
679b4943 64 {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
e953ef25
DG
65 {0, 0, 0, 0, 0, 0, 0}
66};
67
68/*
69 * usage
70 */
71static void usage(FILE *ofp)
72{
73 fprintf(ofp, "usage: lttng disable-event NAME[,NAME2,...] [options]\n");
74 fprintf(ofp, "\n");
75 fprintf(ofp, " -h, --help Show this help\n");
679b4943 76 fprintf(ofp, " --list-options Simple listing of options\n");
27221701
DG
77 fprintf(ofp, " -s, --session Apply to session name\n");
78 fprintf(ofp, " -c, --channel Apply to this channel\n");
9730260e 79 fprintf(ofp, " -a, --all-events Disable all tracepoints\n");
e953ef25 80 fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n");
d78d6610 81#if 0
27221701 82 fprintf(ofp, " -u, --userspace [CMD] Apply to the user-space tracer\n");
e14f64a8
DG
83 fprintf(ofp, " If no CMD, the domain used is UST global\n");
84 fprintf(ofp, " or else the domain is UST EXEC_NAME\n");
85 fprintf(ofp, " -p, --pid PID If -u, apply to specific PID (domain: UST PID)\n");
d78d6610 86#else
27221701 87 fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n");
d78d6610 88#endif
e953ef25
DG
89 fprintf(ofp, "\n");
90}
91
92/*
93 * disable_events
94 *
95 * Disabling event using the lttng API.
96 */
cd80958d 97static int disable_events(char *session_name)
e953ef25 98{
ae856491 99 int err, ret = CMD_SUCCESS, warn = 0;
b73d0b29 100 char *event_name, *channel_name = NULL;
7d29a247 101 struct lttng_domain dom;
e953ef25 102
d78d6610 103 /* Create lttng domain */
7d29a247
DG
104 if (opt_kernel) {
105 dom.type = LTTNG_DOMAIN_KERNEL;
d78d6610 106 } else if (opt_userspace) {
9730260e 107 dom.type = LTTNG_DOMAIN_UST;
9730260e 108 } else {
e14f64a8 109 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
d16c1a4c 110 ret = CMD_ERROR;
9730260e 111 goto error;
7d29a247
DG
112 }
113
ae856491
DG
114 /* Get channel name */
115 if (opt_channel_name == NULL) {
116 err = asprintf(&channel_name, DEFAULT_CHANNEL_NAME);
117 if (err < 0) {
118 ret = CMD_FATAL;
119 goto error;
120 }
121 } else {
122 channel_name = opt_channel_name;
123 }
124
cd80958d
DG
125 handle = lttng_create_handle(session_name, &dom);
126 if (handle == NULL) {
127 ret = -1;
128 goto error;
129 }
130
e953ef25 131 if (opt_disable_all) {
9730260e
DG
132 ret = lttng_disable_event(handle, NULL, channel_name);
133 if (ret < 0) {
ae856491 134 /* Don't set ret so lttng can interpret the sessiond error. */
e953ef25
DG
135 goto error;
136 }
137
9730260e
DG
138 MSG("All %s events are disabled in channel %s",
139 opt_kernel ? "kernel" : "UST", channel_name);
140 goto end;
e953ef25
DG
141 }
142
143 /* Strip event list */
144 event_name = strtok(opt_event_list, ",");
145 while (event_name != NULL) {
ae856491 146 DBG("Disabling event %s", event_name);
e953ef25 147
9730260e
DG
148 ret = lttng_disable_event(handle, event_name, channel_name);
149 if (ret < 0) {
ae856491
DG
150 ERR("Event %s: %s (channel %s, session %s)", event_name,
151 lttng_strerror(ret), channel_name, session_name);
152 warn = 1;
9730260e 153 } else {
ae856491
DG
154 MSG("%s event %s disabled in channel %s for session %s",
155 opt_kernel ? "kernel" : "UST", event_name, channel_name,
156 session_name);
9730260e
DG
157 }
158
e953ef25
DG
159 /* Next event */
160 event_name = strtok(NULL, ",");
161 }
162
ae856491
DG
163 ret = CMD_SUCCESS;
164
9730260e 165end:
e953ef25 166error:
ae856491
DG
167 if (warn) {
168 ret = CMD_WARNING;
169 }
b73d0b29
MD
170 if (opt_channel_name == NULL) {
171 free(channel_name);
172 }
cd80958d
DG
173 lttng_destroy_handle(handle);
174
e953ef25
DG
175 return ret;
176}
177
178/*
179 * cmd_disable_events
180 *
181 * Disable event to trace session
182 */
183int cmd_disable_events(int argc, const char **argv)
184{
ca1c3607 185 int opt, ret = CMD_SUCCESS;
e953ef25 186 static poptContext pc;
cd80958d 187 char *session_name = NULL;
e953ef25
DG
188
189 pc = poptGetContext(NULL, argc, argv, long_options, 0);
190 poptReadDefaultConfig(pc, 0);
191
192 while ((opt = poptGetNextOpt(pc)) != -1) {
193 switch (opt) {
194 case OPT_HELP:
ca1c3607 195 usage(stdout);
e953ef25
DG
196 goto end;
197 case OPT_USERSPACE:
198 opt_userspace = 1;
e953ef25 199 break;
679b4943
SM
200 case OPT_LIST_OPTIONS:
201 list_cmd_options(stdout, long_options);
679b4943 202 goto end;
e953ef25
DG
203 default:
204 usage(stderr);
205 ret = CMD_UNDEFINED;
206 goto end;
207 }
208 }
209
210 opt_event_list = (char*) poptGetArg(pc);
211 if (opt_event_list == NULL && opt_disable_all == 0) {
212 ERR("Missing event name(s).\n");
213 usage(stderr);
ca1c3607 214 ret = CMD_ERROR;
e953ef25
DG
215 goto end;
216 }
217
cd80958d
DG
218 if (!opt_session_name) {
219 session_name = get_session_name();
220 if (session_name == NULL) {
ca1c3607 221 ret = CMD_ERROR;
cd80958d
DG
222 goto end;
223 }
224 } else {
225 session_name = opt_session_name;
226 }
227
228 ret = disable_events(session_name);
e953ef25
DG
229
230end:
5853fd43
DG
231 if (!opt_session_name && session_name) {
232 free(session_name);
233 }
ca1c3607 234 poptFreeContext(pc);
e953ef25
DG
235 return ret;
236}
This page took 0.036553 seconds and 4 git commands to generate.