4 * Linux Trace Toolkit Daemon
6 * This is a simple daemon that reads a few LTTng debugfs channels and saves
7 * them in a trace on the virtual file system.
9 * CPU hot-plugging is supported using inotify.
11 * Copyright 2009-2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
12 * Copyright 2010 - Michael Sills-Lavoie <michael.sills-lavoie@polymtl.ca>
13 * Copyright 2010 - Oumarou Dicko <oumarou.dicko@polymtl.ca>
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License along
26 * with this program; if not, write to the Free Software Foundation, Inc.,
27 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
42 #include <liblttd/liblttd.h>
43 #include <liblttd/liblttdvfs.h>
45 struct liblttd_instance
* instance
;
47 static char *trace_name
= NULL
;
48 static char *channel_name
= NULL
;
49 static int daemon_mode
= 0;
50 static int append_mode
= 0;
51 static unsigned long num_threads
= 1;
52 static int dump_flight_only
= 0;
53 static int dump_normal_only
= 0;
54 static int verbose_mode
= 0;
59 * -t directory Directory name of the trace to write to. Will be created.
60 * -c directory Root directory of the debugfs trace channels.
61 * -d Run in background (daemon).
62 * -a Trace append mode.
63 * -s Send SIGUSR1 to parent when ready for IO.
65 void show_arguments(void)
67 printf("Please use the following arguments :\n");
69 printf("-t directory Directory name of the trace to write to.\n"
70 " It will be created.\n");
71 printf("-c directory Root directory of the debugfs trace channels.\n");
72 printf("-d Run in background (daemon).\n");
73 printf("-a Append to an possibly existing trace.\n");
74 printf("-N Number of threads to start.\n");
75 printf("-f Dump only flight recorder channels.\n");
76 printf("-n Dump only normal channels.\n");
77 printf("-v Verbose mode.\n");
84 * Parses the command line arguments.
86 * Returns 1 if the arguments were correct, but doesn't ask for program
87 * continuation. Returns -1 if the arguments are incorrect, or 0 if OK.
89 int parse_arguments(int argc
, char **argv
)
95 if(strcmp(argv
[1], "-h") == 0) {
102 switch(argv
[argn
][0]) {
104 switch(argv
[argn
][1]) {
107 trace_name
= argv
[argn
+1];
113 channel_name
= argv
[argn
+1];
125 num_threads
= strtoul(argv
[argn
+1], NULL
, 0);
130 dump_flight_only
= 1;
133 dump_normal_only
= 1;
139 printf("Invalid argument '%s'.\n", argv
[argn
]);
145 printf("Invalid argument '%s'.\n", argv
[argn
]);
152 if(trace_name
== NULL
) {
153 printf("Please specify a trace name.\n");
158 if(channel_name
== NULL
) {
159 printf("Please specify a channel name.\n");
169 printf("Linux Trace Toolkit Trace Daemon " VERSION
"\n");
171 printf("Reading from debugfs directory : %s\n", channel_name
);
172 printf("Writing to trace directory : %s\n", trace_name
);
177 /* signal handling */
179 static void handler(int signo
)
181 printf("Signal %d received : exiting cleanly\n", signo
);
182 liblttd_stop_instance(instance
);
185 int main(int argc
, char ** argv
)
188 struct sigaction act
;
190 ret
= parse_arguments(argc
, argv
);
192 if(ret
!= 0) show_arguments();
193 if(ret
< 0) return EINVAL
;
194 if(ret
> 0) return 0;
198 /* Connect the signal handlers */
199 act
.sa_handler
= handler
;
201 sigemptyset(&(act
.sa_mask
));
202 sigaddset(&(act
.sa_mask
), SIGTERM
);
203 sigaddset(&(act
.sa_mask
), SIGQUIT
);
204 sigaddset(&(act
.sa_mask
), SIGINT
);
205 sigaction(SIGTERM
, &act
, NULL
);
206 sigaction(SIGQUIT
, &act
, NULL
);
207 sigaction(SIGINT
, &act
, NULL
);
213 perror("An error occured while daemonizing.");
218 struct liblttd_callbacks
* callbacks
=
219 liblttdvfs_new_callbacks(trace_name
, append_mode
, verbose_mode
);
221 instance
= liblttd_new_instance(callbacks
, channel_name
, num_threads
,
222 dump_flight_only
, dump_normal_only
,
226 perror("An error occured while creating the liblttd instance");
230 liblttd_start_instance(instance
);
This page took 0.033288 seconds and 4 git commands to generate.