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
51 char *progname
= NULL
;
55 fprintf(stderr
, "usage: %s COMMAND PIDs...\n", progname
);
56 fprintf(stderr
, "\nControl the tracing of a process that supports LTTng Userspace Tracing.\n\
59 --create-trace\t\t\tCreate trace\n\
60 --start-trace\t\t\tStart tracing\n\
61 --stop-trace\t\t\tStop tracing\n\
62 --destroy-trace\t\t\tDestroy the trace\n\
63 --set-subbuf-size \"CHANNEL/bytes\"\tSet the size of subbuffers per channel\n\
64 --set-subbuf-num \"CHANNEL/n\"\tSet the number of subbuffers per channel\n\
65 --enable-marker \"CHANNEL/MARKER\"\tEnable a marker\n\
66 --disable-marker \"CHANNEL/MARKER\"\tDisable a marker\n\
67 --list-markers\t\t\tList the markers of the process, their\n\t\t\t\t\t state and format string\n\
72 int parse_opts_long(int argc
, char **argv
, struct ust_opts
*opts
)
81 static struct option long_options
[] = {
82 {"create-trace", 0, 0, 1012},
83 {"alloc-trace", 0, 0, 1015},
84 {"start-trace", 0, 0, 1000},
85 {"stop-trace", 0, 0, 1001},
86 {"destroy-trace", 0, 0, 1002},
87 {"list-markers", 0, 0, 1004},
88 {"print-markers", 0, 0, 1005},
90 {"enable-marker", 1, 0, 1007},
91 {"disable-marker", 1, 0, 1008},
92 {"start", 0, 0, 1009},
94 /*{"version", 0, 0, 1010},*/
95 {"online-pids", 0, 0, 1011},
96 {"set-subbuf-size", 1, 0, 1013},
97 {"set-subbuf-num", 1, 0, 1014},
101 c
= getopt_long(argc
, argv
, "h", long_options
, &option_index
);
107 printf("option %s", long_options
[option_index
].name
);
109 printf(" with arg %s", optarg
);
114 opts
->cmd
= START_TRACE
;
117 opts
->cmd
= STOP_TRACE
;
126 opts
->cmd
= LIST_MARKERS
;
129 opts
->cmd
= ENABLE_MARKER
;
130 opts
->regex
= strdup(optarg
);
133 opts
->cmd
= DISABLE_MARKER
;
134 opts
->regex
= strdup(optarg
);
137 opts
->cmd
= GET_ONLINE_PIDS
;
144 printf("Version 0.1\n");
148 opts
->cmd
= CREATE_TRACE
;
151 opts
->cmd
= SET_SUBBUF_SIZE
;
152 opts
->regex
= strdup(optarg
);
155 opts
->cmd
= SET_SUBBUF_NUM
;
156 opts
->regex
= strdup(optarg
);
159 opts
->cmd
= ALLOC_TRACE
;
162 /* unknown option or other error; error is
163 printed by getopt, just return */
169 if (argc
- optind
> 0 && opts
->cmd
!= GET_ONLINE_PIDS
) {
172 opts
->pids
= malloc((argc
-optind
+1) * sizeof(pid_t
));
174 for(i
=optind
; i
<argc
; i
++) {
175 /* don't take any chances, use a long long */
178 tmp
= strtoull(argv
[i
], &endptr
, 10);
179 if(*endptr
!= '\0') {
180 ERR("The pid \"%s\" is invalid.", argv
[i
]);
183 opts
->pids
[pididx
++] = (pid_t
) tmp
;
185 opts
->pids
[pididx
] = -1;
191 int main(int argc
, char *argv
[])
195 struct ust_opts opts
;
200 fprintf(stderr
, "No operation specified.\n");
205 result
= parse_opts_long(argc
, argv
, &opts
);
207 fprintf(stderr
, "\n");
212 if(opts
.pids
== NULL
&& opts
.cmd
!= GET_ONLINE_PIDS
) {
213 fprintf(stderr
, "No pid specified.\n");
217 if(opts
.cmd
== UNKNOWN
) {
218 fprintf(stderr
, "No command specified.\n");
222 if (opts
.cmd
== GET_ONLINE_PIDS
) {
223 pid_t
*pp
= ustcmd_get_online_pids();
228 printf("%u\n", (unsigned int) pp
[i
]);
238 struct marker_status
*cmsf
= NULL
;
240 while(*pidit
!= -1) {
243 result
= ustcmd_create_trace(*pidit
);
245 ERR("error while trying to create trace with PID %u\n", (unsigned int) *pidit
);
251 result
= ustcmd_start_trace(*pidit
);
253 ERR("error while trying to for trace with PID %u\n", (unsigned int) *pidit
);
256 //printf("sucessfully started trace for PID %u\n", (unsigned int) *pidit);
260 result
= ustcmd_stop_trace(*pidit
);
262 ERR("error while trying to stop trace for PID %u\n", (unsigned int) *pidit
);
265 //printf("sucessfully stopped trace for PID %u\n", (unsigned int) *pidit);
269 result
= ustcmd_setup_and_start(*pidit
);
271 ERR("error while trying to setup/start trace for PID %u\n", (unsigned int) *pidit
);
274 //printf("sucessfully setup/started trace for PID %u\n", (unsigned int) *pidit);
278 result
= ustcmd_destroy_trace(*pidit
);
280 ERR("error while trying to destroy trace with PID %u\n", (unsigned int) *pidit
);
283 //printf("sucessfully destroyed trace for PID %u\n", (unsigned int) *pidit);
288 if (ustcmd_get_cmsf(&cmsf
, *pidit
)) {
290 "error while trying to list markers for"
291 " PID %u\n", (unsigned int) *pidit
);
295 while (cmsf
[i
].channel
!= NULL
) {
296 printf("{PID: %u, channel/marker: %s/%s, "
297 "state: %u, fmt: %s}\n",
298 (unsigned int) *pidit
,
305 ustcmd_free_cmsf(cmsf
);
310 ustcmd_set_marker_state(opts
.regex
, 1, *pidit
);
314 ustcmd_set_marker_state(opts
.regex
, 0, *pidit
);
317 case SET_SUBBUF_SIZE
:
318 ustcmd_set_subbuf_size(opts
.regex
, *pidit
);
322 ustcmd_set_subbuf_num(opts
.regex
, *pidit
);
326 result
= ustcmd_alloc_trace(*pidit
);
328 ERR("error while trying to alloc trace with PID %u\n", (unsigned int) *pidit
);
334 ERR("unknown command\n");
341 if (opts
.pids
!= NULL
) {
344 if (opts
.regex
!= NULL
) {
This page took 0.056253 seconds and 4 git commands to generate.