1eeb1b1201adeb7b1fbca5c86653252b83a5d596
3 * Linux Trace Toolkit Control
5 * Small program that controls LTT through libltt.
8 * Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
11 #include <libltt/libltt.h>
15 #include <sys/types.h>
28 static char *trace_name
= NULL
;
29 static char *mode_name
= NULL
;
30 static enum trace_mode mode
= LTT_TRACE_NORMAL
;
31 static enum trace_ctl_op op
= CTL_OP_NONE
;
32 static char *channel_root
= NULL
;
33 static char *trace_root
= NULL
;
35 void handler(int signo
)
37 printf("signal %d received\n", signo
);
44 void show_arguments(void)
46 printf("Please use the following arguments :\n");
48 printf("-n name Name of the trace.\n");
49 printf("-c mode Create trace channels in mode normal or flight recorder.\n");
50 printf(" Mode values : normal (default) or flight.\n");
51 printf("-r Destroy trace channels.\n");
52 printf("-s Start tracing.\n");
53 //printf(" Note : will automatically create a normal trace if "
55 printf("-q Stop tracing.\n");
56 printf("-d Create trace, spawn a lttd daemon, start tracing.\n");
57 printf(" (optionnaly, you can set LTT_DAEMON env. var.)\n");
58 printf("-t Trace root path. (ex. /root/traces/example_trace)\n");
59 printf("-l LTT channels root path. (ex. /mnt/relayfs/ltt)\n");
66 * Parses the command line arguments.
68 * Returns 1 if the arguments were correct, but doesn't ask for program
69 * continuation. Returns -1 if the arguments are incorrect, or 0 if OK.
71 int parse_arguments(int argc
, char **argv
)
77 if(strcmp(argv
[1], "-h") == 0) {
84 switch(argv
[argn
][0]) {
86 switch(argv
[argn
][1]) {
89 trace_name
= argv
[argn
+1];
92 printf("Specify a trace name after -n.\n", argv
[argn
]);
101 mode_name
= argv
[argn
+1];
103 if(strcmp(mode_name
, "normal") == 0)
104 mode
= LTT_TRACE_NORMAL
;
105 else if(strcmp(mode_name
, "flight") == 0)
106 mode
= LTT_TRACE_FLIGHT
;
108 printf("Invalid mode '%s'.\n", argv
[argn
]);
113 printf("Specify a mode after -c.\n", argv
[argn
]);
132 trace_root
= argv
[argn
+1];
135 printf("Specify a trace root path after -t.\n", argv
[argn
]);
142 channel_root
= argv
[argn
+1];
145 printf("Specify a channel root path after -l.\n", argv
[argn
]);
151 printf("Invalid argument '%s'.\n", argv
[argn
]);
157 printf("Invalid argument '%s'.\n", argv
[argn
]);
164 if(trace_name
== NULL
) {
165 printf("Please specify a trace name.\n");
170 if(op
== CTL_OP_NONE
) {
171 printf("Please specify an operation.\n");
176 if(op
== CTL_OP_DAEMON
) {
177 if(trace_root
== NULL
) {
178 printf("Please specify -t trace_root_path with the -d option.\n");
182 if(channel_root
== NULL
) {
183 printf("Please specify -l ltt_root_path with the -d option.\n");
194 printf("Linux Trace Toolkit Trace Control\n");
196 printf("Controlling trace : %s\n", trace_name
);
200 int lttctl_daemon(struct lttctl_handle
*handle
, char *trace_name
)
202 char channel_path
[PATH_MAX
] = "";
205 char *lttd_path
= getenv("LTT_DAEMON");
206 struct sigaction act
;
208 if(lttd_path
== NULL
) lttd_path
= "lttd";
210 strcat(channel_path
, channel_root
);
211 strcat(channel_path
, "/");
212 strcat(channel_path
, trace_name
);
215 ret
= lttctl_create_trace(handle
, trace_name
, mode
);
216 if(ret
!= 0) goto create_error
;
218 act
.sa_handler
= handler
;
219 sigemptyset(&(act
.sa_mask
));
220 sigaddset(&(act
.sa_mask
), SIGIO
);
221 sigaction(SIGIO
, &act
, NULL
);
230 /* Now the trace is created, go on and create the supplementary files... */
231 printf("Creating supplementary trace files\n");
233 } else if(pid
== 0) {
236 execlp(lttd_path
, lttd_path
, "-t", trace_root
, "-c", channel_path
, "-s", NULL
);
238 perror("Error in executing the lttd daemon");
243 perror("Error in forking for lttd daemon");
247 ret
= lttctl_start(handle
, trace_name
);
248 if(ret
!= 0) goto start_error
;
254 ret
|= lttctl_destroy_trace(handle
, trace_name
);
259 int main(int argc
, char ** argv
)
262 struct lttctl_handle
*handle
;
264 ret
= parse_arguments(argc
, argv
);
266 if(ret
!= 0) show_arguments();
267 if(ret
< 0) return EINVAL
;
268 if(ret
> 0) return 0;
272 handle
= lttctl_create_handle();
274 if(handle
== NULL
) return -1;
278 ret
= lttctl_create_trace(handle
, trace_name
, mode
);
281 ret
= lttctl_destroy_trace(handle
, trace_name
);
284 ret
= lttctl_start(handle
, trace_name
);
287 ret
= lttctl_stop(handle
, trace_name
);
290 ret
= lttctl_daemon(handle
, trace_name
);
296 ret
|= lttctl_destroy_handle(handle
);
This page took 0.035699 seconds and 4 git commands to generate.