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
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\
80 int parse_opts_long(int argc
, char **argv
, struct ust_opts
*opts
)
89 static struct option long_options
[] = {
90 { "create-trace", 0, 0, CREATE_TRACE
},
91 { "alloc-trace", 0, 0, ALLOC_TRACE
},
92 { "start-trace", 0, 0, START_TRACE
},
93 { "stop-trace", 0, 0, STOP_TRACE
},
94 { "destroy-trace", 0, 0, DESTROY_TRACE
},
95 { "list-markers", 0, 0, LIST_MARKERS
},
96 { "enable-marker", 1, 0, ENABLE_MARKER
},
97 { "disable-marker", 1, 0, DISABLE_MARKER
},
98 { "help", 0, 0, 'h' },
99 { "online-pids", 0, 0, GET_ONLINE_PIDS
},
100 { "set-subbuf-size", 1, 0, SET_SUBBUF_SIZE
},
101 { "set-subbuf-num", 1, 0, SET_SUBBUF_NUM
},
102 { "get-subbuf-size", 1, 0, GET_SUBBUF_SIZE
},
103 { "get-subbuf-num", 1, 0, GET_SUBBUF_NUM
},
104 { "get-sock-path", 0, 0, GET_SOCK_PATH
},
105 { "set-sock-path", 1, 0, SET_SOCK_PATH
},
109 c
= getopt_long(argc
, argv
, "h", long_options
, &option_index
);
118 printf("option %s", long_options
[option_index
].name
);
120 printf(" with arg %s", optarg
);
126 case SET_SUBBUF_SIZE
:
128 case GET_SUBBUF_SIZE
:
131 opts
->regex
= strdup(optarg
);
139 fprintf(stderr
, "Invalid argument\n\n");
145 if (argc
- optind
> 0 && opts
->cmd
!= GET_ONLINE_PIDS
) {
148 opts
->pids
= malloc((argc
-optind
+1) * sizeof(pid_t
));
150 for(i
=optind
; i
<argc
; i
++) {
151 /* don't take any chances, use a long long */
154 tmp
= strtoull(argv
[i
], &endptr
, 10);
155 if(*endptr
!= '\0') {
156 ERR("The pid \"%s\" is invalid.", argv
[i
]);
159 opts
->pids
[pididx
++] = (pid_t
) tmp
;
161 opts
->pids
[pididx
] = -1;
167 int main(int argc
, char *argv
[])
172 struct ust_opts opts
;
177 fprintf(stderr
, "No operation specified.\n");
182 result
= parse_opts_long(argc
, argv
, &opts
);
184 fprintf(stderr
, "\n");
189 if(opts
.pids
== NULL
&& opts
.cmd
!= GET_ONLINE_PIDS
) {
190 fprintf(stderr
, "No pid specified.\n");
194 if(opts
.cmd
== UNKNOWN
) {
195 fprintf(stderr
, "No command specified.\n");
199 if (opts
.cmd
== GET_ONLINE_PIDS
) {
200 pid_t
*pp
= ustcmd_get_online_pids();
205 printf("%u\n", (unsigned int) pp
[i
]);
215 struct marker_status
*cmsf
= NULL
;
217 while(*pidit
!= -1) {
220 result
= ustcmd_create_trace(*pidit
);
222 ERR("error while trying to create trace with PID %u\n", (unsigned int) *pidit
);
228 result
= ustcmd_start_trace(*pidit
);
230 ERR("error while trying to for trace with PID %u\n", (unsigned int) *pidit
);
236 result
= ustcmd_stop_trace(*pidit
);
238 ERR("error while trying to stop trace for PID %u\n", (unsigned int) *pidit
);
244 result
= ustcmd_destroy_trace(*pidit
);
246 ERR("error while trying to destroy trace with PID %u\n", (unsigned int) *pidit
);
253 if (ustcmd_get_cmsf(&cmsf
, *pidit
)) {
255 "error while trying to list markers for"
256 " PID %u\n", (unsigned int) *pidit
);
260 while (cmsf
[i
].channel
!= NULL
) {
261 printf("{PID: %u, channel/marker: %s/%s, "
262 "state: %u, fmt: %s}\n",
263 (unsigned int) *pidit
,
270 ustcmd_free_cmsf(cmsf
);
275 ustcmd_set_marker_state(opts
.regex
, 1, *pidit
);
279 ustcmd_set_marker_state(opts
.regex
, 0, *pidit
);
282 case SET_SUBBUF_SIZE
:
283 ustcmd_set_subbuf_size(opts
.regex
, *pidit
);
287 ustcmd_set_subbuf_num(opts
.regex
, *pidit
);
290 case GET_SUBBUF_SIZE
:
291 result
= ustcmd_get_subbuf_size(opts
.regex
, *pidit
);
293 ERR("error while trying to get_subuf_size with PID %u\n", (unsigned int) *pidit
);
297 printf("the size of subbufers is %d\n", result
);
301 result
= ustcmd_get_subbuf_num(opts
.regex
, *pidit
);
303 ERR("error while trying to get_subuf_num with PID %u\n", (unsigned int) *pidit
);
307 printf("the number of subbufers is %d\n", result
);
311 result
= ustcmd_alloc_trace(*pidit
);
313 ERR("error while trying to alloc trace with PID %u\n", (unsigned int) *pidit
);
319 result
= ustcmd_get_sock_path(&tmp
, *pidit
);
321 ERR("error while trying to get sock path for PID %u\n", (unsigned int) *pidit
);
324 printf("the socket path is %s\n", tmp
);
329 result
= ustcmd_set_sock_path(opts
.regex
, *pidit
);
331 ERR("error while trying to set sock path for PID %u\n", (unsigned int) *pidit
);
336 ERR("unknown command\n");
343 if (opts
.pids
!= NULL
) {
346 if (opts
.regex
!= NULL
) {
This page took 0.036395 seconds and 4 git commands to generate.