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,...] [-k|-u] [OPTIONS]\n");
70 fprintf(ofp
, "Options:\n");
71 fprintf(ofp
, " -h, --help Show this help\n");
72 fprintf(ofp
, " --list-options Simple listing of options\n");
73 fprintf(ofp
, " -s, --session NAME Apply to session name\n");
74 fprintf(ofp
, " -k, --kernel Apply to the kernel tracer\n");
75 fprintf(ofp
, " -u, --userspace Apply to the user-space tracer\n");
80 * Disabling channel using the lttng API.
82 static int disable_channels(char *session_name
)
84 int ret
= CMD_SUCCESS
, warn
= 0;
86 struct lttng_domain dom
;
88 memset(&dom
, 0, sizeof(dom
));
90 /* Create lttng domain */
92 dom
.type
= LTTNG_DOMAIN_KERNEL
;
93 } else if (opt_userspace
) {
94 dom
.type
= LTTNG_DOMAIN_UST
;
96 ERR("Please specify a tracer (-k/--kernel or -u/--userspace)");
101 handle
= lttng_create_handle(session_name
, &dom
);
102 if (handle
== NULL
) {
107 /* Strip channel list */
108 channel_name
= strtok(opt_channels
, ",");
109 while (channel_name
!= NULL
) {
110 DBG("Disabling channel %s", channel_name
);
112 ret
= lttng_disable_channel(handle
, channel_name
);
114 ERR("Channel %s: %s (session %s)", channel_name
,
115 lttng_strerror(ret
), session_name
);
118 MSG("%s channel %s disabled for session %s",
119 opt_kernel
? "Kernel" : "UST", channel_name
, session_name
);
123 channel_name
= strtok(NULL
, ",");
133 lttng_destroy_handle(handle
);
139 * cmd_disable_channels
141 * Disable channel to trace session
143 int cmd_disable_channels(int argc
, const char **argv
)
145 int opt
, ret
= CMD_SUCCESS
;
146 static poptContext pc
;
147 char *session_name
= NULL
;
149 pc
= poptGetContext(NULL
, argc
, argv
, long_options
, 0);
150 poptReadDefaultConfig(pc
, 0);
152 while ((opt
= poptGetNextOpt(pc
)) != -1) {
160 case OPT_LIST_OPTIONS
:
161 list_cmd_options(stdout
, long_options
);
170 opt_channels
= (char*) poptGetArg(pc
);
171 if (opt_channels
== NULL
) {
172 ERR("Missing channel name(s).\n");
178 if (!opt_session_name
) {
179 session_name
= get_session_name();
180 if (session_name
== NULL
) {
185 session_name
= opt_session_name
;
188 ret
= disable_channels(session_name
);
191 if (!opt_session_name
&& session_name
) {
This page took 0.035443 seconds and 4 git commands to generate.