3 * Linux Trace Toolkit Control
5 * Small program that controls LTT through libltt.
8 * Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
15 #include <libltt/libltt.h>
19 #include <sys/types.h>
33 static char *trace_name
= NULL
;
34 static char *mode_name
= NULL
;
35 static unsigned subbuf_size
= 0;
36 static unsigned n_subbufs
= 0;
37 static enum trace_mode mode
= LTT_TRACE_NORMAL
;
38 static enum trace_ctl_op op
= CTL_OP_NONE
;
39 static char *channel_root
= NULL
;
40 static char *trace_root
= NULL
;
41 static unsigned alignment
= 0;
43 static int sigio_received
= 0;
45 void handler(int signo
)
47 printf("signal %d received\n", signo
);
55 void show_arguments(void)
57 printf("Please use the following arguments :\n");
59 printf("-n name Name of the trace.\n");
60 printf("-c mode Create trace channels in mode normal or flight recorder.\n");
61 printf(" Mode values : normal (default) or flight.\n");
62 printf("-r Destroy trace channels.\n");
63 printf("-s Start tracing.\n");
64 //printf(" Note : will automatically create a normal trace if "
66 printf("-q Stop tracing.\n");
67 printf("-d Create trace, spawn a lttd daemon, start tracing.\n");
68 printf(" (optionnaly, you can set LTT_DAEMON env. var.)\n");
69 printf("-t Trace root path. (ex. /root/traces/example_trace)\n");
70 printf("-l LTT channels root path. (ex. /mnt/relayfs/ltt)\n");
71 printf("-a Alignment of a new or existing trace\n");
72 printf("-z Size of the subbuffers\n");
73 printf("-x Number of subbuffers\n");
80 * Parses the command line arguments.
82 * Returns 1 if the arguments were correct, but doesn't ask for program
83 * continuation. Returns -1 if the arguments are incorrect, or 0 if OK.
85 int parse_arguments(int argc
, char **argv
)
91 if(strcmp(argv
[1], "-h") == 0) {
98 switch(argv
[argn
][0]) {
100 switch(argv
[argn
][1]) {
103 trace_name
= argv
[argn
+1];
106 printf("Specify a trace name after -n.\n", argv
[argn
]);
115 mode_name
= argv
[argn
+1];
117 if(strcmp(mode_name
, "normal") == 0)
118 mode
= LTT_TRACE_NORMAL
;
119 else if(strcmp(mode_name
, "flight") == 0)
120 mode
= LTT_TRACE_FLIGHT
;
122 printf("Invalid mode '%s'.\n", argv
[argn
]);
127 printf("Specify a mode after -c.\n");
142 if(op
== CTL_OP_NONE
) op
= CTL_OP_ALIGN
;
144 alignment
= (unsigned)atoi(argv
[argn
+1]);
147 printf("Specify an alignment after -a.\n");
154 subbuf_size
= (unsigned)atoi(argv
[argn
+1]);
157 printf("Specify a number of subbuffers after -z.\n");
164 n_subbufs
= (unsigned)atoi(argv
[argn
+1]);
167 printf("Specify a subbuffer size after -x.\n");
177 trace_root
= argv
[argn
+1];
180 printf("Specify a trace root path after -t.\n");
187 channel_root
= argv
[argn
+1];
190 printf("Specify a channel root path after -l.\n");
196 printf("Invalid argument '%s'.\n", argv
[argn
]);
202 printf("Invalid argument '%s'.\n", argv
[argn
]);
209 if(trace_name
== NULL
) {
210 printf("Please specify a trace name.\n");
215 if(op
== CTL_OP_NONE
) {
216 printf("Please specify an operation.\n");
221 if(op
== CTL_OP_DAEMON
) {
222 if(trace_root
== NULL
) {
223 printf("Please specify -t trace_root_path with the -d option.\n");
227 if(channel_root
== NULL
) {
228 printf("Please specify -l ltt_root_path with the -d option.\n");
239 printf("Linux Trace Toolkit Trace Control\n");
241 printf("Controlling trace : %s\n", trace_name
);
245 int lttctl_daemon(struct lttctl_handle
*handle
, char *trace_name
)
247 char channel_path
[PATH_MAX
] = "";
250 char *lttd_path
= getenv("LTT_DAEMON");
251 struct sigaction act
;
253 if(lttd_path
== NULL
) lttd_path
= "lttd";
255 strcat(channel_path
, channel_root
);
256 strcat(channel_path
, "/");
257 strcat(channel_path
, trace_name
);
260 ret
= lttctl_create_trace(handle
, trace_name
, mode
, subbuf_size
, n_subbufs
);
261 if(ret
!= 0) goto create_error
;
263 act
.sa_handler
= handler
;
264 sigemptyset(&(act
.sa_mask
));
265 sigaddset(&(act
.sa_mask
), SIGIO
);
266 sigaction(SIGIO
, &act
, NULL
);
274 while(!sigio_received
) pause();
276 /* Now the trace is created, go on and create the supplementary files... */
277 printf("Creating supplementary trace files\n");
279 } else if(pid
== 0) {
282 execlp(lttd_path
, lttd_path
, "-t", trace_root
, "-c", channel_path
, "-s", NULL
);
284 perror("Error in executing the lttd daemon");
289 perror("Error in forking for lttd daemon");
293 ret
= lttctl_start(handle
, trace_name
);
294 if(ret
!= 0) goto start_error
;
300 ret
|= lttctl_destroy_trace(handle
, trace_name
);
305 int main(int argc
, char ** argv
)
308 struct lttctl_handle
*handle
;
310 ret
= parse_arguments(argc
, argv
);
312 if(ret
!= 0) show_arguments();
313 if(ret
< 0) return EINVAL
;
314 if(ret
> 0) return 0;
318 handle
= lttctl_create_handle();
320 if(handle
== NULL
) return -1;
324 ret
= lttctl_create_trace(handle
, trace_name
, mode
, subbuf_size
,
328 ret
= lttctl_destroy_trace(handle
, trace_name
);
331 ret
= lttctl_start(handle
, trace_name
);
334 ret
= lttctl_stop(handle
, trace_name
);
337 ret
= lttctl_daemon(handle
, trace_name
);
343 ret
|= lttctl_destroy_handle(handle
);
This page took 0.036369 seconds and 4 git commands to generate.