2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; only version 2
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.
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.
25 #include <sys/types.h>
32 static char *opt_event_list
;
33 static int opt_kernel
;
34 static char *opt_channel_name
;
35 static char *opt_session_name
;
36 static int opt_userspace
;
37 static char *opt_cmd_name
;
38 static int opt_disable_all
;
46 static struct lttng_handle
*handle
;
48 static struct poptOption long_options
[] = {
49 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
50 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
51 {"session", 's', POPT_ARG_STRING
, &opt_session_name
, 0, 0, 0},
52 {"all-events", 'a', POPT_ARG_VAL
, &opt_disable_all
, 1, 0, 0},
53 {"channel", 'c', POPT_ARG_STRING
, &opt_channel_name
, 0, 0, 0},
54 {"kernel", 'k', POPT_ARG_VAL
, &opt_kernel
, 1, 0, 0},
55 {"userspace", 'u', POPT_ARG_STRING
| POPT_ARGFLAG_OPTIONAL
, &opt_cmd_name
, OPT_USERSPACE
, 0, 0},
56 {"pid", 'p', POPT_ARG_INT
, &opt_pid
, 0, 0, 0},
63 static void usage(FILE *ofp
)
65 fprintf(ofp
, "usage: lttng disable-event NAME[,NAME2,...] [options]\n");
67 fprintf(ofp
, " -h, --help Show this help\n");
68 fprintf(ofp
, " -s, --session Apply on session name\n");
69 fprintf(ofp
, " -c, --channel Apply on this channel\n");
70 fprintf(ofp
, " -a, --all-events Disable 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
, " If no CMD, the domain used is UST global\n");
74 fprintf(ofp
, " or else the domain is UST EXEC_NAME\n");
75 fprintf(ofp
, " -p, --pid PID If -u, apply to specific PID (domain: UST PID)\n");
82 * Disabling event using the lttng API.
84 static int disable_events(char *session_name
)
86 int err
, ret
= CMD_SUCCESS
;
87 char *event_name
, *channel_name
= NULL
;
88 struct lttng_domain dom
;
90 if (opt_channel_name
== NULL
) {
91 err
= asprintf(&channel_name
, DEFAULT_CHANNEL_NAME
);
97 channel_name
= opt_channel_name
;
100 if (opt_kernel
&& opt_userspace
) {
101 ERR("Can't use -k/--kernel and -u/--userspace together");
107 dom
.type
= LTTNG_DOMAIN_KERNEL
;
108 } else if (opt_pid
!= 0) {
109 dom
.type
= LTTNG_DOMAIN_UST_PID
;
110 dom
.attr
.pid
= opt_pid
;
111 DBG("PID %d set to lttng handle", opt_pid
);
112 } else if (opt_userspace
&& opt_cmd_name
== NULL
) {
113 dom
.type
= LTTNG_DOMAIN_UST
;
114 DBG("UST global domain selected");
115 } else if (opt_userspace
&& opt_cmd_name
!= NULL
) {
116 dom
.type
= LTTNG_DOMAIN_UST_EXEC_NAME
;
117 strncpy(dom
.attr
.exec_name
, opt_cmd_name
, NAME_MAX
);
118 dom
.attr
.exec_name
[NAME_MAX
- 1] = '\0';
120 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
121 ret
= CMD_NOT_IMPLEMENTED
;
125 handle
= lttng_create_handle(session_name
, &dom
);
126 if (handle
== NULL
) {
131 if (opt_disable_all
) {
132 ret
= lttng_disable_event(handle
, NULL
, channel_name
);
137 MSG("All %s events are disabled in channel %s",
138 opt_kernel
? "kernel" : "UST", channel_name
);
142 /* Strip event list */
143 event_name
= strtok(opt_event_list
, ",");
144 while (event_name
!= NULL
) {
145 /* Kernel tracer action */
147 DBG("Disabling kernel event %s in channel %s",
148 event_name
, channel_name
);
149 } else if (opt_userspace
) { /* User-space tracer action */
150 if (opt_cmd_name
!= NULL
|| opt_pid
) {
151 MSG("Only supporting tracing all UST processes (-u) for now.");
152 ret
= CMD_NOT_IMPLEMENTED
;
155 DBG("Disabling UST event %s in channel %s",
156 event_name
, channel_name
);
158 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
162 ret
= lttng_disable_event(handle
, event_name
, channel_name
);
164 MSG("Unable to disable %s event %s in channel %s",
165 opt_kernel
? "kernel" : "UST", event_name
,
168 MSG("%s event %s disabled in channel %s",
169 opt_kernel
? "kernel" : "UST", event_name
,
174 event_name
= strtok(NULL
, ",");
179 if (opt_channel_name
== NULL
) {
182 lttng_destroy_handle(handle
);
190 * Disable event to trace session
192 int cmd_disable_events(int argc
, const char **argv
)
195 static poptContext pc
;
196 char *session_name
= NULL
;
198 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
199 poptReadDefaultConfig(pc
, 0);
201 while ((opt
= poptGetNextOpt(pc
)) != -1) {
217 opt_event_list
= (char*) poptGetArg(pc
);
218 if (opt_event_list
== NULL
&& opt_disable_all
== 0) {
219 ERR("Missing event name(s).\n");
225 if (!opt_session_name
) {
226 session_name
= get_session_name();
227 if (session_name
== NULL
) {
232 session_name
= opt_session_name
;
235 ret
= disable_events(session_name
);