update syscalls
[ltt-control.git] / ltt-control / lttd / lttd.c
index 0deb40230a61007fffc235660d055f19d529e092..638a41c8f3e12d47954d1114df9f6040efbb231d 100644 (file)
@@ -2,8 +2,8 @@
  *
  * Linux Trace Toolkit Daemon
  *
- * This is a simple daemon that reads a few relayfs channels and save them in a
- * trace.
+ * This is a simple daemon that reads a few relay+debugfs channels and save
+ * them in a trace.
  *
  *
  * Copyright 2005 -
 #include <asm/types.h>
 
 /* Get the next sub buffer that can be read. */
-#define RELAYFS_GET_SUBBUF        _IOR(0xF4, 0x00,__u32)
+#define RELAY_GET_SUBBUF        _IOR(0xF4, 0x00,__u32)
 /* Release the oldest reserved (by "get") sub buffer. */
-#define RELAYFS_PUT_SUBBUF        _IOW(0xF4, 0x01,__u32)
+#define RELAY_PUT_SUBBUF        _IOW(0xF4, 0x01,__u32)
 /* returns the number of sub buffers in the per cpu channel. */
-#define RELAYFS_GET_N_SUBBUFS     _IOR(0xF4, 0x02,__u32)
+#define RELAY_GET_N_SUBBUFS     _IOR(0xF4, 0x02,__u32)
 /* returns the size of the sub buffers. */
-#define RELAYFS_GET_SUBBUF_SIZE   _IOR(0xF4, 0x03,__u32)
+#define RELAY_GET_SUBBUF_SIZE   _IOR(0xF4, 0x03,__u32)
 
 
 
@@ -67,17 +67,19 @@ struct channel_trace_fd {
        int num_pairs;
 };
 
-static char *trace_name = NULL;
-static char *channel_name = NULL;
-static int     daemon_mode = 0;
-static int     append_mode = 0;
-static unsigned long num_threads = 1;
+static char            *trace_name = NULL;
+static char            *channel_name = NULL;
+static int             daemon_mode = 0;
+static int             append_mode = 0;
+static unsigned long   num_threads = 1;
 volatile static int    quit_program = 0;       /* For signal handler */
