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 --start-trace\t\t\tStart tracing\n\
59 --stop-trace\t\t\tStop tracing\n\
60 --destroy-trace\t\t\tDestroy the trace\n\
61 --enable-marker \"CHANNEL/MARKER\"\tEnable a marker\n\
62 --disable-marker \"CHANNEL/MARKER\"\tDisable a marker\n\
63 --list-markers\t\t\tList the markers of the process, their\n\t\t\t\t\t state and format string\n\
68 int parse_opts_long(int argc
, char **argv
, struct ust_opts
*opts
)
74 opts
->regex_state
= -1;
78 static struct option long_options
[] = {
79 {"start-trace", 0, 0, 1000},
80 {"stop-trace", 0, 0, 1001},
81 {"destroy-trace", 0, 0, 1002},
82 {"list-markers", 0, 0, 1004},
83 {"print-markers", 0, 0, 1005},
85 {"enable-marker", 1, 0, 1007},
86 {"disable-marker", 1, 0, 1008},
87 {"start", 0, 0, 1009},
89 {"version", 0, 0, 1010},
90 {"online-pids", 0, 0, 1011},
94 c
= getopt_long(argc
, argv
, "h", long_options
, &option_index
);
100 printf("option %s", long_options
[option_index
].name
);
102 printf(" with arg %s", optarg
);
107 opts
->cmd
= START_TRACE
;
110 opts
->cmd
= STOP_TRACE
;
119 opts
->cmd
= LIST_MARKERS
;
122 opts
->cmd
= ENABLE_MARKER
;
123 opts
->regex
= strdup(optarg
);
126 opts
->cmd
= DISABLE_MARKER
;
127 opts
->regex
= strdup(optarg
);
130 opts
->cmd
= GET_ONLINE_PIDS
;
136 printf("Version 0.1\n");
139 /* unknown option or other error; error is
140 printed by getopt, just return */
146 if (argc
- optind
> 0 && opts
->cmd
!= GET_ONLINE_PIDS
) {
149 opts
->pids
= malloc((argc
-optind
+1) * sizeof(pid_t
));
151 for(i
=optind
; i
<argc
; i
++) {
152 opts
->pids
[pididx
++] = atoi(argv
[i
]);
154 opts
->pids
[pididx
] = -1;
157 if (opts
->cmd
== ENABLE_MARKER
|| opts
->cmd
== DISABLE_MARKER
) {
158 if (opts
->regex_state
= regcomp(&opts
->preg
, opts
->regex
, 0)) {
159 fprintf(stderr
, "Invalid regular expression.\n");
166 static void regex_change_m_state(struct ust_opts
* opts
, pid_t pid
) {
167 struct USTcmd_cmsf
* cmsf
= NULL
;
169 int e
= (opts
->cmd
== ENABLE_MARKER
);
171 if (opts
->regex_state
!= 0) {
175 if (ustcmd_get_cmsf(&cmsf
, pid
)) {
176 fprintf(stderr
, "error while trying to get markers for PID "
177 "%u\n", (unsigned int) pid
);
180 while (cmsf
[i
].channel
!= NULL
) {
182 asprintf(&mc
, "%s/%s", cmsf
[i
].channel
, cmsf
[i
].marker
);
183 if (regexec(&opts
->preg
, mc
, 0, NULL
, 0) == 0) {
184 /* We got a match! */
185 if (ustcmd_set_marker_state(mc
,
186 e
? USTCMD_MS_ON
: USTCMD_MS_OFF
, pid
)) {
188 "error while trying to %sable marker"
189 "\"%s\" for PID %u\n",
190 e
? "en" : "dis", mc
,
193 printf("sucessfully %sabled marker "
194 "\"%s\" for PID %u\n",
195 e
? "en" : "dis", mc
,
202 ustcmd_free_cmsf(cmsf
);
205 int main(int argc
, char *argv
[])
208 struct ustcomm_connection conn
;
210 struct ust_opts opts
;
215 fprintf(stderr
, "No operation specified.\n");
220 result
= parse_opts_long(argc
, argv
, &opts
);
226 if(opts
.pids
== NULL
&& opts
.cmd
!= GET_ONLINE_PIDS
) {
227 fprintf(stderr
, "No pid specified.\n");
231 if(opts
.cmd
== UNKNOWN
) {
232 fprintf(stderr
, "No command specified.\n");
236 if (opts
.cmd
== GET_ONLINE_PIDS
) {
237 pid_t
* pp
= ustcmd_get_online_pids();
242 printf("%u\n", (unsigned int) pp
[i
]);
252 struct USTcmd_cmsf
* cmsf
= NULL
;
254 while(*pidit
!= -1) {
257 if (ustcmd_start_trace(*pidit
)) {
259 "error while trying to for trace "
260 "with PID %u\n", (unsigned int) *pidit
);
263 printf("sucessfully started trace for PID %u\n",
264 (unsigned int) *pidit
);
268 if (ustcmd_stop_trace(*pidit
)) {
270 "error while trying to stop trace "
271 "for PID %u\n", (unsigned int) *pidit
);
274 printf("sucessfully stopped trace for PID %u\n",
275 (unsigned int) *pidit
);
279 if (ustcmd_setup_and_start(*pidit
)) {
281 "error while trying to setup/start "
282 "trace for PID %u\n",
283 (unsigned int) *pidit
);
286 printf("sucessfully setup/started trace for PID %u\n",
287 (unsigned int) *pidit
);
291 if (ustcmd_destroy_trace(*pidit
)) {
293 "error while trying to destroy "
294 "trace with PID %u\n",
295 (unsigned int) *pidit
);
298 printf("sucessfully destroyed trace for PID %u\n",
299 (unsigned int) *pidit
);
304 if (ustcmd_get_cmsf(&cmsf
, *pidit
)) {
306 "error while trying to list markers for"
307 " PID %u\n", (unsigned int) *pidit
);
311 while (cmsf
[i
].channel
!= NULL
) {
312 printf("{PID: %u, channel/marker: %s/%s, "
313 "state: %u, fs: %s}\n",
314 (unsigned int) *pidit
,
321 ustcmd_free_cmsf(cmsf
);
326 regex_change_m_state(&opts
, *pidit
);
330 fprintf(stderr
, "error: unknown command...\n");
338 if (opts
.pids
!= NULL
) {
341 if (opts
.regex
!= NULL
) {
This page took 0.039293 seconds and 5 git commands to generate.