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_channels
;
30 static int opt_kernel
;
31 static char *opt_session_name
;
32 static int opt_userspace
;
34 /* Not implemented yet */
35 static char *opt_cmd_name
;
45 static struct lttng_handle
*handle
;
47 static struct poptOption long_options
[] = {
48 /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
49 {"help", 'h', POPT_ARG_NONE
, 0, OPT_HELP
, 0, 0},
50 {"session", 's', POPT_ARG_STRING
, &opt_session_name
, 0, 0, 0},
51 {"kernel", 'k', POPT_ARG_VAL
, &opt_kernel
, 1, 0, 0},
53 /* Not implemented yet */
54 {"userspace", 'u', POPT_ARG_STRING
| POPT_ARGFLAG_OPTIONAL
, &opt_cmd_name
, OPT_USERSPACE
, 0, 0},
55 {"pid", 'p', POPT_ARG_INT
, &opt_pid
, 0, 0, 0},
57 {"userspace", 'u', POPT_ARG_NONE
, 0, OPT_USERSPACE
, 0, 0},
59 {"list-options", 0, POPT_ARG_NONE
, NULL
, OPT_LIST_OPTIONS
, NULL
, NULL
},
66 static void usage(FILE *ofp
)
68 fprintf(ofp
, "usage: lttng disable-channel NAME[,NAME2,...] [options]\n");
70 fprintf(ofp
, " -h, --help Show this help\n");
71 fprintf(ofp
, " --list-options Simple listing of options\n");
72 fprintf(ofp
, " -s, --session Apply to session name\n");
73 fprintf(ofp
, " -k, --kernel Apply to the kernel tracer\n");
75 fprintf(ofp
, " -u, --userspace [CMD] Apply to the user-space tracer\n");
76 fprintf(ofp
, " If no CMD, the domain used is UST global\n");
77 fprintf(ofp
, " or else the domain is UST EXEC_NAME\n");
78 fprintf(ofp
, " -p, --pid PID If -u, apply to specific PID (domain: UST PID)\n");
80 fprintf(ofp
, " -u, --userspace Apply to the user-space tracer\n");
86 * Disabling channel using the lttng API.
88 static int disable_channels(char *session_name
)
90 int ret
= CMD_SUCCESS
, warn
= 0;
92 struct lttng_domain dom
;
94 memset(&dom
, 0, sizeof(dom
));
96 /* Create lttng domain */
98 dom
.type
= LTTNG_DOMAIN_KERNEL
;
99 } else if (opt_userspace
) {
100 dom
.type
= LTTNG_DOMAIN_UST
;
102 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
107 handle
= lttng_create_handle(session_name
, &dom
);
108 if (handle
== NULL
) {
113 /* Strip channel list */
114 channel_name
= strtok(opt_channels
, ",");
115 while (channel_name
!= NULL
) {
116 DBG("Disabling channel %s", channel_name
);
118 ret
= lttng_disable_channel(handle
, channel_name
);
120 ERR("Channel %s: %s (session %s)", channel_name
,
121 lttng_strerror(ret
), session_name
);
124 MSG("%s channel %s disabled for session %s",
125 opt_kernel
? "Kernel" : "UST", channel_name
, session_name
);
129 channel_name
= strtok(NULL
, ",");
139 lttng_destroy_handle(handle
);
145 * cmd_disable_channels
147 * Disable channel to trace session
149 int cmd_disable_channels(int argc
, const char **argv
)
151 int opt
, ret
= CMD_SUCCESS
;
152 static poptContext pc
;
153 char *session_name
= NULL
;
155 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
156 poptReadDefaultConfig(pc
, 0);
158 while ((opt
= poptGetNextOpt(pc
)) != -1) {
166 case OPT_LIST_OPTIONS
:
167 list_cmd_options(stdout
, long_options
);
176 opt_channels
= (char*) poptGetArg(pc
);
177 if (opt_channels
== NULL
) {
178 ERR("Missing channel name(s).\n");
184 if (!opt_session_name
) {
185 session_name
= get_session_name();
186 if (session_name
== NULL
) {
191 session_name
= opt_session_name
;
194 ret
= disable_channels(session_name
);
197 if (!opt_session_name
&& session_name
) {
This page took 0.033835 seconds and 5 git commands to generate.