2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
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.
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.
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.
24 #include <sys/types.h>
27 #include "../command.h"
29 static char *opt_event_list
;
30 static int opt_kernel
;
31 static char *opt_channel_name
;
32 static char *opt_session_name
;
33 static int opt_userspace
;
34 static int opt_disable_all
;
37 /* Not implemented yet */
38 static char *opt_cmd_name
;
48 static struct lttng_handle
*handle
;
50 static struct poptOption long_options
[] = {
51 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
52 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
53 {"session", 's', POPT_ARG_STRING
, &opt_session_name
, 0, 0, 0},
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 {"jul", 'j', POPT_ARG_VAL
, &opt_jul
, 1, 0, 0},
57 {"kernel", 'k', POPT_ARG_VAL
, &opt_kernel
, 1, 0, 0},
59 /* Not implemented yet */
60 {"userspace", 'u', POPT_ARG_STRING
| POPT_ARGFLAG_OPTIONAL
, &opt_cmd_name
, OPT_USERSPACE
, 0, 0},
61 {"pid", 'p', POPT_ARG_INT
, &opt_pid
, 0, 0, 0},
63 {"userspace", 'u', POPT_ARG_NONE
, 0, OPT_USERSPACE
, 0, 0},
65 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
72 static void usage(FILE *ofp
)
74 fprintf(ofp
, "usage: lttng disable-event NAME[,NAME2,...] (-k | -u) [OPTIONS]\n");
76 fprintf(ofp
, "Options:\n");
77 fprintf(ofp
, " -h, --help Show this help\n");
78 fprintf(ofp
, " --list-options Simple listing of options\n");
79 fprintf(ofp
, " -s, --session NAME Apply to session name\n");
80 fprintf(ofp
, " -c, --channel NAME Apply to this channel\n");
81 fprintf(ofp
, " -a, --all-events Disable all tracepoints\n");
82 fprintf(ofp
, " -k, --kernel Apply for the kernel tracer\n");
83 fprintf(ofp
, " -u, --userspace Apply to the user-space tracer\n");
84 fprintf(ofp
, " -j, --jul Apply for Java application using JUL\n");
89 const char *print_channel_name(const char *name
)
91 return name
? : DEFAULT_CHANNEL_NAME
;
95 const char *print_raw_channel_name(const char *name
)
97 return name
? : "<default>";
103 * Disabling event using the lttng API.
105 static int disable_events(char *session_name
)
107 int ret
= CMD_SUCCESS
, warn
= 0;
108 char *event_name
, *channel_name
= NULL
;
109 struct lttng_domain dom
;
111 memset(&dom
, 0, sizeof(dom
));
113 /* Create lttng domain */
115 dom
.type
= LTTNG_DOMAIN_KERNEL
;
116 } else if (opt_userspace
) {
117 dom
.type
= LTTNG_DOMAIN_UST
;
118 } else if (opt_jul
) {
119 dom
.type
= LTTNG_DOMAIN_JUL
;
121 print_missing_domain();
126 channel_name
= opt_channel_name
;
128 handle
= lttng_create_handle(session_name
, &dom
);
129 if (handle
== NULL
) {
134 if (opt_disable_all
) {
135 ret
= lttng_disable_event(handle
, NULL
, channel_name
);
137 ERR("%s", lttng_strerror(ret
));
141 MSG("All %s events are disabled in channel %s",
142 get_domain_str(dom
.type
), print_channel_name(channel_name
));
146 /* Strip event list */
147 event_name
= strtok(opt_event_list
, ",");
148 while (event_name
!= NULL
) {
149 DBG("Disabling event %s", event_name
);
151 ret
= lttng_disable_event(handle
, event_name
, channel_name
);
153 ERR("Event %s: %s (channel %s, session %s)", event_name
,
155 ret
== -LTTNG_ERR_NEED_CHANNEL_NAME
156 ? print_raw_channel_name(channel_name
)
157 : print_channel_name(channel_name
),
161 MSG("%s event %s disabled in channel %s for session %s",
162 get_domain_str(dom
.type
), event_name
,
163 print_channel_name(channel_name
),
168 event_name
= strtok(NULL
, ",");
178 lttng_destroy_handle(handle
);
186 * Disable event to trace session
188 int cmd_disable_events(int argc
, const char **argv
)
190 int opt
, ret
= CMD_SUCCESS
;
191 static poptContext pc
;
192 char *session_name
= NULL
;
194 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
195 poptReadDefaultConfig(pc
, 0);
197 while ((opt
= poptGetNextOpt(pc
)) != -1) {
205 case OPT_LIST_OPTIONS
:
206 list_cmd_options(stdout
, long_options
);
215 /* TODO: mi support */
217 ret
= -LTTNG_ERR_MI_NOT_IMPLEMENTED
;
218 ERR("mi option not supported");
222 opt_event_list
= (char*) poptGetArg(pc
);
223 if (opt_event_list
== NULL
&& opt_disable_all
== 0) {
224 ERR("Missing event name(s).\n");
230 if (!opt_session_name
) {
231 session_name
= get_session_name();
232 if (session_name
== NULL
) {
237 session_name
= opt_session_name
;
240 ret
= disable_events(session_name
);
243 if (!opt_session_name
&& session_name
) {