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_channels
;
33 static int opt_kernel
;
34 static char *opt_session_name
;
35 static int opt_userspace
;
36 static char *opt_cmd_name
;
44 static struct lttng_handle
*handle
;
46 static struct poptOption long_options
[] = {
47 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
48 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
49 {"session", 's', POPT_ARG_STRING
, &opt_session_name
, 0, 0, 0},
50 {"kernel", 'k', POPT_ARG_VAL
, &opt_kernel
, 1, 0, 0},
51 {"userspace", 'u', POPT_ARG_STRING
| POPT_ARGFLAG_OPTIONAL
, &opt_cmd_name
, OPT_USERSPACE
, 0, 0},
52 {"pid", 'p', POPT_ARG_INT
, &opt_pid
, 0, 0, 0},
59 static void usage(FILE *ofp
)
61 fprintf(ofp
, "usage: lttng disable-channel NAME[,NAME2,...] [options]\n");
63 fprintf(ofp
, " -h, --help Show this help\n");
64 fprintf(ofp
, " -s, --session Apply on session name\n");
65 fprintf(ofp
, " -k, --kernel Apply for the kernel tracer\n");
66 fprintf(ofp
, " -u, --userspace [CMD] Apply for the user-space tracer\n");
67 fprintf(ofp
, " If no CMD, the domain used is UST global\n");
68 fprintf(ofp
, " or else the domain is UST EXEC_NAME\n");
69 fprintf(ofp
, " -p, --pid PID If -u, apply to specific PID (domain: UST PID)\n");
74 * Disabling channel using the lttng API.
76 static int disable_channels(char *session_name
)
78 int ret
= CMD_SUCCESS
;
80 struct lttng_domain dom
;
83 dom
.type
= LTTNG_DOMAIN_KERNEL
;
84 } else if (opt_pid
!= 0) {
85 dom
.type
= LTTNG_DOMAIN_UST_PID
;
86 dom
.attr
.pid
= opt_pid
;
87 DBG("PID %d set to lttng handle", opt_pid
);
88 } else if (opt_userspace
&& opt_cmd_name
== NULL
) {
89 dom
.type
= LTTNG_DOMAIN_UST
;
90 } else if (opt_userspace
&& opt_cmd_name
!= NULL
) {
91 dom
.type
= LTTNG_DOMAIN_UST_EXEC_NAME
;
92 strncpy(dom
.attr
.exec_name
, opt_cmd_name
, NAME_MAX
);
94 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
95 ret
= CMD_NOT_IMPLEMENTED
;
99 handle
= lttng_create_handle(session_name
, &dom
);
100 if (handle
== NULL
) {
105 /* Strip channel list */
106 channel_name
= strtok(opt_channels
, ",");
107 while (channel_name
!= NULL
) {
108 DBG("Disabling channel %s", channel_name
);
110 ret
= lttng_disable_channel(handle
, channel_name
);
114 MSG("%s channel %s disabled for session %s",
115 opt_kernel
? "Kernel" : "UST", channel_name
,
120 channel_name
= strtok(NULL
, ",");
124 lttng_destroy_handle(handle
);
130 * cmd_disable_channels
132 * Disable channel to trace session
134 int cmd_disable_channels(int argc
, const char **argv
)
137 static poptContext pc
;
138 char *session_name
= NULL
;
140 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
141 poptReadDefaultConfig(pc
, 0);
143 while ((opt
= poptGetNextOpt(pc
)) != -1) {
159 opt_channels
= (char*) poptGetArg(pc
);
160 if (opt_channels
== NULL
) {
161 ERR("Missing channel name(s).\n");
167 if (!opt_session_name
) {
168 session_name
= get_session_name();
169 if (session_name
== NULL
) {
174 session_name
= opt_session_name
;
177 ret
= disable_channels(session_name
);