Change lttng API to use a lttng_handle
[lttng-tools.git] / 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
6e2d116c
DG
28#include "../cmd.h"
29#include "../conf.h"
30#include "../utils.h"
e953ef25
DG
31
32static char *opt_event_list;
33static char *opt_kernel;
34static char *opt_cmd_name;
35static char *opt_channel_name;
5440dc42 36static char *opt_session_name;
e953ef25
DG
37static int opt_pid_all;
38static int opt_userspace;
39static int opt_disable_all;
40static pid_t opt_pid;
41
42enum {
43 OPT_HELP = 1,
44 OPT_USERSPACE,
45};
46
cd80958d
DG
47static struct lttng_handle *handle;
48
e953ef25
DG
49static struct poptOption long_options[] = {
50 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
51 {"help", 'h', POPT_ARG_NONE, 0, OPT_HELP, 0, 0},
5440dc42 52 {"session", 's', POPT_ARG_STRING, &opt_session_name, 0, 0, 0},
e953ef25
DG
53 {"all-events", 'a', POPT_ARG_VAL, &opt_disable_all, 1, 0, 0},
54 {"channel", 'c', POPT_ARG_STRING, &opt_channel_name, 0, 0, 0},
55 {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
56 {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, 0, OPT_USERSPACE, 0, 0},
57 {"all", 0, POPT_ARG_VAL, &opt_pid_all, 1, 0, 0},
58 {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
59 {0, 0, 0, 0, 0, 0, 0}
60};
61
62/*
63 * usage
64 */
65static void usage(FILE *ofp)
66{
67 fprintf(ofp, "usage: lttng disable-event NAME[,NAME2,...] [options]\n");
68 fprintf(ofp, "\n");
69 fprintf(ofp, " -h, --help Show this help\n");
5440dc42 70 fprintf(ofp, " -s, --session Apply on session name\n");
e953ef25
DG
71 fprintf(ofp, " -c, --channel Apply on this channel\n");
72 fprintf(ofp, " -a, --all-events Enable all tracepoints\n");
73 fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n");
74 fprintf(ofp, " -u, --userspace [CMD] Apply for the user-space tracer\n");
75 fprintf(ofp, " --all If -u, apply on all traceable apps\n");
76 fprintf(ofp, " -p, --pid PID If -u, apply on a specific PID\n");
77 fprintf(ofp, "\n");
78}
79
80/*
81 * disable_events
82 *
83 * Disabling event using the lttng API.
84 */
cd80958d 85static int disable_events(char *session_name)
e953ef25
DG
86{
87 int err, ret = CMD_SUCCESS;
b73d0b29 88 char *event_name, *channel_name = NULL;
e953ef25 89 struct lttng_event ev;
7d29a247 90 struct lttng_domain dom;
e953ef25 91
e953ef25
DG
92 if (opt_channel_name == NULL) {
93 err = asprintf(&channel_name, DEFAULT_CHANNEL_NAME);
94 if (err < 0) {
95 ret = CMD_FATAL;
96 goto error;
97 }
98 } else {
99 channel_name = opt_channel_name;
100 }
101
7d29a247
DG
102 if (opt_kernel) {
103 dom.type = LTTNG_DOMAIN_KERNEL;
104 }
105
cd80958d
DG
106 handle = lttng_create_handle(session_name, &dom);
107 if (handle == NULL) {
108 ret = -1;
109 goto error;
110 }
111
e953ef25
DG
112 if (opt_disable_all) {
113 if (opt_kernel) {
cd80958d 114 ret = lttng_disable_event(handle, NULL, channel_name);
e953ef25
DG
115 goto error;
116 }
117
118 /* TODO: User-space tracer */
119 }
120
121 /* Strip event list */
122 event_name = strtok(opt_event_list, ",");
123 while (event_name != NULL) {
124 /* Kernel tracer action */
125 if (opt_kernel) {
126 DBG("Disabling kernel event %s for channel %s",
127 event_name, channel_name);
128
129 /* Copy name and type of the event */
130 strncpy(ev.name, event_name, LTTNG_SYMBOL_NAME_LEN);
99497cd0 131 ev.name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
cd80958d 132 ret = lttng_disable_event(handle, event_name, channel_name);
e953ef25
DG
133 if (ret < 0) {
134 MSG("Unable to disable event %s for channel %s",
135 event_name, channel_name);
136 } else {
137 MSG("Kernel event %s disabled for channel %s",
138 event_name, channel_name);
139 }
140 } else if (opt_userspace) { /* User-space tracer action */
141 /*
142 * TODO: Waiting on lttng UST 2.0
143 */
144 if (opt_pid_all) {
145 } else if (opt_pid != 0) {
146 }
147 ret = CMD_NOT_IMPLEMENTED;
148 goto error;
149 } else {
048e2159 150 ERR("Please specify a tracer (--kernel or --userspace)");
e953ef25
DG
151 goto error;
152 }
153
154 /* Next event */
155 event_name = strtok(NULL, ",");
156 }
157
158error:
b73d0b29
MD
159 if (opt_channel_name == NULL) {
160 free(channel_name);
161 }
cd80958d
DG
162 lttng_destroy_handle(handle);
163
e953ef25
DG
164 return ret;
165}
166
167/*
168 * cmd_disable_events
169 *
170 * Disable event to trace session
171 */
172int cmd_disable_events(int argc, const char **argv)
173{
174 int opt, ret;
175 static poptContext pc;
cd80958d 176 char *session_name = NULL;
e953ef25
DG
177
178 pc = poptGetContext(NULL, argc, argv, long_options, 0);
179 poptReadDefaultConfig(pc, 0);
180
181 while ((opt = poptGetNextOpt(pc)) != -1) {
182 switch (opt) {
183 case OPT_HELP:
184 usage(stderr);
185 ret = CMD_SUCCESS;
186 goto end;
187 case OPT_USERSPACE:
188 opt_userspace = 1;
189 opt_cmd_name = poptGetOptArg(pc);
190 break;
191 default:
192 usage(stderr);
193 ret = CMD_UNDEFINED;
194 goto end;
195 }
196 }
197
198 opt_event_list = (char*) poptGetArg(pc);
199 if (opt_event_list == NULL && opt_disable_all == 0) {
200 ERR("Missing event name(s).\n");
201 usage(stderr);
202 ret = CMD_SUCCESS;
203 goto end;
204 }
205
cd80958d
DG
206 if (!opt_session_name) {
207 session_name = get_session_name();
208 if (session_name == NULL) {
209 ret = -1;
210 goto end;
211 }
212 } else {
213 session_name = opt_session_name;
214 }
215
216 ret = disable_events(session_name);
e953ef25
DG
217
218end:
219 return ret;
220}
This page took 0.032851 seconds and 5 git commands to generate.