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
;
36 /* Not implemented yet */
37 static char *opt_cmd_name
;
47 static struct lttng_handle
*handle
;
49 static struct poptOption long_options
[] = {
50 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
51 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
52 {"session", 's', POPT_ARG_STRING
, &opt_session_name
, 0, 0, 0},
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},
57 /* Not implemented yet */
58 {"userspace", 'u', POPT_ARG_STRING
| POPT_ARGFLAG_OPTIONAL
, &opt_cmd_name
, OPT_USERSPACE
, 0, 0},
59 {"pid", 'p', POPT_ARG_INT
, &opt_pid
, 0, 0, 0},
61 {"userspace", 'u', POPT_ARG_NONE
, 0, OPT_USERSPACE
, 0, 0},
63 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
70 static void usage(FILE *ofp
)
72 fprintf(ofp
, "usage: lttng disable-event NAME[,NAME2,...] [options]\n");
74 fprintf(ofp
, " -h, --help Show this help\n");
75 fprintf(ofp
, " --list-options Simple listing of options\n");
76 fprintf(ofp
, " -s, --session Apply to session name\n");
77 fprintf(ofp
, " -c, --channel Apply to this channel\n");
78 fprintf(ofp
, " -a, --all-events Disable all tracepoints\n");
79 fprintf(ofp
, " -k, --kernel Apply for the kernel tracer\n");
81 fprintf(ofp
, " -u, --userspace [CMD] Apply to the user-space tracer\n");
82 fprintf(ofp
, " If no CMD, the domain used is UST global\n");
83 fprintf(ofp
, " or else the domain is UST EXEC_NAME\n");
84 fprintf(ofp
, " -p, --pid PID If -u, apply to specific PID (domain: UST PID)\n");
86 fprintf(ofp
, " -u, --userspace Apply to the user-space tracer\n");
94 * Disabling event using the lttng API.
96 static int disable_events(char *session_name
)
98 int err
, ret
= CMD_SUCCESS
, warn
= 0;
99 char *event_name
, *channel_name
= NULL
;
100 struct lttng_domain dom
;
102 memset(&dom
, 0, sizeof(dom
));
104 /* Create lttng domain */
106 dom
.type
= LTTNG_DOMAIN_KERNEL
;
107 } else if (opt_userspace
) {
108 dom
.type
= LTTNG_DOMAIN_UST
;
110 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
115 /* Get channel name */
116 if (opt_channel_name
== NULL
) {
117 err
= asprintf(&channel_name
, DEFAULT_CHANNEL_NAME
);
123 channel_name
= opt_channel_name
;
126 handle
= lttng_create_handle(session_name
, &dom
);
127 if (handle
== NULL
) {
132 if (opt_disable_all
) {
133 ret
= lttng_disable_event(handle
, NULL
, channel_name
);
135 /* Don't set ret so lttng can interpret the sessiond error. */
139 MSG("All %s events are disabled in channel %s",
140 opt_kernel
? "kernel" : "UST", channel_name
);
144 /* Strip event list */
145 event_name
= strtok(opt_event_list
, ",");
146 while (event_name
!= NULL
) {
147 DBG("Disabling event %s", event_name
);
149 ret
= lttng_disable_event(handle
, event_name
, channel_name
);
151 ERR("Event %s: %s (channel %s, session %s)", event_name
,
152 lttng_strerror(ret
), channel_name
, session_name
);
155 MSG("%s event %s disabled in channel %s for session %s",
156 opt_kernel
? "kernel" : "UST", event_name
, channel_name
,
161 event_name
= strtok(NULL
, ",");
171 if (opt_channel_name
== NULL
) {
174 lttng_destroy_handle(handle
);
182 * Disable event to trace session
184 int cmd_disable_events(int argc
, const char **argv
)
186 int opt
, ret
= CMD_SUCCESS
;
187 static poptContext pc
;
188 char *session_name
= NULL
;
190 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
191 poptReadDefaultConfig(pc
, 0);
193 while ((opt
= poptGetNextOpt(pc
)) != -1) {
201 case OPT_LIST_OPTIONS
:
202 list_cmd_options(stdout
, long_options
);
211 opt_event_list
= (char*) poptGetArg(pc
);
212 if (opt_event_list
== NULL
&& opt_disable_all
== 0) {
213 ERR("Missing event name(s).\n");
219 if (!opt_session_name
) {
220 session_name
= get_session_name();
221 if (session_name
== NULL
) {
226 session_name
= opt_session_name
;
229 ret
= disable_events(session_name
);
232 if (!opt_session_name
&& session_name
) {
This page took 0.035671 seconds and 5 git commands to generate.