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>
32 static char *trace_name
= NULL
;
33 static char *mode_name
= NULL
;
34 static unsigned subbuf_size
= 0;
35 static unsigned n_subbufs
= 0;
36 static enum trace_mode mode
= LTT_TRACE_NORMAL
;
37 static enum trace_ctl_op op
= CTL_OP_NONE
;
38 static char *channel_root
= NULL
;
39 static char *trace_root
= NULL
;
41 static int sigio_received
= 0;
43 void handler(int signo
)
45 printf("signal %d received\n", signo
);
53 void show_arguments(void)
55 printf("Please use the following arguments :\n");
57 printf("-n name Name of the trace.\n");
58 printf("-c mode Create trace channels in mode normal or flight recorder.\n");
59 printf(" Mode values : normal (default) or flight.\n");
60 printf("-r Destroy trace channels.\n");
61 printf("-s Start tracing.\n");
62 //printf(" Note : will automatically create a normal trace if "
64 printf("-q Stop tracing.\n");
65 printf("-d Create trace, spawn a lttd daemon, start tracing.\n");
66 printf(" (optionnaly, you can set LTT_DAEMON env. var.)\n");
67 printf("-t Trace root path. (ex. /root/traces/example_trace)\n");
68 printf("-l LTT channels root path. (ex. /mnt/relayfs/ltt)\n");
69 printf("-z Size of the subbuffers (will be rounded to next page size)\n");
70 printf("-x Number of subbuffers\n");
77 * Parses the command line arguments.
79 * Returns 1 if the arguments were correct, but doesn't ask for program
80 * continuation. Returns -1 if the arguments are incorrect, or 0 if OK.
82 int parse_arguments(int argc
, char **argv
)
88 if(strcmp(argv
[1], "-h") == 0) {
95 switch(argv
[argn
][0]) {
97 switch(argv
[argn
][1]) {
100 trace_name
= argv
[argn
+1];
103 printf("Specify a trace name after -n.\n", argv
[argn
]);
112 mode_name
= argv
[argn
+1];
114 if(strcmp(mode_name
, "normal") == 0)
115 mode
= LTT_TRACE_NORMAL
;
116 else if(strcmp(mode_name
, "flight") == 0)
117 mode
= LTT_TRACE_FLIGHT
;
119 printf("Invalid mode '%s'.\n", argv
[argn
]);
124 printf("Specify a mode after -c.\n");
140 subbuf_size
= (unsigned)atoi(argv
[argn
+1]);
143 printf("Specify a number of subbuffers after -z.\n");
150 n_subbufs
= (unsigned)atoi(argv
[argn
+1]);
153 printf("Specify a subbuffer size after -x.\n");
163 trace_root
= argv
[argn
+1];
166 printf("Specify a trace root path after -t.\n");
173 channel_root
= argv
[argn
+1];
176 printf("Specify a channel root path after -l.\n");
182 printf("Invalid argument '%s'.\n", argv
[argn
]);
188 printf("Invalid argument '%s'.\n", argv
[argn
]);
195 if(trace_name
== NULL
) {
196 printf("Please specify a trace name.\n");
201 if(op
== CTL_OP_NONE
) {
202 printf("Please specify an operation.\n");
207 if(op
== CTL_OP_DAEMON
) {
208 if(trace_root
== NULL
) {
209 printf("Please specify -t trace_root_path with the -d option.\n");
213 if(channel_root
== NULL
) {
214 printf("Please specify -l ltt_root_path with the -d option.\n");
225 printf("Linux Trace Toolkit Trace Control\n");
227 printf("Controlling trace : %s\n", trace_name
);
231 int lttctl_daemon(struct lttctl_handle
*handle
, char *trace_name
)
233 char channel_path
[PATH_MAX
] = "";
236 char *lttd_path
= getenv("LTT_DAEMON");
237 struct sigaction act
;
239 if(lttd_path
== NULL
) lttd_path
= "lttd";
241 strcat(channel_path
, channel_root
);
242 strcat(channel_path
, "/");
243 strcat(channel_path
, trace_name
);
246 ret
= lttctl_create_trace(handle
, trace_name
, mode
, subbuf_size
, n_subbufs
);
247 if(ret
!= 0) goto create_error
;
249 act
.sa_handler
= handler
;
250 sigemptyset(&(act
.sa_mask
));
251 sigaddset(&(act
.sa_mask
), SIGIO
);
252 sigaction(SIGIO
, &act
, NULL
);
260 while(!sigio_received
) pause();
262 /* Now the trace is created, go on and create the supplementary files... */
263 printf("Creating supplementary trace files\n");
265 } else if(pid
== 0) {
268 execlp(lttd_path
, lttd_path
, "-t", trace_root
, "-c", channel_path
, "-s", NULL
);
270 perror("Error in executing the lttd daemon");
275 perror("Error in forking for lttd daemon");
279 ret
= lttctl_start(handle
, trace_name
);
280 if(ret
!= 0) goto start_error
;
286 ret
|= lttctl_destroy_trace(handle
, trace_name
);
291 int main(int argc
, char ** argv
)
294 struct lttctl_handle
*handle
;
296 ret
= parse_arguments(argc
, argv
);
298 if(ret
!= 0) show_arguments();
299 if(ret
< 0) return EINVAL
;
300 if(ret
> 0) return 0;
304 handle
= lttctl_create_handle();
306 if(handle
== NULL
) return -1;
310 ret
= lttctl_create_trace(handle
, trace_name
, mode
, subbuf_size
,
313 ret
= lttctl_destroy_trace(handle
, trace_name
);
316 ret
= lttctl_start(handle
, trace_name
);
319 ret
= lttctl_stop(handle
, trace_name
);
322 ret
= lttctl_daemon(handle
, trace_name
);
328 ret
|= lttctl_destroy_handle(handle
);
This page took 0.043707 seconds and 4 git commands to generate.