fixed dependency on private headers
[lttv.git] / ltt / branches / yangxx / convert / convert.c
index b16e8fe353d52185ae40c6f26576645f5b957cce..2b79d5d555b593296c6e6c20a5045e0eae0f9ec7 100644 (file)
@@ -87,10 +87,22 @@ int main(int argc, char ** argv){
   int i,j;
 
   uint8_t cpu_id;
+
+  char foo[4*BUFFER_SIZE];
+  char foo_eventdefs[4*BUFFER_SIZE];
+  char foo_control[4*BUFFER_SIZE];
+  char foo_cpu[4*BUFFER_SIZE];
+  char foo_info[4*BUFFER_SIZE];
+
+  char foo_control_facilities[4*BUFFER_SIZE];
+  char foo_control_processes[4*BUFFER_SIZE];
+  char foo_control_interrupts[4*BUFFER_SIZE];
+  char foo_info_system[4*BUFFER_SIZE];
+
   struct stat      lTDFStat;   
   off_t file_size;                  
   int block_number, block_size;                 
-  char * buffer, **buf_out, cpuStr[BUFFER_SIZE];
+  char * buffer, **buf_out, cpuStr[4*BUFFER_SIZE];
   char * buf_fac, * buf_intr, * buf_proc;
   void ** write_pos, *write_pos_fac, * write_pos_intr, *write_pos_proc;
   trace_start *tStart;
@@ -105,16 +117,41 @@ int main(int argc, char ** argv){
   buffer_start end;
   heartbeat beat;
   int beat_count = 0;
-  int *size_count;
   gboolean * has_event;
   uint32_t size_lost;
   int reserve_size = sizeof(buffer_start) + sizeof(uint16_t) + 2*sizeof(uint32_t);//lost_size and buffer_end event
 
-  if(argc != 3){
-    printf("need a trace file and cpu number\n");
+  if(argc != 3 && argc != 4){
+    printf("need a trace file and cpu number or root directory for the new tracefile\n");
     exit(1);
   }
 
+  if(argc == 3){
+    strcpy(foo, "foo");
+    strcpy(foo_eventdefs, "foo/eventdefs");
+    strcpy(foo_control, "foo/control");
+    strcpy(foo_cpu, "foo/cpu");
+    strcpy(foo_info, "foo/info");
+  }else{
+    strcpy(foo, argv[3]);
+    strcpy(foo_eventdefs, argv[3]);
+    strcat(foo_eventdefs,"/eventdefs");
+    strcpy(foo_control, argv[3]);
+    strcat(foo_control,"/control");
+    strcpy(foo_cpu, argv[3]);
+    strcat(foo_cpu,"/cpu");
+    strcpy(foo_info, argv[3]);
+    strcat(foo_info,"/info");
+  }
+  strcpy(foo_control_facilities, foo_control);
+  strcat(foo_control_facilities,"/facilities");
+  strcpy(foo_control_processes, foo_control);
+  strcat(foo_control_processes, "/processes");
+  strcpy(foo_control_interrupts, foo_control);
+  strcat(foo_control_interrupts, "/interrupts");
+  strcpy(foo_info_system, foo_info);
+  strcat(foo_info_system, "/system.xml");
+
   cpu = atoi(argv[2]);
   printf("cpu number = %d\n", cpu);
 
@@ -161,13 +198,18 @@ int main(int argc, char ** argv){
   }
   fclose(fp);
 
-  if(mkdir("foo", S_IFDIR | S_IRWXU | S_IRGRP |  S_IROTH)) g_error("can not make foo directory");
-  if(mkdir("foo/info", S_IFDIR | S_IRWXU | S_IRGRP |  S_IROTH)) g_error("can not make foo/info directory");
-  if(mkdir("foo/cpu", S_IFDIR | S_IRWXU | S_IRGRP |  S_IROTH)) g_error("can not make foo/cpu directory");
-  if(mkdir("foo/control", S_IFDIR | S_IRWXU | S_IRGRP |  S_IROTH)) g_error("can not make foo/control directory");
-  if(mkdir("foo/eventdefs", S_IFDIR | S_IRWXU | S_IRGRP |  S_IROTH)) g_error("can not make foo/eventdefs directory");
+  if(mkdir(foo, S_IFDIR | S_IRWXU | S_IRGRP |  S_IROTH)) 
+    g_error("can not make %s directory", foo);
+  if(mkdir(foo_info, S_IFDIR | S_IRWXU | S_IRGRP |  S_IROTH)) 
+    g_error("can not make %s directory", foo_info);
+  if(mkdir(foo_cpu, S_IFDIR | S_IRWXU | S_IRGRP |  S_IROTH)) 
+    g_error("can not make %s directory", foo_cpu);
+  if(mkdir(foo_control, S_IFDIR | S_IRWXU | S_IRGRP |  S_IROTH)) 
+    g_error("can not make %s directory", foo_control);
+  if(mkdir(foo_eventdefs, S_IFDIR | S_IRWXU | S_IRGRP |  S_IROTH)) 
+    g_error("can not make %s directory", foo_eventdefs);
   
-  fp = fopen("foo/info/system.xml","w");
+  fp = fopen(foo_info_system,"w");
   if(!fp){
     g_error("Unable to open file system.xml\n");
   }
@@ -177,15 +219,15 @@ int main(int argc, char ** argv){
     g_error("Unable to open input data file %s\n", argv[1]);
   }
 
-  fdFac = open("foo/control/facilities",O_CREAT | O_RDWR | O_TRUNC,S_IRUSR |S_IWUSR | S_IRGRP | S_IROTH);
+  fdFac = open(foo_control_facilities,O_CREAT | O_RDWR | O_TRUNC,S_IRUSR |S_IWUSR | S_IRGRP | S_IROTH);
   if(fdFac < 0){
     g_error("Unable to open file facilities\n");
   }
-  fdIntr = open("foo/control/interrupts",O_CREAT | O_RDWR | O_TRUNC,S_IRUSR |S_IWUSR | S_IRGRP | S_IROTH);
+  fdIntr = open(foo_control_interrupts,O_CREAT | O_RDWR | O_TRUNC,S_IRUSR |S_IWUSR | S_IRGRP | S_IROTH);
   if(fdIntr<0){
     g_error("Unable to open file interrupts\n");
   }
-  fdProc = open("foo/control/processes",O_CREAT | O_RDWR | O_TRUNC,S_IRUSR |S_IWUSR | S_IRGRP | S_IROTH);
+  fdProc = open(foo_control_processes,O_CREAT | O_RDWR | O_TRUNC,S_IRUSR |S_IWUSR | S_IRGRP | S_IROTH);
   if(fdIntr<0){
     g_error("Unable to open file process\n");
   }
@@ -243,14 +285,13 @@ int main(int argc, char ** argv){
   buf_out    = g_new(char*,cpu);
   write_pos  = g_new(void*, cpu);
   fdCpu      = g_new(int, cpu); 
-  size_count = g_new(int, cpu);
   has_event  = g_new(gboolean, cpu);
   for(i=0;i<cpu;i++){
     has_event[i] = FALSE;
     if(i==0)has_event[i] = TRUE;
     buf_out[i] = g_new(char, block_size);
     write_pos[i] = NULL;;
-    sprintf(cpuStr,"foo/cpu/%d\0",i);
+    sprintf(cpuStr,"%s/%d\0",foo_cpu,i);
     fdCpu[i] = open(cpuStr, O_CREAT | O_RDWR | O_TRUNC,S_IRUSR |S_IWUSR | S_IRGRP | S_IROTH); //for cpu i
     if(fdCpu[i] < 0)  g_error("Unable to open  cpu file %d\n", i);    
   }
@@ -262,11 +303,18 @@ int main(int argc, char ** argv){
     beat_count = 0;
 
     for(j=1;j<cpu;j++)has_event[j] = FALSE;
-    for(j=0;j<cpu;j++) write_pos[j] = buf_out[j];
+    for(j=0;j<cpu;j++){
+      memset((void*)buf_out[j], 0, block_size);
+      write_pos[j] = buf_out[j];
+    }
+    memset((void*)buf_intr, 0, block_size);    
+    memset((void*)buf_fac, 0, block_size);    
+    memset((void*)buf_proc, 0, block_size);    
     write_pos_intr = buf_intr;
     write_pos_fac = buf_fac;
     write_pos_proc = buf_proc;
 
+    memset((void*)buffer,0,block_size); 
     readFile(fd,(void*)buffer, block_size, "Unable to read block header");
 
     cur_pos= buffer;
@@ -291,7 +339,11 @@ int main(int argc, char ** argv){
     size_lost = *(uint32_t*)(end_pos - sizeof(uint32_t));
 
     end_pos = buffer + block_size - size_lost ; //buffer_end event
-    tBufEnd = (trace_buffer_end*)(end_pos+sizeof(uint8_t)+sizeof(uint32_t));
+    if(ltt_log_cpu){
+      tBufEnd = (trace_buffer_end*)(end_pos + 2 * sizeof(uint8_t)+sizeof(uint32_t));
+    }else{
+      tBufEnd = (trace_buffer_end*)(end_pos+sizeof(uint8_t)+sizeof(uint32_t));
+    }
     end.seconds = tBufEnd->Time.tv_sec;
     end.nanoseconds = tBufEnd->Time.tv_usec;
     end.cycle_count = tBufEnd->TSC;
@@ -302,9 +354,6 @@ int main(int argc, char ** argv){
     else //other blocks
       cur_pos = buffer + sizeof(trace_buffer_start) + sizeof(uint8_t)+sizeof(uint16_t)+sizeof(uint32_t);
 
-    for(j=0;j<cpu;j++)
-      size_count[j] = sizeof(buffer_start) + sizeof(uint16_t) + sizeof(uint32_t);
-
     //for cpu 0, always make records
     write_to_buffer(write_pos[0],(void*)&startId, sizeof(uint16_t));    
     write_to_buffer(write_pos[0],(void*)&startTimeDelta, sizeof(uint32_t));
@@ -335,6 +384,9 @@ int main(int argc, char ** argv){
       }
       evId = *(uint8_t *)cur_pos;
       newId = evId;
+      if(evId == TRACE_HEARTBEAT) {
+       newId = 19;
+      }
       cur_pos += sizeof(uint8_t);
       time_delta = *(uint32_t*)cur_pos;
       cur_pos += sizeof(uint32_t); 
@@ -354,14 +406,14 @@ int main(int argc, char ** argv){
            write_to_buffer(write_pos[cpu_id],(void*)&end,sizeof(buffer_start));
          for(i=0;i<cpu;i++){
            if(has_event[i]){
-             size = block_size - size_count[i];
+             size = block_size + ((void*)buf_out[i] - write_pos[i])+ sizeof(uint16_t) + sizeof(uint32_t);
              write_pos[i] = buf_out[i] + block_size - sizeof(uint32_t);
              write_to_buffer(write_pos[i],(void*)&size, sizeof(uint32_t));
              write(fdCpu[i],(void*)buf_out[i], block_size);        
            }
          }
        }else {
-         int size = block_size - size_count[0];
+         int size = block_size + ((void*)buf_out[0] - write_pos[0])+ sizeof(uint16_t) + sizeof(uint32_t);
          write_to_buffer(write_pos[0],(void*)&end,sizeof(buffer_start));   
          write_pos[0] = buf_out[0] + block_size - sizeof(uint32_t);
          write_to_buffer(write_pos[0],(void*)&size, sizeof(uint32_t));
@@ -465,27 +517,15 @@ int main(int argc, char ** argv){
       }
       if(evId != TRACE_FILE_SYSTEM && event_size >=0){
        if(ltt_log_cpu){
-         size_count[cpu_id] += sizeof(uint16_t) + sizeof(uint32_t) + event_size;
-         if(size_count[cpu_id] > block_size - reserve_size){
-           printf("size count exceeds the limit of the buffer\n");
-           exit(1);
-         }
          write_to_buffer(write_pos[cpu_id], cur_pos, event_size); 
        }else{
-         size_count[0] += sizeof(uint16_t) + sizeof(uint32_t) + event_size;
-         if(size_count[0] > block_size - reserve_size){
-           printf("size count exceeds the limit of the buffer\n");
-           exit(1);
-         }
          write_to_buffer(write_pos[0], cur_pos, event_size); 
        }
        
        if(evId == TRACE_HEARTBEAT){
          if(ltt_log_cpu){
-           size_count[cpu_id] += sizeof(heartbeat);
            write_to_buffer(write_pos[cpu_id],(void*)&beat , sizeof(heartbeat));         
          }else{
-           size_count[0] +=  sizeof(heartbeat);
            write_to_buffer(write_pos[0], (void*)&beat, sizeof(heartbeat));               
          }
        }
@@ -501,11 +541,6 @@ int main(int argc, char ** argv){
        }else nbBytes = 0;
 
        if(ltt_log_cpu){
-         size_count[cpu_id] += nbBytes + sizeof(uint16_t) + sizeof(uint32_t);
-         if(size_count[cpu_id] > block_size - reserve_size){
-           printf("size count exceeds the limit of the buffer\n");
-           exit(1);
-         }
          write_to_buffer(write_pos[cpu_id], cur_pos, event_size);      
          cur_pos += event_size + sizeof(char*);
          if(nbBytes){
@@ -514,11 +549,6 @@ int main(int argc, char ** argv){
            write_to_buffer(write_pos[cpu_id], (void*)&c, 1);
          }
        }else{
-         size_count[0] += nbBytes + sizeof(uint16_t) + sizeof(uint32_t);
-         if(size_count[0] > block_size - reserve_size){
-           printf("size count exceeds the limit of the buffer\n");
-           exit(1);
-         }
          write_to_buffer(write_pos[0], cur_pos, event_size);
          cur_pos += event_size + sizeof(char*);
          if(nbBytes){
This page took 0.026259 seconds and 4 git commands to generate.