Add -j/--jul to lttng UI and ABI
[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 *
d14d33bf
AM
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2 only,
6 * as published by the Free Software Foundation.
e953ef25
DG
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
d14d33bf
AM
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
e953ef25
DG
16 */
17
18#define _GNU_SOURCE
19#include <popt.h>
20#include <stdio.h>
21#include <stdlib.h>
22#include <string.h>
23#include <sys/stat.h>
24#include <sys/types.h>
25#include <unistd.h>
26
c399183f 27#include "../command.h"
e953ef25
DG
28
29static char *opt_event_list;
9730260e 30static int opt_kernel;
e953ef25 31static char *opt_channel_name;
5440dc42 32static char *opt_session_name;
e953ef25
DG
33static int opt_userspace;
34static int opt_disable_all;
b9dfb167 35static int opt_jul;
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},
b9dfb167 56 {"jul", 'j', POPT_ARG_VAL, &opt_jul, 1, 0, 0},
e953ef25 57 {"kernel", 'k', POPT_ARG_VAL, &opt_kernel, 1, 0, 0},
d78d6610
DG
58#if 0
59 /* Not implemented yet */
6caa2bcc 60 {"userspace", 'u', POPT_ARG_STRING | POPT_ARGFLAG_OPTIONAL, &opt_cmd_name, OPT_USERSPACE, 0, 0},
e953ef25 61 {"pid", 'p', POPT_ARG_INT, &opt_pid, 0, 0, 0},
d78d6610
DG
62#else
63 {"userspace", 'u', POPT_ARG_NONE, 0, OPT_USERSPACE, 0, 0},
64#endif
679b4943 65 {"list-options", 0, POPT_ARG_NONE, NULL, OPT_LIST_OPTIONS, NULL, NULL},
e953ef25
DG
66 {0, 0, 0, 0, 0, 0, 0}
67};
68
69/*
70 * usage
71 */
72static void usage(FILE *ofp)
73{
c138a39b 74 fprintf(ofp, "usage: lttng disable-event NAME[,NAME2,...] (-k | -u) [OPTIONS]\n");
e953ef25 75 fprintf(ofp, "\n");
32a6298d 76 fprintf(ofp, "Options:\n");
e953ef25 77 fprintf(ofp, " -h, --help Show this help\n");
679b4943 78 fprintf(ofp, " --list-options Simple listing of options\n");
32a6298d
DG
79 fprintf(ofp, " -s, --session NAME Apply to session name\n");
80 fprintf(ofp, " -c, --channel NAME Apply to this channel\n");
9730260e 81 fprintf(ofp, " -a, --all-events Disable all tracepoints\n");
e953ef25 82 fprintf(ofp, " -k, --kernel Apply for the kernel tracer\n");
27221701 83 fprintf(ofp, " -u, --userspace Apply to the user-space tracer\n");
b9dfb167 84 fprintf(ofp, " -j, --jul Apply for Java application using JUL\n");
e953ef25
DG
85 fprintf(ofp, "\n");
86}
87
85076754
MD
88static
89const char *print_channel_name(const char *name)
90{
91 return name ? : DEFAULT_CHANNEL_NAME;
92}
93
94static
95const char *print_raw_channel_name(const char *name)
96{
97 return name ? : "<default>";
98}
99
e953ef25
DG
100/*
101 * disable_events
102 *
103 * Disabling event using the lttng API.
104 */
cd80958d 105static int disable_events(char *session_name)
e953ef25 106{
85076754 107 int ret = CMD_SUCCESS, warn = 0;
b73d0b29 108 char *event_name, *channel_name = NULL;
7d29a247 109 struct lttng_domain dom;
e953ef25 110
441c16a7
MD
111 memset(&dom, 0, sizeof(dom));
112
d78d6610 113 /* Create lttng domain */
7d29a247
DG
114 if (opt_kernel) {
115 dom.type = LTTNG_DOMAIN_KERNEL;
d78d6610 116 } else if (opt_userspace) {
9730260e 117 dom.type = LTTNG_DOMAIN_UST;
b9dfb167
DG
118 } else if (opt_jul) {
119 dom.type = LTTNG_DOMAIN_JUL;
9730260e 120 } else {
b9dfb167 121 print_missing_domain();
d16c1a4c 122 ret = CMD_ERROR;
9730260e 123 goto error;
7d29a247
DG
124 }
125
85076754 126 channel_name = opt_channel_name;
ae856491 127
cd80958d
DG
128 handle = lttng_create_handle(session_name, &dom);
129 if (handle == NULL) {
130 ret = -1;
131 goto error;
132 }
133
e953ef25 134 if (opt_disable_all) {
9730260e
DG
135 ret = lttng_disable_event(handle, NULL, channel_name);
136 if (ret < 0) {
60e835ca 137 ERR("%s", lttng_strerror(ret));
e953ef25
DG
138 goto error;
139 }
140
9730260e 141 MSG("All %s events are disabled in channel %s",
b9dfb167 142 get_domain_str(dom.type), print_channel_name(channel_name));
9730260e 143 goto end;
e953ef25
DG
144 }
145
146 /* Strip event list */
147 event_name = strtok(opt_event_list, ",");
148 while (event_name != NULL) {
ae856491 149 DBG("Disabling event %s", event_name);
e953ef25 150
9730260e
DG
151 ret = lttng_disable_event(handle, event_name, channel_name);
152 if (ret < 0) {
ae856491 153 ERR("Event %s: %s (channel %s, session %s)", event_name,
85076754
MD
154 lttng_strerror(ret),
155 ret == -LTTNG_ERR_NEED_CHANNEL_NAME
156 ? print_raw_channel_name(channel_name)
157 : print_channel_name(channel_name),
158 session_name);
ae856491 159 warn = 1;
9730260e 160 } else {
ae856491 161 MSG("%s event %s disabled in channel %s for session %s",
b9dfb167 162 get_domain_str(dom.type), event_name,
85076754 163 print_channel_name(channel_name),
ae856491 164 session_name);
9730260e
DG
165 }
166
e953ef25
DG
167 /* Next event */
168 event_name = strtok(NULL, ",");
169 }
170
ae856491
DG
171 ret = CMD_SUCCESS;
172
9730260e 173end:
e953ef25 174error:
ae856491
DG
175 if (warn) {
176 ret = CMD_WARNING;
177 }
cd80958d
DG
178 lttng_destroy_handle(handle);
179
e953ef25
DG
180 return ret;
181}
182
183/*
184 * cmd_disable_events
185 *
186 * Disable event to trace session
187 */
188int cmd_disable_events(int argc, const char **argv)
189{
ca1c3607 190 int opt, ret = CMD_SUCCESS;
e953ef25 191 static poptContext pc;
cd80958d 192 char *session_name = NULL;
e953ef25
DG
193
194 pc = poptGetContext(NULL, argc, argv, long_options, 0);
195 poptReadDefaultConfig(pc, 0);
196
197 while ((opt = poptGetNextOpt(pc)) != -1) {
198 switch (opt) {
199 case OPT_HELP:
ca1c3607 200 usage(stdout);
e953ef25
DG
201 goto end;
202 case OPT_USERSPACE:
203 opt_userspace = 1;
e953ef25 204 break;
679b4943
SM
205 case OPT_LIST_OPTIONS:
206 list_cmd_options(stdout, long_options);
679b4943 207 goto end;
e953ef25
DG
208 default:
209 usage(stderr);
210 ret = CMD_UNDEFINED;
211 goto end;
212 }
213 }
214
215 opt_event_list = (char*) poptGetArg(pc);
216 if (opt_event_list == NULL && opt_disable_all == 0) {
217 ERR("Missing event name(s).\n");
218 usage(stderr);
ca1c3607 219 ret = CMD_ERROR;
e953ef25
DG
220 goto end;
221 }
222
cd80958d
DG
223 if (!opt_session_name) {
224 session_name = get_session_name();
225 if (session_name == NULL) {
ca1c3607 226 ret = CMD_ERROR;
cd80958d
DG
227 goto end;
228 }
229 } else {
230 session_name = opt_session_name;
231 }
232
233 ret = disable_events(session_name);
e953ef25
DG
234
235end:
5853fd43
DG
236 if (!opt_session_name && session_name) {
237 free(session_name);
238 }
ca1c3607 239 poptFreeContext(pc);
e953ef25
DG
240 return ret;
241}
This page took 0.04344 seconds and 4 git commands to generate.