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
50 char *progname
= NULL
;
54 fprintf(stderr
, "usage: %s COMMAND PIDs...\n", progname
);
55 fprintf(stderr
, "\nControl the tracing of a process that supports LTTng Userspace Tracing.\n\
58 --create-trace\t\t\tCreate trace\n\
59 --alloc-trace\t\t\tAlloc 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, CREATE_TRACE
},
83 { "alloc-trace", 0, 0, ALLOC_TRACE
},
84 { "start-trace", 0, 0, START_TRACE
},
85 { "stop-trace", 0, 0, STOP_TRACE
},
86 { "destroy-trace", 0, 0, DESTROY_TRACE
},
87 { "list-markers", 0, 0, LIST_MARKERS
},
88 { "enable-marker", 1, 0, ENABLE_MARKER
},
89 { "disable-marker", 1, 0, DISABLE_MARKER
},
90 { "help", 0, 0, 'h' },
91 { "online-pids", 0, 0, GET_ONLINE_PIDS
},
92 { "set-subbuf-size", 1, 0, SET_SUBBUF_SIZE
},
93 { "set-subbuf-num", 1, 0, SET_SUBBUF_NUM
},
97 c
= getopt_long(argc
, argv
, "h", long_options
, &option_index
);
106 printf("option %s", long_options
[option_index
].name
);
108 printf(" with arg %s", optarg
);
114 case SET_SUBBUF_SIZE
:
116 opts
->regex
= strdup(optarg
);
124 fprintf(stderr
, "Invalid argument\n\n");
130 if (argc
- optind
> 0 && opts
->cmd
!= GET_ONLINE_PIDS
) {
133 opts
->pids
= malloc((argc
-optind
+1) * sizeof(pid_t
));
135 for(i
=optind
; i
<argc
; i
++) {
136 /* don't take any chances, use a long long */
139 tmp
= strtoull(argv
[i
], &endptr
, 10);
140 if(*endptr
!= '\0') {
141 ERR("The pid \"%s\" is invalid.", argv
[i
]);
144 opts
->pids
[pididx
++] = (pid_t
) tmp
;
146 opts
->pids
[pididx
] = -1;
152 int main(int argc
, char *argv
[])
156 struct ust_opts opts
;
161 fprintf(stderr
, "No operation specified.\n");
166 result
= parse_opts_long(argc
, argv
, &opts
);
168 fprintf(stderr
, "\n");
173 if(opts
.pids
== NULL
&& opts
.cmd
!= GET_ONLINE_PIDS
) {
174 fprintf(stderr
, "No pid specified.\n");
178 if(opts
.cmd
== UNKNOWN
) {
179 fprintf(stderr
, "No command specified.\n");
183 if (opts
.cmd
== GET_ONLINE_PIDS
) {
184 pid_t
*pp
= ustcmd_get_online_pids();
189 printf("%u\n", (unsigned int) pp
[i
]);
199 struct marker_status
*cmsf
= NULL
;
201 while(*pidit
!= -1) {
204 result
= ustcmd_create_trace(*pidit
);
206 ERR("error while trying to create trace with PID %u\n", (unsigned int) *pidit
);
212 result
= ustcmd_start_trace(*pidit
);
214 ERR("error while trying to for trace with PID %u\n", (unsigned int) *pidit
);
220 result
= ustcmd_stop_trace(*pidit
);
222 ERR("error while trying to stop trace for PID %u\n", (unsigned int) *pidit
);
228 result
= ustcmd_destroy_trace(*pidit
);
230 ERR("error while trying to destroy trace with PID %u\n", (unsigned int) *pidit
);
237 if (ustcmd_get_cmsf(&cmsf
, *pidit
)) {
239 "error while trying to list markers for"
240 " PID %u\n", (unsigned int) *pidit
);
244 while (cmsf
[i
].channel
!= NULL
) {
245 printf("{PID: %u, channel/marker: %s/%s, "
246 "state: %u, fmt: %s}\n",
247 (unsigned int) *pidit
,
254 ustcmd_free_cmsf(cmsf
);
259 ustcmd_set_marker_state(opts
.regex
, 1, *pidit
);
263 ustcmd_set_marker_state(opts
.regex
, 0, *pidit
);
266 case SET_SUBBUF_SIZE
:
267 ustcmd_set_subbuf_size(opts
.regex
, *pidit
);
271 ustcmd_set_subbuf_num(opts
.regex
, *pidit
);
275 result
= ustcmd_alloc_trace(*pidit
);
277 ERR("error while trying to alloc trace with PID %u\n", (unsigned int) *pidit
);
283 ERR("unknown command\n");
290 if (opts
.pids
!= NULL
) {
293 if (opts
.regex
!= NULL
) {
This page took 0.048328 seconds and 4 git commands to generate.