Home | History | Annotate | Download | only in qtools
      1 #include <stdio.h>
      2 #include <stdlib.h>
      3 #include <inttypes.h>
      4 #include "trace_reader.h"
      5 
      6 int main(int argc, char **argv) {
      7   if (argc != 2) {
      8     fprintf(stderr, "Usage: %s trace_file\n", argv[0]);
      9     exit(1);
     10   }
     11 
     12   char *trace_filename = argv[1];
     13   TraceReaderBase *trace = new TraceReaderBase;
     14   trace->Open(trace_filename);
     15 
     16   while (1) {
     17     PidEvent event;
     18     if (trace->ReadPidEvent(&event))
     19       break;
     20     switch (event.rec_type) {
     21       case kPidFork:
     22         printf("t%lld fork tgid %d pid %d\n", event.time, event.tgid, event.pid);
     23         break;
     24       case kPidClone:
     25         printf("t%lld clone tgid %d pid %d\n", event.time, event.tgid, event.pid);
     26         break;
     27       case kPidSwitch:
     28         printf("t%lld switch %d\n", event.time, event.pid);
     29         break;
     30       case kPidExit:
     31         printf("t%lld exit %d\n", event.time, event.pid);
     32         break;
     33       case kPidMmap:
     34         printf("t%lld mmap %08x - %08x, offset %08x '%s'\n",
     35                event.time, event.vstart, event.vend, event.offset, event.path);
     36         delete[] event.path;
     37         break;
     38       case kPidMunmap:
     39         printf("t%lld munmap %08x - %08x\n",
     40                event.time, event.vstart, event.vend);
     41         break;
     42       case kPidSymbolAdd:
     43         printf("t%lld add sym %08x '%s'\n",
     44                event.time, event.vstart, event.path);
     45         delete[] event.path;
     46         break;
     47       case kPidSymbolRemove:
     48         printf("t%lld remove %08x\n", event.time, event.vstart);
     49         break;
     50       case kPidExec:
     51         printf("t%lld argc: %d\n", event.time, event.argc);
     52         for (int ii = 0; ii < event.argc; ++ii) {
     53           printf("  argv[%d]: %s\n", ii, event.argv[ii]);
     54           delete[] event.argv[ii];
     55         }
     56         delete[] event.argv;
     57         break;
     58       case kPidKthreadName:
     59         printf("t%lld kthread tgid %d pid %d %s\n",
     60                event.time, event.tgid, event.pid, event.path);
     61         delete[] event.path;
     62         break;
     63       case kPidName:
     64         printf("t%lld name %d %s\n",
     65                event.time, event.pid, event.path);
     66         delete[] event.path;
     67         break;
     68     }
     69   }
     70   return 0;
     71 }
     72