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
47 char *progname
= NULL
;
51 fprintf(stderr
, "usage: %s COMMAND PIDs...\n", progname
);
52 fprintf(stderr
, "\nControl the tracing of a process that supports LTTng Userspace Tracing.\n\
55 --start-trace\t\t\tStart tracing\n\
56 --stop-trace\t\t\tStop tracing\n\
57 --destroy-trace\t\t\tDestroy the trace\n\
58 --enable-marker \"CHANNEL/MARKER\"\tEnable a marker\n\
59 --disable-marker \"CHANNEL/MARKER\"\tDisable a marker\n\
60 --list-markers\t\t\tList the markers of the process, their\n\t\t\t\t\t state and format string\n\
65 int parse_opts_long(int argc
, char **argv
, struct ust_opts
*opts
)
74 static struct option long_options
[] = {
75 {"start-trace", 0, 0, 1000},
76 {"stop-trace", 0, 0, 1001},
77 {"destroy-trace", 0, 0, 1002},
78 {"list-markers", 0, 0, 1004},
79 {"print-markers", 0, 0, 1005},
81 {"enable-marker", 1, 0, 1007},
82 {"disable-marker", 1, 0, 1008},
83 {"start", 0, 0, 1009},
85 {"version", 0, 0, 1010},
86 {"online-pids", 0, 0, 1011},
90 c
= getopt_long(argc
, argv
, "h", long_options
, &option_index
);
96 printf("option %s", long_options
[option_index
].name
);
98 printf(" with arg %s", optarg
);
103 opts
->cmd
= START_TRACE
;
106 opts
->cmd
= STOP_TRACE
;
115 opts
->cmd
= LIST_MARKERS
;
118 opts
->cmd
= ENABLE_MARKER
;
119 opts
->regex
= strdup(optarg
);
122 opts
->cmd
= DISABLE_MARKER
;
123 opts
->regex
= strdup(optarg
);
126 opts
->cmd
= GET_ONLINE_PIDS
;
132 printf("Version 0.1\n");
135 /* unknown option or other error; error is
136 printed by getopt, just return */
142 if (argc
- optind
> 0 && opts
->cmd
!= GET_ONLINE_PIDS
) {
145 opts
->pids
= malloc((argc
-optind
+1) * sizeof(pid_t
));
147 for(i
=optind
; i
<argc
; i
++) {
148 /* don't take any chances, use a long long */
151 tmp
= strtoull(argv
[i
], &endptr
, 10);
152 if(*endptr
!= '\0') {
153 ERR("The pid \"%s\" is invalid.", argv
[i
]);
156 opts
->pids
[pididx
++] = (pid_t
) tmp
;
158 opts
->pids
[pididx
] = -1;
164 int main(int argc
, char *argv
[])
168 struct ust_opts opts
;
173 fprintf(stderr
, "No operation specified.\n");
178 result
= parse_opts_long(argc
, argv
, &opts
);
180 fprintf(stderr
, "\n");
185 if(opts
.pids
== NULL
&& opts
.cmd
!= GET_ONLINE_PIDS
) {
186 fprintf(stderr
, "No pid specified.\n");
190 if(opts
.cmd
== UNKNOWN
) {
191 fprintf(stderr
, "No command specified.\n");
195 if (opts
.cmd
== GET_ONLINE_PIDS
) {
196 pid_t
*pp
= ustcmd_get_online_pids();
201 printf("%u\n", (unsigned int) pp
[i
]);
211 struct marker_status
*cmsf
= NULL
;
213 while(*pidit
!= -1) {
216 result
= ustcmd_start_trace(*pidit
);
218 ERR("error while trying to for trace with PID %u\n", (unsigned int) *pidit
);
221 //printf("sucessfully started trace for PID %u\n", (unsigned int) *pidit);
225 result
= ustcmd_stop_trace(*pidit
);
227 ERR("error while trying to stop trace for PID %u\n", (unsigned int) *pidit
);
230 //printf("sucessfully stopped trace for PID %u\n", (unsigned int) *pidit);
234 result
= ustcmd_setup_and_start(*pidit
);
236 ERR("error while trying to setup/start trace for PID %u\n", (unsigned int) *pidit
);
239 //printf("sucessfully setup/started trace for PID %u\n", (unsigned int) *pidit);
243 result
= ustcmd_destroy_trace(*pidit
);
245 ERR("error while trying to destroy trace with PID %u\n", (unsigned int) *pidit
);
248 //printf("sucessfully destroyed trace for 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
);
283 ERR("unknown command\n");
290 if (opts
.pids
!= NULL
) {
293 if (opts
.regex
!= NULL
) {
This page took 0.035319 seconds and 4 git commands to generate.