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/ustcmd.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
);
48 struct option options
[] =
50 {"help", 2, NULL
, 'h'},
51 {"list", 0, NULL
, 'l'},
52 {"extended-list", 0, NULL
, 'e'},
56 int main(int argc
, char *argv
[])
58 struct cli_cmd
*cli_cmd
;
62 fprintf(stderr
, "No operation specified.\n");
67 while ((opt
= getopt_long(argc
, argv
, "+h::le",
68 options
, NULL
)) != -1) {
74 if (cli_print_help(optarg
)) {
75 fprintf(stderr
, "No such command %s\n",
82 list_cli_cmds(CLI_SIMPLE_LIST
);
86 list_cli_cmds(CLI_EXTENDED_LIST
);
89 fprintf(stderr
, "Unknown option\n");
94 cli_cmd
= find_cli_cmd(argv
[optind
]);
96 fprintf(stderr
, "No such command %s\n",
101 cli_dispatch_cmd(cli_cmd
, argc
- optind
, &argv
[optind
]);
106 static int list_trace_events(int argc
, char *argv
[])
108 struct trace_event_status
*tes
= NULL
;
112 pid
= parse_pid(argv
[1]);
114 if (ustcmd_get_tes(&tes
, pid
)) {
115 ERR("error while trying to list "
116 "trace_events for PID %u\n",
121 for (i
= 0; tes
[i
].name
; i
++) {
122 printf("{PID: %u, trace_event: %s}\n",
126 ustcmd_free_tes(tes
);
131 static int set_sock_path(int argc
, char *argv
[])
135 pid
= parse_pid(argv
[1]);
137 if (ustcmd_set_sock_path(argv
[2], pid
)) {
138 ERR("error while trying to set sock path for PID %u\n", pid
);
145 static int get_sock_path(int argc
, char *argv
[])
150 pid
= parse_pid(argv
[1]);
152 if (ustcmd_get_sock_path(&sock_path
, pid
)) {
153 ERR("error while trying to get sock path for PID %u\n", pid
);
156 printf("The socket path is %s\n", sock_path
);
162 struct cli_cmd __cli_cmds general_cmds
[] = {
164 .name
= "list-trace-events",
165 .description
= "List trace-events for a given pid",
166 .help_text
= "list-trace-events <pid>\n"
167 "List the trace-events in a process\n",
168 .function
= list_trace_events
,
170 .desired_args_op
= CLI_EQ
,
173 .name
= "set-sock-path",
174 .description
= "Set the path to the consumer daemon socket",
175 .help_text
= "set-sock-path <pid> <sock-path>\n"
176 "Set the path to the consumer daemon socket\n",
177 .function
= set_sock_path
,
179 .desired_args_op
= CLI_EQ
,
182 .name
= "get-sock-path",
183 .description
= "Get the path to the consumer daemon socket",
184 .help_text
= "get-sock-path <pid>\n"
185 "Get the path to the consumer daemon socket\n",
186 .function
= get_sock_path
,
188 .desired_args_op
= CLI_EQ
,