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
52 char *progname
= NULL
;
56 fprintf(stderr
, "usage: %s COMMAND PIDs...\n", progname
);
57 fprintf(stderr
, "\nControl the tracing of a process that supports LTTng Userspace Tracing.\n\
60 --create-trace\t\t\tCreate trace\n\
61 --alloc-trace\t\t\tAlloc trace\n\
62 --start-trace\t\t\tStart tracing\n\
63 --stop-trace\t\t\tStop tracing\n\
64 --destroy-trace\t\t\tDestroy the trace\n\
65 --set-subbuf-size \"CHANNEL/bytes\"\tSet the size of subbuffers per channel\n\
66 --set-subbuf-num \"CHANNEL/n\"\tSet the number of subbuffers per channel\n\
67 --get-subbuf-size \"CHANNEL\"\t\tGet the size of subbuffers per channel\n\
68 --get-subbuf-num \"CHANNEL\"\t\tGet the number of subbuffers per channel\n\
69 --enable-marker \"CHANNEL/MARKER\"\tEnable a marker\n\
70 --disable-marker \"CHANNEL/MARKER\"\tDisable a marker\n\
71 --list-markers\t\t\tList the markers of the process, their\n\t\t\t\t\t state and format string\n\
76 int parse_opts_long(int argc
, char **argv
, struct ust_opts
*opts
)
85 static struct option long_options
[] = {
86 { "create-trace", 0, 0, CREATE_TRACE
},
87 { "alloc-trace", 0, 0, ALLOC_TRACE
},
88 { "start-trace", 0, 0, START_TRACE
},
89 { "stop-trace", 0, 0, STOP_TRACE
},
90 { "destroy-trace", 0, 0, DESTROY_TRACE
},
91 { "list-markers", 0, 0, LIST_MARKERS
},
92 { "enable-marker", 1, 0, ENABLE_MARKER
},
93 { "disable-marker", 1, 0, DISABLE_MARKER
},
94 { "help", 0, 0, 'h' },
95 { "online-pids", 0, 0, GET_ONLINE_PIDS
},
96 { "set-subbuf-size", 1, 0, SET_SUBBUF_SIZE
},
97 { "set-subbuf-num", 1, 0, SET_SUBBUF_NUM
},
98 { "get-subbuf-size", 1, 0, GET_SUBBUF_SIZE
},
99 { "get-subbuf-num", 1, 0, GET_SUBBUF_NUM
},
103 c
= getopt_long(argc
, argv
, "h", long_options
, &option_index
);
112 printf("option %s", long_options
[option_index
].name
);
114 printf(" with arg %s", optarg
);
120 case SET_SUBBUF_SIZE
:
122 case GET_SUBBUF_SIZE
:
124 opts
->regex
= strdup(optarg
);
132 fprintf(stderr
, "Invalid argument\n\n");
138 if (argc
- optind
> 0 && opts
->cmd
!= GET_ONLINE_PIDS
) {
141 opts
->pids
= malloc((argc
-optind
+1) * sizeof(pid_t
));
143 for(i
=optind
; i
<argc
; i
++) {
144 /* don't take any chances, use a long long */
147 tmp
= strtoull(argv
[i
], &endptr
, 10);
148 if(*endptr
!= '\0') {
149 ERR("The pid \"%s\" is invalid.", argv
[i
]);
152 opts
->pids
[pididx
++] = (pid_t
) tmp
;
154 opts
->pids
[pididx
] = -1;
160 int main(int argc
, char *argv
[])
164 struct ust_opts opts
;
169 fprintf(stderr
, "No operation specified.\n");
174 result
= parse_opts_long(argc
, argv
, &opts
);
176 fprintf(stderr
, "\n");
181 if(opts
.pids
== NULL
&& opts
.cmd
!= GET_ONLINE_PIDS
) {
182 fprintf(stderr
, "No pid specified.\n");
186 if(opts
.cmd
== UNKNOWN
) {
187 fprintf(stderr
, "No command specified.\n");
191 if (opts
.cmd
== GET_ONLINE_PIDS
) {
192 pid_t
*pp
= ustcmd_get_online_pids();
197 printf("%u\n", (unsigned int) pp
[i
]);
207 struct marker_status
*cmsf
= NULL
;
209 while(*pidit
!= -1) {
212 result
= ustcmd_create_trace(*pidit
);
214 ERR("error while trying to create trace with PID %u\n", (unsigned int) *pidit
);
220 result
= ustcmd_start_trace(*pidit
);
222 ERR("error while trying to for trace with PID %u\n", (unsigned int) *pidit
);
228 result
= ustcmd_stop_trace(*pidit
);
230 ERR("error while trying to stop trace for PID %u\n", (unsigned int) *pidit
);
236 result
= ustcmd_destroy_trace(*pidit
);
238 ERR("error while trying to destroy trace with PID %u\n", (unsigned int) *pidit
);
245 if (ustcmd_get_cmsf(&cmsf
, *pidit
)) {
247 "error while trying to list markers for"
248 " PID %u\n", (unsigned int) *pidit
);
252 while (cmsf
[i
].channel
!= NULL
) {
253 printf("{PID: %u, channel/marker: %s/%s, "
254 "state: %u, fmt: %s}\n",
255 (unsigned int) *pidit
,
262 ustcmd_free_cmsf(cmsf
);
267 ustcmd_set_marker_state(opts
.regex
, 1, *pidit
);
271 ustcmd_set_marker_state(opts
.regex
, 0, *pidit
);
274 case SET_SUBBUF_SIZE
:
275 ustcmd_set_subbuf_size(opts
.regex
, *pidit
);
279 ustcmd_set_subbuf_num(opts
.regex
, *pidit
);
282 case GET_SUBBUF_SIZE
:
283 result
= ustcmd_get_subbuf_size(opts
.regex
, *pidit
);
285 ERR("error while trying to get_subuf_size with PID %u\n", (unsigned int) *pidit
);
289 printf("the size of subbufers is %d\n", result
);
293 result
= ustcmd_get_subbuf_num(opts
.regex
, *pidit
);
295 ERR("error while trying to get_subuf_num with PID %u\n", (unsigned int) *pidit
);
299 printf("the number of subbufers is %d\n", result
);
303 result
= ustcmd_alloc_trace(*pidit
);
305 ERR("error while trying to alloc trace with PID %u\n", (unsigned int) *pidit
);
311 ERR("unknown command\n");
318 if (opts
.pids
!= NULL
) {
321 if (opts
.regex
!= NULL
) {
This page took 0.037654 seconds and 5 git commands to generate.