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