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 char *opt_kernel
;
34 static char *opt_cmd_name
;
35 static char *opt_channel_name
;
36 static char *opt_session_name
;
37 static int opt_pid_all
;
38 static int opt_userspace
;
39 static int opt_disable_all
;
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},
56 {"userspace", 'u', POPT_ARG_STRING
| POPT_ARGFLAG_OPTIONAL
, 0, OPT_USERSPACE
, 0, 0},
57 {"all", 0, POPT_ARG_VAL
, &opt_pid_all
, 1, 0, 0},
58 {"pid", 'p', POPT_ARG_INT
, &opt_pid
, 0, 0, 0},
65 static void usage(FILE *ofp
)
67 fprintf(ofp
, "usage: lttng disable-event NAME[,NAME2,...] [options]\n");
69 fprintf(ofp
, " -h, --help Show this help\n");
70 fprintf(ofp
, " -s, --session Apply on session name\n");
71 fprintf(ofp
, " -c, --channel Apply on this channel\n");
72 fprintf(ofp
, " -a, --all-events Enable all tracepoints\n");
73 fprintf(ofp
, " -k, --kernel Apply for the kernel tracer\n");
74 fprintf(ofp
, " -u, --userspace [CMD] Apply for the user-space tracer\n");
75 fprintf(ofp
, " --all If -u, apply on all traceable apps\n");
76 fprintf(ofp
, " -p, --pid PID If -u, apply on a specific PID\n");
83 * Disabling event using the lttng API.
85 static int disable_events(char *session_name
)
87 int err
, ret
= CMD_SUCCESS
;
88 char *event_name
, *channel_name
= NULL
;
89 struct lttng_event ev
;
90 struct lttng_domain dom
;
92 if (opt_channel_name
== NULL
) {
93 err
= asprintf(&channel_name
, DEFAULT_CHANNEL_NAME
);
99 channel_name
= opt_channel_name
;
103 dom
.type
= LTTNG_DOMAIN_KERNEL
;
106 handle
= lttng_create_handle(session_name
, &dom
);
107 if (handle
== NULL
) {
112 if (opt_disable_all
) {
114 ret
= lttng_disable_event(handle
, NULL
, channel_name
);
118 /* TODO: User-space tracer */
121 /* Strip event list */
122 event_name
= strtok(opt_event_list
, ",");
123 while (event_name
!= NULL
) {
124 /* Kernel tracer action */
126 DBG("Disabling kernel event %s for channel %s",
127 event_name
, channel_name
);
129 /* Copy name and type of the event */
130 strncpy(ev
.name
, event_name
, LTTNG_SYMBOL_NAME_LEN
);
131 ev
.name
[LTTNG_SYMBOL_NAME_LEN
- 1] = '\0';
132 ret
= lttng_disable_event(handle
, event_name
, channel_name
);
134 MSG("Unable to disable event %s for channel %s",
135 event_name
, channel_name
);
137 MSG("Kernel event %s disabled for channel %s",
138 event_name
, channel_name
);
140 } else if (opt_userspace
) { /* User-space tracer action */
142 * TODO: Waiting on lttng UST 2.0
145 } else if (opt_pid
!= 0) {
147 ret
= CMD_NOT_IMPLEMENTED
;
150 ERR("Please specify a tracer (--kernel or --userspace)");
155 event_name
= strtok(NULL
, ",");
159 if (opt_channel_name
== NULL
) {
162 lttng_destroy_handle(handle
);
170 * Disable event to trace session
172 int cmd_disable_events(int argc
, const char **argv
)
175 static poptContext pc
;
176 char *session_name
= NULL
;
178 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
179 poptReadDefaultConfig(pc
, 0);
181 while ((opt
= poptGetNextOpt(pc
)) != -1) {
189 opt_cmd_name
= poptGetOptArg(pc
);
198 opt_event_list
= (char*) poptGetArg(pc
);
199 if (opt_event_list
== NULL
&& opt_disable_all
== 0) {
200 ERR("Missing event name(s).\n");
206 if (!opt_session_name
) {
207 session_name
= get_session_name();
208 if (session_name
== NULL
) {
213 session_name
= opt_session_name
;
216 ret
= disable_events(session_name
);
This page took 0.071345 seconds and 4 git commands to generate.