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_channels
;
31 static int opt_kernel
;
32 static char *opt_session_name
;
33 static int opt_userspace
;
34 static char *opt_cmd_name
;
42 static struct lttng_handle
*handle
;
44 static struct poptOption long_options
[] = {
45 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
46 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
47 {"session", 's', POPT_ARG_STRING
, &opt_session_name
, 0, 0, 0},
48 {"kernel", 'k', POPT_ARG_VAL
, &opt_kernel
, 1, 0, 0},
49 {"userspace", 'u', POPT_ARG_STRING
| POPT_ARGFLAG_OPTIONAL
, &opt_cmd_name
, OPT_USERSPACE
, 0, 0},
50 {"pid", 'p', POPT_ARG_INT
, &opt_pid
, 0, 0, 0},
57 static void usage(FILE *ofp
)
59 fprintf(ofp
, "usage: lttng disable-channel NAME[,NAME2,...] [options]\n");
61 fprintf(ofp
, " -h, --help Show this help\n");
62 fprintf(ofp
, " -s, --session Apply on session name\n");
63 fprintf(ofp
, " -k, --kernel Apply for the kernel tracer\n");
64 fprintf(ofp
, " -u, --userspace [CMD] Apply for the user-space tracer\n");
65 fprintf(ofp
, " If no CMD, the domain used is UST global\n");
66 fprintf(ofp
, " or else the domain is UST EXEC_NAME\n");
67 fprintf(ofp
, " -p, --pid PID If -u, apply to specific PID (domain: UST PID)\n");
72 * Disabling channel using the lttng API.
74 static int disable_channels(char *session_name
)
76 int ret
= CMD_SUCCESS
;
78 struct lttng_domain dom
;
81 dom
.type
= LTTNG_DOMAIN_KERNEL
;
82 } else if (opt_pid
!= 0) {
83 dom
.type
= LTTNG_DOMAIN_UST_PID
;
84 dom
.attr
.pid
= opt_pid
;
85 DBG("PID %d set to lttng handle", opt_pid
);
86 } else if (opt_userspace
&& opt_cmd_name
== NULL
) {
87 dom
.type
= LTTNG_DOMAIN_UST
;
88 } else if (opt_userspace
&& opt_cmd_name
!= NULL
) {
89 dom
.type
= LTTNG_DOMAIN_UST_EXEC_NAME
;
90 strncpy(dom
.attr
.exec_name
, opt_cmd_name
, NAME_MAX
);
92 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
93 ret
= CMD_NOT_IMPLEMENTED
;
97 handle
= lttng_create_handle(session_name
, &dom
);
103 /* Strip channel list */
104 channel_name
= strtok(opt_channels
, ",");
105 while (channel_name
!= NULL
) {
106 DBG("Disabling channel %s", channel_name
);
108 ret
= lttng_disable_channel(handle
, channel_name
);
112 MSG("%s channel %s disabled for session %s",
113 opt_kernel
? "Kernel" : "UST", channel_name
,
118 channel_name
= strtok(NULL
, ",");
122 lttng_destroy_handle(handle
);
128 * cmd_disable_channels
130 * Disable channel to trace session
132 int cmd_disable_channels(int argc
, const char **argv
)
135 static poptContext pc
;
136 char *session_name
= NULL
;
138 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
139 poptReadDefaultConfig(pc
, 0);
141 while ((opt
= poptGetNextOpt(pc
)) != -1) {
157 opt_channels
= (char*) poptGetArg(pc
);
158 if (opt_channels
== NULL
) {
159 ERR("Missing channel name(s).\n");
165 if (!opt_session_name
) {
166 session_name
= get_session_name();
167 if (session_name
== NULL
) {
172 session_name
= opt_session_name
;
175 ret
= disable_channels(session_name
);