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
48 char *progname
= NULL
;
52 fprintf(stderr
, "usage: %s COMMAND PIDs...\n", progname
);
53 fprintf(stderr
, "\nControl the tracing of a process that supports LTTng Userspace Tracing.\n\
56 --create-trace\t\t\tCreate trace\n\
57 --start-trace\t\t\tStart tracing\n\
58 --stop-trace\t\t\tStop tracing\n\
59 --destroy-trace\t\t\tDestroy the trace\n\
60 --enable-marker \"CHANNEL/MARKER\"\tEnable a marker\n\
61 --disable-marker \"CHANNEL/MARKER\"\tDisable a marker\n\
62 --list-markers\t\t\tList the markers of the process, their\n\t\t\t\t\t state and format string\n\
67 int parse_opts_long(int argc
, char **argv
, struct ust_opts
*opts
)
76 static struct option long_options
[] = {
77 {"create-trace", 0, 0, 1012},
78 {"start-trace", 0, 0, 1000},
79 {"stop-trace", 0, 0, 1001},
80 {"destroy-trace", 0, 0, 1002},
81 {"list-markers", 0, 0, 1004},
82 {"print-markers", 0, 0, 1005},
84 {"enable-marker", 1, 0, 1007},
85 {"disable-marker", 1, 0, 1008},
86 {"start", 0, 0, 1009},
88 {"version", 0, 0, 1010},
89 {"online-pids", 0, 0, 1011},
93 c
= getopt_long(argc
, argv
, "h", long_options
, &option_index
);
99 printf("option %s", long_options
[option_index
].name
);
101 printf(" with arg %s", optarg
);
106 opts
->cmd
= START_TRACE
;
109 opts
->cmd
= STOP_TRACE
;
118 opts
->cmd
= LIST_MARKERS
;
121 opts
->cmd
= ENABLE_MARKER
;
122 opts
->regex
= strdup(optarg
);
125 opts
->cmd
= DISABLE_MARKER
;
126 opts
->regex
= strdup(optarg
);
129 opts
->cmd
= GET_ONLINE_PIDS
;
135 printf("Version 0.1\n");
138 opts
->cmd
= CREATE_TRACE
;
141 /* unknown option or other error; error is
142 printed by getopt, just return */
148 if (argc
- optind
> 0 && opts
->cmd
!= GET_ONLINE_PIDS
) {
151 opts
->pids
= malloc((argc
-optind
+1) * sizeof(pid_t
));
153 for(i
=optind
; i
<argc
; i
++) {
154 /* don't take any chances, use a long long */
157 tmp
= strtoull(argv
[i
], &endptr
, 10);
158 if(*endptr
!= '\0') {
159 ERR("The pid \"%s\" is invalid.", argv
[i
]);
162 opts
->pids
[pididx
++] = (pid_t
) tmp
;
164 opts
->pids
[pididx
] = -1;
170 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
);
235 //printf("sucessfully started trace for PID %u\n", (unsigned int) *pidit);
239 result
= ustcmd_stop_trace(*pidit
);
241 ERR("error while trying to stop trace for PID %u\n", (unsigned int) *pidit
);
244 //printf("sucessfully stopped trace for PID %u\n", (unsigned int) *pidit);
248 result
= ustcmd_setup_and_start(*pidit
);
250 ERR("error while trying to setup/start trace for PID %u\n", (unsigned int) *pidit
);
253 //printf("sucessfully setup/started trace for PID %u\n", (unsigned int) *pidit);
257 result
= ustcmd_destroy_trace(*pidit
);
259 ERR("error while trying to destroy trace with PID %u\n", (unsigned int) *pidit
);
262 //printf("sucessfully destroyed trace for PID %u\n", (unsigned int) *pidit);
267 if (ustcmd_get_cmsf(&cmsf
, *pidit
)) {
269 "error while trying to list markers for"
270 " PID %u\n", (unsigned int) *pidit
);
274 while (cmsf
[i
].channel
!= NULL
) {
275 printf("{PID: %u, channel/marker: %s/%s, "
276 "state: %u, fmt: %s}\n",
277 (unsigned int) *pidit
,
284 ustcmd_free_cmsf(cmsf
);
289 ustcmd_set_marker_state(opts
.regex
, 1, *pidit
);
293 ustcmd_set_marker_state(opts
.regex
, 0, *pidit
);
297 ERR("unknown command\n");
304 if (opts
.pids
!= NULL
) {
307 if (opts
.regex
!= NULL
) {
This page took 0.052206 seconds and 5 git commands to generate.