1 /* Copyright (C) 2009 Pierre-Marc Fournier
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
8 * This library 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 GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "ust/ustcmd.h"
54 char *progname
= NULL
;
58 fprintf(stderr
, "usage: %s COMMAND PIDs...\n", progname
);
59 fprintf(stderr
, "\nControl the tracing of a process that supports LTTng Userspace Tracing.\n\
62 --create-trace\t\t\tCreate trace\n\
63 --alloc-trace\t\t\tAlloc trace\n\
64 --start-trace\t\t\tStart tracing\n\
65 --stop-trace\t\t\tStop tracing\n\
66 --destroy-trace\t\t\tDestroy the trace\n\
67 --set-subbuf-size \"CHANNEL/bytes\"\tSet the size of subbuffers per channel\n\
68 --set-subbuf-num \"CHANNEL/n\"\tSet the number of subbuffers per channel\n\
69 --set-sock-path\t\t\tSet the path of the daemon socket\n\
70 --get-subbuf-size \"CHANNEL\"\t\tGet the size of subbuffers per channel\n\
71 --get-subbuf-num \"CHANNEL\"\t\tGet the number of subbuffers per channel\n\
72 --get-sock-path\t\t\tGet the path of the daemon socket\n\
73 --enable-marker \"CHANNEL/MARKER\"\tEnable a marker\n\
74 --disable-marker \"CHANNEL/MARKER\"\tDisable a marker\n\
75 --list-markers\t\t\tList the markers of the process, their\n\t\t\t\t\t state and format string\n\
76 --force-switch\t\t\tForce a subbuffer switch\n\
81 int parse_opts_long(int argc
, char **argv
, struct ust_opts
*opts
)
90 static struct option long_options
[] = {
91 { "create-trace", 0, 0, CREATE_TRACE
},
92 { "alloc-trace", 0, 0, ALLOC_TRACE
},
93 { "start-trace", 0, 0, START_TRACE
},
94 { "stop-trace", 0, 0, STOP_TRACE
},
95 { "destroy-trace", 0, 0, DESTROY_TRACE
},
96 { "list-markers", 0, 0, LIST_MARKERS
},
97 { "enable-marker", 1, 0, ENABLE_MARKER
},
98 { "disable-marker", 1, 0, DISABLE_MARKER
},
99 { "help", 0, 0, 'h' },
100 { "online-pids", 0, 0, GET_ONLINE_PIDS
},
101 { "set-subbuf-size", 1, 0, SET_SUBBUF_SIZE
},
102 { "set-subbuf-num", 1, 0, SET_SUBBUF_NUM
},
103 { "get-subbuf-size", 1, 0, GET_SUBBUF_SIZE
},
104 { "get-subbuf-num", 1, 0, GET_SUBBUF_NUM
},
105 { "get-sock-path", 0, 0, GET_SOCK_PATH
},
106 { "set-sock-path", 1, 0, SET_SOCK_PATH
},
107 { "force-switch", 0, 0, FORCE_SWITCH
},
111 c
= getopt_long(argc
, argv
, "h", long_options
, &option_index
);
120 printf("option %s", long_options
[option_index
].name
);
122 printf(" with arg %s", optarg
);
128 case SET_SUBBUF_SIZE
:
130 case GET_SUBBUF_SIZE
:
133 opts
->regex
= strdup(optarg
);
141 fprintf(stderr
, "Invalid argument\n\n");
147 if (argc
- optind
> 0 && opts
->cmd
!= GET_ONLINE_PIDS
) {
150 opts
->pids
= malloc((argc
-optind
+1) * sizeof(pid_t
));
152 for(i
=optind
; i
<argc
; i
++) {
153 /* don't take any chances, use a long long */
156 tmp
= strtoull(argv
[i
], &endptr
, 10);
157 if(*endptr
!= '\0') {
158 ERR("The pid \"%s\" is invalid.", argv
[i
]);
161 opts
->pids
[pididx
++] = (pid_t
) tmp
;
163 opts
->pids
[pididx
] = -1;
169 int main(int argc
, char *argv
[])
174 struct ust_opts opts
;
179 fprintf(stderr
, "No operation specified.\n");
184 result
= parse_opts_long(argc
, argv
, &opts
);
186 fprintf(stderr
, "\n");
191 if(opts
.pids
== NULL
&& opts
.cmd
!= GET_ONLINE_PIDS
) {
192 fprintf(stderr
, "No pid specified.\n");
196 if(opts
.cmd
== UNKNOWN
) {
197 fprintf(stderr
, "No command specified.\n");
201 if (opts
.cmd
== GET_ONLINE_PIDS
) {
202 pid_t
*pp
= ustcmd_get_online_pids();
207 printf("%u\n", (unsigned int) pp
[i
]);
217 struct marker_status
*cmsf
= NULL
;
219 while(*pidit
!= -1) {
222 result
= ustcmd_create_trace(*pidit
);
224 ERR("error while trying to create trace with PID %u\n", (unsigned int) *pidit
);
230 result
= ustcmd_start_trace(*pidit
);
232 ERR("error while trying to for trace with PID %u\n", (unsigned int) *pidit
);
238 result
= ustcmd_stop_trace(*pidit
);
240 ERR("error while trying to stop trace for PID %u\n", (unsigned int) *pidit
);
246 result
= ustcmd_destroy_trace(*pidit
);
248 ERR("error while trying to destroy trace with PID %u\n", (unsigned int) *pidit
);
255 if (ustcmd_get_cmsf(&cmsf
, *pidit
)) {
257 "error while trying to list markers for"
258 " PID %u\n", (unsigned int) *pidit
);
262 while (cmsf
[i
].channel
!= NULL
) {
263 printf("{PID: %u, channel/marker: %s/%s, "
264 "state: %u, fmt: %s}\n",
265 (unsigned int) *pidit
,
272 ustcmd_free_cmsf(cmsf
);
277 ustcmd_set_marker_state(opts
.regex
, 1, *pidit
);
281 ustcmd_set_marker_state(opts
.regex
, 0, *pidit
);
284 case SET_SUBBUF_SIZE
:
285 ustcmd_set_subbuf_size(opts
.regex
, *pidit
);
289 ustcmd_set_subbuf_num(opts
.regex
, *pidit
);
292 case GET_SUBBUF_SIZE
:
293 result
= ustcmd_get_subbuf_size(opts
.regex
, *pidit
);
295 ERR("error while trying to get_subuf_size with PID %u\n", (unsigned int) *pidit
);
299 printf("the size of subbufers is %d\n", result
);
303 result
= ustcmd_get_subbuf_num(opts
.regex
, *pidit
);
305 ERR("error while trying to get_subuf_num with PID %u\n", (unsigned int) *pidit
);
309 printf("the number of subbufers is %d\n", result
);
313 result
= ustcmd_alloc_trace(*pidit
);
315 ERR("error while trying to alloc trace with PID %u\n", (unsigned int) *pidit
);
321 result
= ustcmd_get_sock_path(&tmp
, *pidit
);
323 ERR("error while trying to get sock path for PID %u\n", (unsigned int) *pidit
);
326 printf("the socket path is %s\n", tmp
);
331 result
= ustcmd_set_sock_path(opts
.regex
, *pidit
);
333 ERR("error while trying to set sock path for PID %u\n", (unsigned int) *pidit
);
338 result
= ustcmd_force_switch(*pidit
);
340 ERR("error while trying to force switch for PID %u\n", (unsigned int) *pidit
);
345 ERR("unknown command\n");
352 if (opts
.pids
!= NULL
) {
355 if (opts
.regex
!= NULL
) {
This page took 0.040763 seconds and 5 git commands to generate.