1 /* Copyright (C) 2009 Pierre-Marc Fournier
2 * Copyright (C) 2011 Ericsson AB, Nils Carlson <nils.carlson@ericsson.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "ust/ustctl.h"
29 #include "scanning_functions.h"
31 void usage(const char *process_name
)
33 fprintf(stderr
, "Usage: %s COMMAND [ARGS]...\n", process_name
);
35 "Control tracing within a process that supports UST,\n"
36 " the Userspace Tracing libary\n"
38 " -h[<cmd>], --help[=<cmd>] "
39 "help, for a command if provided\n"
41 "short list of commands\n"
42 " -e, --extended-list "
43 "extented list of commands with help\n"
45 list_cli_cmds(CLI_DESCRIPTIVE_LIST
);
49 * Provide backward compatibility for scripts that make use of the
50 * --commands in ustctl version <= 0.11
64 struct option options
[] =
66 { "create-trace", 0, 0, CREATE_TRACE
},
67 { "alloc-trace", 0, 0, ALLOC_TRACE
},
68 { "start-trace", 0, 0, START_TRACE
},
69 { "stop-trace", 0, 0, STOP_TRACE
},
70 { "destroy-trace", 0, 0, DESTROY_TRACE
},
71 { "list-markers", 0, 0, LIST_MARKERS
},
72 { "list-trace-events", 0, 0, LIST_TRACE_EVENTS
},
73 { "enable-marker", 0, 0, ENABLE_MARKER
},
74 { "disable-marker", 0, 0, DISABLE_MARKER
},
75 {"help", 2, NULL
, 'h'},
76 {"list", 0, NULL
, 'l'},
77 {"extended-list", 0, NULL
, 'e'},
81 int main(int argc
, char *argv
[])
83 struct cli_cmd
*cli_cmd
;
89 fprintf(stderr
, "No operation specified.\n");
94 while ((opt
= getopt_long(argc
, argv
, "+h::le",
95 options
, NULL
)) != -1) {
101 if (cli_print_help(optarg
)) {
102 fprintf(stderr
, "No such command %s\n",
109 list_cli_cmds(CLI_SIMPLE_LIST
);
113 list_cli_cmds(CLI_EXTENDED_LIST
);
116 case LIST_TRACE_EVENTS
:
124 args
= (char **)malloc(sizeof(char *) * (argc
+ 3));
126 args
[optind
] = strdup(&argv
[optind
][2]);
127 for (i
= optind
+ 1; i
< argc
; i
++) {
130 if (opt
>= CREATE_TRACE
&& opt
<= DESTROY_TRACE
) {
131 args
[argc
] = strdup("auto");
134 if (opt
>= ENABLE_MARKER
&& opt
<= DISABLE_MARKER
) {
135 args
[argc
] = args
[argc
- 2];
136 args
[argc
- 2] = args
[argc
- 1];
137 args
[argc
- 1] = strdup("auto");
143 fprintf(stderr
, "Unknown option\n");
149 cli_cmd
= find_cli_cmd(args
[optind
]);
151 fprintf(stderr
, "No such command %s\n",
156 cli_dispatch_cmd(cli_cmd
, argc
- optind
, &args
[optind
]);
161 static int list_trace_events(int argc
, char *argv
[])
163 struct trace_event_status
*tes
= NULL
;
166 sock
= parse_and_connect_pid(argv
[1]);
168 if (ustctl_get_tes(sock
, &tes
)) {
169 ERR("error while trying to list "
170 "trace_events for PID %s\n",
175 for (i
= 0; tes
[i
].name
; i
++) {
176 printf("{PID: %s, trace_event: %s}\n",
180 ustctl_free_tes(tes
);
185 static int set_sock_path(int argc
, char *argv
[])
189 sock
= parse_and_connect_pid(argv
[1]);
191 if (ustctl_set_sock_path(sock
, argv
[2])) {
192 ERR("error while trying to set sock path for PID %s\n", argv
[1]);
199 static int get_sock_path(int argc
, char *argv
[])
204 sock
= parse_and_connect_pid(argv
[1]);
206 if (ustctl_get_sock_path(sock
, &sock_path
)) {
207 ERR("error while trying to get sock path for PID %s\n", argv
[1]);
210 printf("The socket path is %s\n", sock_path
);
216 static int list_pids(int argc
, char *argv
[])
221 pid_list
= ustctl_get_online_pids();
226 for (i
= 0; pid_list
[i
]; i
++) {
227 printf("%ld\n", (long)pid_list
[i
]);
235 struct cli_cmd __cli_cmds general_cmds
[] = {
237 .name
= "list-trace-events",
238 .description
= "List trace-events for a given pid",
239 .help_text
= "list-trace-events <pid>\n"
240 "List the trace-events in a process\n",
241 .function
= list_trace_events
,
243 .desired_args_op
= CLI_EQ
,
246 .name
= "set-sock-path",
247 .description
= "Set the path to the consumer daemon socket",
248 .help_text
= "set-sock-path <pid> <sock-path>\n"
249 "Set the path to the consumer daemon socket\n",
250 .function
= set_sock_path
,
252 .desired_args_op
= CLI_EQ
,
255 .name
= "get-sock-path",
256 .description
= "Get the path to the consumer daemon socket",
257 .help_text
= "get-sock-path <pid>\n"
258 "Get the path to the consumer daemon socket\n",
259 .function
= get_sock_path
,
261 .desired_args_op
= CLI_EQ
,
265 .description
= "List traceable pids",
266 .help_text
= "list-pids\n"
267 "List the traceable pids for the current user\n",
268 .function
= list_pids
,
270 .desired_args_op
= CLI_EQ
,