+static int             dump_flight_only = 0;
+static int             dump_normal_only = 0;
 
 /* Args :
  *
  * -t directory                Directory name of the trace to write to. Will be created.
- * -c directory                Root directory of the relayfs trace channels.
+ * -c directory                Root directory of the debugfs trace channels.
  * -d                          Run in background (daemon).
  * -a                                                  Trace append mode.
  * -s                                                  Send SIGUSR1 to parent when ready for IO.
@@ -88,10 +90,12 @@ void show_arguments(void)
        printf("\n");
        printf("-t directory  Directory name of the trace to write to.\n"
                                 "              It will be created.\n");
-       printf("-c directory  Root directory of the relayfs trace channels.\n");
+       printf("-c directory  Root directory of the debugfs trace channels.\n");
        printf("-d            Run in background (daemon).\n");
        printf("-a            Append to an possibly existing trace.\n");
        printf("-N            Number of threads to start.\n");
+       printf("-f            Dump only flight recorder channels.\n");
+       printf("-n            Dump only normal channels.\n");
        printf("\n");
 }
 
@@ -143,6 +147,12 @@ int parse_arguments(int argc, char **argv)
                                                        argn++;
                                                }
                                                break;
+                                       case 'f':
+                                               dump_flight_only = 1;
+                                               break;
+                                       case 'n':
+                                               dump_normal_only = 1;
+                                               break;
                                        default:
                                                printf("Invalid argument '%s'.\n", argv[argn]);
                                                printf("\n");
@@ -174,9 +184,9 @@ int parse_arguments(int argc, char **argv)
 
 void show_info(void)
 {
-       printf("Linux Trace Toolkit Trace Daemon\n");
+       printf("Linux Trace Toolkit Trace Daemon " VERSION "\n");
        printf("\n");
-       printf("Reading from relayfs directory : %s\n", channel_name);
+       printf("Reading from debugfs directory : %s\n", channel_name);
        printf("Writing to trace directory : %s\n", trace_name);
        printf("\n");
 }
@@ -205,12 +215,12 @@ int open_channel_trace_pairs(char *subchannel_name, char *subtrace_name,
        char path_trace[PATH_MAX];
        int path_trace_len;
        char *path_trace_ptr;
-  int open_ret = 0;
+       int open_ret = 0;
 
        if(channel_dir == NULL) {
                perror(subchannel_name);
                open_ret = ENOENT;
-    goto end;
+               goto end;
        }
 
        printf("Creating trace subdirectory %s\n", subtrace_name);
@@ -218,7 +228,7 @@ int open_channel_trace_pairs(char *subchannel_name, char *subtrace_name,
        if(ret == -1) {
                if(errno != EEXIST) {
                        perror(subtrace_name);
-      open_ret = -1;
+                       open_ret = -1;
                        goto end;
                }
        }
@@ -256,6 +266,17 @@ int open_channel_trace_pairs(char *subchannel_name, char *subtrace_name,
                        ret = open_channel_trace_pairs(path_channel, path_trace, fd_pairs);
                        if(ret < 0) continue;
                } else if(S_ISREG(stat_buf.st_mode)) {
+                       if(strncmp(entry->d_name, "flight-", sizeof("flight-")-1) != 0) {
+                               if(dump_flight_only) {
+                                       printf("Skipping normal channel %s\n", path_channel);
+                                       continue;
+                               }
+                       } else {
+                               if(dump_normal_only) {
+                                       printf("Skipping flight channel %s\n", path_channel);
+                                       continue;
+                               }
+                       }
                        printf("Opening file.\n");
                        
                        fd_pairs->pair = realloc(fd_pairs->pair,
@@ -285,7 +306,7 @@ int open_channel_trace_pairs(char *subchannel_name, char *subtrace_name,
                                } else {
                                        printf("File %s exists, cannot open. Try append mode.\n", path_trace);
                                        open_ret = -1;
-          goto end;
+                                       goto end;
                                }
                        } else {
                                if(errno == ENOENT) {
@@ -313,7 +334,7 @@ int read_subbuffer(struct fd_pair *pair)
        int err, ret=0;
 
 
-       err = ioctl(pair->channel, RELAYFS_GET_SUBBUF, 
+       err = ioctl(pair->channel, RELAY_GET_SUBBUF, 
                                                                &consumed_old);
        printf("cookie : %u\n", consumed_old);
        if(err != 0) {
@@ -341,7 +362,7 @@ int read_subbuffer(struct fd_pair *pair)
        }
 #endif //0
 write_error:
-       err = ioctl(pair->channel, RELAYFS_PUT_SUBBUF, &consumed_old);
+       err = ioctl(pair->channel, RELAY_PUT_SUBBUF, &consumed_old);
        if(err != 0) {
                ret = errno;
                if(errno == EFAULT) {
@@ -374,13 +395,13 @@ int map_channels(struct channel_trace_fd *fd_pairs)
        for(i=0;i<fd_pairs->num_pairs;i++) {
                struct fd_pair *pair = &fd_pairs->pair[i];
 
-               ret = ioctl(pair->channel, RELAYFS_GET_N_SUBBUFS, 
+               ret = ioctl(pair->channel, RELAY_GET_N_SUBBUFS, 
                                                        &pair->n_subbufs);
                if(ret != 0) {
                        perror("Error in getting the number of subbuffers");
                        goto end;
                }
-               ret = ioctl(pair->channel, RELAYFS_GET_SUBBUF_SIZE, 
+               ret = ioctl(pair->channel, RELAY_GET_SUBBUF_SIZE, 
                                                        &pair->subbuf_size);
                if(ret != 0) {
                        perror("Error in getting the size of the subbuffers");
@@ -459,7 +480,7 @@ int unmap_channels(struct channel_trace_fd *fd_pairs)
  *
  * Thread worker.
  *
- * Read the relayfs channels and write them in the paired tracefiles.
+ * Read the debugfs channels and write them in the paired tracefiles.
  *
  * @fd_pairs : paired channels and trace files.
  *
@@ -609,12 +630,12 @@ int main(int argc, char ** argv)
 
        if(daemon_mode) {
                ret = daemon(0, 0);
-    
-    if(ret == -1) {
-      perror("An error occured while daemonizing.");
-      exit(-1);
-    }
-  }
+               
+               if(ret == -1) {
+                       perror("An error occured while daemonizing.");
+                       exit(-1);
+               }
+       }
 
        /* Connect the signal handlers */
        act.sa_handler = handler;
This page took 0.026447 seconds and 4 git commands to generate.