ff42da0e001c552c6b6f49c3d9a58b3126ecc4c1
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>
28 #include "../command.h"
30 static char *opt_event_list
;
31 static int opt_kernel
;
32 static char *opt_channel_name
;
33 static char *opt_session_name
;
34 static int opt_userspace
;
35 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 {"kernel", 'k', POPT_ARG_VAL
, &opt_kernel
, 1, 0, 0},
58 /* Not implemented yet */
59 {"userspace", 'u', POPT_ARG_STRING
| POPT_ARGFLAG_OPTIONAL
, &opt_cmd_name
, OPT_USERSPACE
, 0, 0},
60 {"pid", 'p', POPT_ARG_INT
, &opt_pid
, 0, 0, 0},
62 {"userspace", 'u', POPT_ARG_NONE
, 0, OPT_USERSPACE
, 0, 0},
64 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
71 static void usage(FILE *ofp
)
73 fprintf(ofp
, "usage: lttng disable-event NAME[,NAME2,...] [options]\n");
75 fprintf(ofp
, " -h, --help Show this help\n");
76 fprintf(ofp
, " --list-options Simple listing of options\n");
77 fprintf(ofp
, " -s, --session Apply on session name\n");
78 fprintf(ofp
, " -c, --channel Apply on this channel\n");
79 fprintf(ofp
, " -a, --all-events Disable all tracepoints\n");
80 fprintf(ofp
, " -k, --kernel Apply for the kernel tracer\n");
82 fprintf(ofp
, " -u, --userspace [CMD] Apply for the user-space tracer\n");
83 fprintf(ofp
, " If no CMD, the domain used is UST global\n");
84 fprintf(ofp
, " or else the domain is UST EXEC_NAME\n");
85 fprintf(ofp
, " -p, --pid PID If -u, apply to specific PID (domain: UST PID)\n");
87 fprintf(ofp
, " -u, --userspace Apply for the user-space tracer\n");
95 * Disabling event using the lttng API.
97 static int disable_events(char *session_name
)
99 int err
, ret
= CMD_SUCCESS
;
100 char *event_name
, *channel_name
= NULL
;
101 struct lttng_domain dom
;
103 if (opt_channel_name
== NULL
) {
104 err
= asprintf(&channel_name
, DEFAULT_CHANNEL_NAME
);
110 channel_name
= opt_channel_name
;
113 if (opt_kernel
&& opt_userspace
) {
114 ERR("Can't use -k/--kernel and -u/--userspace together");
119 /* Create lttng domain */
121 dom
.type
= LTTNG_DOMAIN_KERNEL
;
122 } else if (opt_userspace
) {
123 dom
.type
= LTTNG_DOMAIN_UST
;
125 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
130 handle
= lttng_create_handle(session_name
, &dom
);
131 if (handle
== NULL
) {
136 if (opt_disable_all
) {
137 ret
= lttng_disable_event(handle
, NULL
, channel_name
);
142 MSG("All %s events are disabled in channel %s",
143 opt_kernel
? "kernel" : "UST", channel_name
);
147 /* Strip event list */
148 event_name
= strtok(opt_event_list
, ",");
149 while (event_name
!= NULL
) {
150 /* Kernel tracer action */
152 DBG("Disabling kernel event %s in channel %s",
153 event_name
, channel_name
);
154 } else if (opt_userspace
) { /* User-space tracer action */
156 if (opt_cmd_name
!= NULL
|| opt_pid
) {
157 MSG("Only supporting tracing all UST processes (-u) for now.");
162 DBG("Disabling UST event %s in channel %s",
163 event_name
, channel_name
);
165 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
169 ret
= lttng_disable_event(handle
, event_name
, channel_name
);
171 MSG("Unable to disable %s event %s in channel %s",
172 opt_kernel
? "kernel" : "UST", event_name
,
175 MSG("%s event %s disabled in channel %s",
176 opt_kernel
? "kernel" : "UST", event_name
,
181 event_name
= strtok(NULL
, ",");
186 if (opt_channel_name
== NULL
) {
189 lttng_destroy_handle(handle
);
197 * Disable event to trace session
199 int cmd_disable_events(int argc
, const char **argv
)
202 static poptContext pc
;
203 char *session_name
= NULL
;
205 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
206 poptReadDefaultConfig(pc
, 0);
208 while ((opt
= poptGetNextOpt(pc
)) != -1) {
217 case OPT_LIST_OPTIONS
:
218 list_cmd_options(stdout
, long_options
);
228 opt_event_list
= (char*) poptGetArg(pc
);
229 if (opt_event_list
== NULL
&& opt_disable_all
== 0) {
230 ERR("Missing event name(s).\n");
236 if (!opt_session_name
) {
237 session_name
= get_session_name();
238 if (session_name
== NULL
) {
243 session_name
= opt_session_name
;
246 ret
= disable_events(session_name
);
This page took 0.044138 seconds and 4 git commands to generate.