uninitialized variables checked. Also change two if/else if functions for switch
[lttv.git] / ltt / branches / poly / ltt / convert / convert.c
index ccec523fc029da3683718b65adfa8660eacc0f1d..efacdcb630690bcc464689a7d3d82a9f2e4d5957 100644 (file)
@@ -1,8 +1,11 @@
 #include <stdio.h>
+#include <unistd.h>
 #include <fcntl.h>
 #include <sys/stat.h>
 #include <sys/types.h>
-#include <linux/errno.h>  
+#include <errno.h>  
+#include <stdlib.h>
+#include <string.h>
 
 #include <glib.h>
 #include "LTTTypes.h"
@@ -13,7 +16,7 @@
 #define PROCESS_EXIT_ID     21
 
 #define INFO_ENTRY          9
-#define OVERFLOW_FIGURE     4294967296
+#define OVERFLOW_FIGURE     0x100000000ULL
 
 typedef struct _new_process
 {
@@ -30,10 +33,14 @@ do\
 
 int readFile(int fd, void * buf, size_t size, char * mesg)
 {
-   ssize_t nbBytes;
-   nbBytes = read(fd, buf, size);
-   if(nbBytes != size){
-     printf("%s\n",mesg);
+   ssize_t nbBytes = read(fd, buf, size);
+   
+   if((size_t)nbBytes != size) {
+     if(nbBytes < 0) {
+       perror("Error in readFile : ");
+     } else {
+       printf("%s\n",mesg);
+     }
      exit(1);
    }
    return 0;
@@ -92,12 +99,12 @@ int main(int argc, char ** argv){
   char hardware_platform[BUFFER_SIZE];
   char operating_system[BUFFER_SIZE];
   int  cpu;
-  int  ltt_block_size;
-  int  ltt_major_version;
-  int  ltt_minor_version;
+  int  ltt_block_size=0;
+  int  ltt_major_version=0;
+  int  ltt_minor_version=0;
   int  ltt_log_cpu;
   char buf[BUFFER_SIZE];
-  int i,j, k;
+  int i, k;
 
   uint8_t cpu_id;
 
@@ -124,7 +131,7 @@ int main(int argc, char ** argv){
   trace_file_system * tFileSys;
   uint16_t newId, startId, tmpId;
   uint8_t  evId;
-  uint32_t time_delta, startTimeDelta, previous_time_delta;
+  uint32_t time_delta, startTimeDelta;
   void * cur_pos, *end_pos;
   buffer_start start, start_proc, start_intr;
   buffer_start end, end_proc, end_intr;
@@ -137,7 +144,8 @@ int main(int argc, char ** argv){
   new_process process;
 
   if(argc < 4){
-    printf("Not enough parameters\n");
+    printf("Usage : ./convert processfile_name number_of_cpu tracefile1 tracefile2 ... trace_creation_directory\n");
+               printf("For more details, see README.\n");
     exit(1);
   }
 
@@ -305,7 +313,7 @@ int main(int argc, char ** argv){
 
     buf_out = g_new(char, block_size);
     write_pos = buf_out;
-    sprintf(cpuStr,"%s/%d\0",foo_cpu,k);
+    sprintf(cpuStr,"%s/%d",foo_cpu,k);
     fdCpu = open(cpuStr, O_CREAT | O_RDWR | O_TRUNC,S_IRUSR |S_IWUSR | S_IRGRP | S_IROTH); //for cpu k
     if(fdCpu < 0)  g_error("Unable to open  cpu file %d\n", k);    
     lseek(fd,0,SEEK_SET);
@@ -338,7 +346,6 @@ int main(int argc, char ** argv){
 
       startId = newId;
       startTimeDelta = time_delta;
-      previous_time_delta = time_delta;
       start.seconds = tBufStart->Time.tv_sec;
       start.nanoseconds = tBufStart->Time.tv_usec;
       start.cycle_count = tBufStart->TSC;
@@ -437,16 +444,13 @@ int main(int argc, char ** argv){
        time_delta = *(uint32_t*)cur_pos;
        cur_pos += sizeof(uint32_t); 
        
-       if(time_delta < previous_time_delta){
-         end.cycle_count += OVERFLOW_FIGURE;
-       }
-       previous_time_delta = time_delta;
-
        //write event_id and time_delta
        write_to_buffer(write_pos,(void*)&newId,sizeof(uint16_t));
        write_to_buffer(write_pos,(void*)&time_delta, sizeof(uint32_t));     
        
        if(evId == TRACE_BUFFER_END){
+    end.cycle_count = start.cycle_count 
+                         + beat_count * OVERFLOW_FIGURE;
          int size = block_size + ((void*)buf_out - write_pos)+ sizeof(uint16_t) + sizeof(uint32_t);
          write_to_buffer(write_pos,(void*)&end,sizeof(buffer_start));   
          write_pos = buf_out + block_size - sizeof(uint32_t);
@@ -556,10 +560,9 @@ int main(int argc, char ** argv){
            beat_count++;
            beat.seconds = 0;
            beat.nanoseconds = 0;
-           beat.cycle_count = start.cycle_count + beat_count * OVERFLOW_FIGURE;
+           beat.cycle_count = (uint64_t)start.cycle_count 
+                         + (uint64_t)beat_count * OVERFLOW_FIGURE;
            event_size = 0;
-
-           //    end.cycle_count += OVERFLOW_FIGURE;
            
            write_to_buffer(write_pos_intr,(void*)&newId, sizeof(uint16_t));
            write_to_buffer(write_pos_intr,(void*)&timeDelta, sizeof(uint32_t));
@@ -618,22 +621,22 @@ int main(int argc, char ** argv){
 
 
   //write to system.xml
-  fprintf(fp,"<system\n");
-  fprintf(fp,"node_name=\"%s\"\n", node_name);
-  fprintf(fp,"domainname=\"%s\"\n", domainname);
-  fprintf(fp,"cpu=%d\n", cpu);
-  fprintf(fp,"arch_size=\"%s\"\n", arch_size);
-  fprintf(fp,"endian=\"%s\"\n",endian);
-  fprintf(fp,"kernel_name=\"%s\"\n",kernel_name);
-  fprintf(fp,"kernel_release=\"%s\"\n",kernel_release);
-  fprintf(fp,"kernel_version=\"%s\"\n",kernel_version);
-  fprintf(fp,"machine=\"%s\"\n",machine);
-  fprintf(fp,"processor=\"%s\"\n",processor);
-  fprintf(fp,"hardware_platform=\"%s\"\n",hardware_platform);
-  fprintf(fp,"operating_system=\"%s\"\n",operating_system);
-  fprintf(fp,"ltt_major_version=%d\n",ltt_major_version);
-  fprintf(fp,"ltt_minor_version=%d\n",ltt_minor_version);
-  fprintf(fp,"ltt_block_size=%d\n",ltt_block_size);
+  fprintf(fp,"<system \n");
+  fprintf(fp,"node_name=\"%s\" \n", node_name);
+  fprintf(fp,"domainname=\"%s\" \n", domainname);
+  fprintf(fp,"cpu=\"%d\" \n", cpu);
+  fprintf(fp,"arch_size=\"%s\" \n", arch_size);
+  fprintf(fp,"endian=\"%s\" \n",endian);
+  fprintf(fp,"kernel_name=\"%s\" \n",kernel_name);
+  fprintf(fp,"kernel_release=\"%s\" \n",kernel_release);
+  fprintf(fp,"kernel_version=\"%s\" \n",kernel_version);
+  fprintf(fp,"machine=\"%s\" \n",machine);
+  fprintf(fp,"processor=\"%s\" \n",processor);
+  fprintf(fp,"hardware_platform=\"%s\" \n",hardware_platform);
+  fprintf(fp,"operating_system=\"%s\" \n",operating_system);
+  fprintf(fp,"ltt_major_version=\"%d\" \n",ltt_major_version);
+  fprintf(fp,"ltt_minor_version=\"%d\" \n",ltt_minor_version);
+  fprintf(fp,"ltt_block_size=\"%d\" \n",ltt_block_size);
   fprintf(fp,">\n");
   fprintf(fp,"This is just a test\n");
   fprintf(fp,"</system>\n");
@@ -644,5 +647,6 @@ int main(int argc, char ** argv){
   close(fdProc); 
   fclose(fp);
 
+  return 0;
 }
 
This page took 0.024374 seconds and 4 git commands to generate.