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 static const int kMaxHistEntries = 256;
      7 static const int kMaxHistEntries2 = kMaxHistEntries /  2;
      8 int hist[kMaxHistEntries];
      9 int underflow, overflow;
     10 
     11 int main(int argc, char **argv) {
     12   if (argc != 2) {
     13     fprintf(stderr, "Usage: %s trace_file\n", argv[0]);
     14     exit(1);
     15   }
     16 
     17   char *trace_filename = argv[1];
     18   TraceReaderBase *trace = new TraceReaderBase;
     19   trace->Open(trace_filename);
     20 
     21   uint64_t prev_bb_num = 0;
     22   uint64_t prev_time = 0;
     23   int total = 0;
     24 
     25   while (1) {
     26     BBEvent event;
     27 
     28     if (trace->ReadBB(&event))
     29       break;
     30     int bb_diff = event.bb_num - prev_bb_num;
     31     //int time_diff = event.time - prev_time;
     32     //printf("bb_num: %llu prev: %llu, diff: %d\n",
     33     // event.bb_num, prev_bb_num, bb_diff);
     34     prev_bb_num = event.bb_num;
     35     prev_time = event.time;
     36 
     37     bb_diff += kMaxHistEntries2;
     38     if (bb_diff < 0)
     39       underflow += 1;
     40     else if (bb_diff >= kMaxHistEntries)
     41       overflow += 1;
     42     else
     43       hist[bb_diff] += 1;
     44     total += 1;
     45   }
     46 
     47   int sum = 0;
     48   double sum_per = 0;
     49   double per = 0;
     50   for (int ii = 0; ii < kMaxHistEntries; ++ii) {
     51     if (hist[ii] == 0)
     52       continue;
     53     per = 100.0 * hist[ii] / total;
     54     sum += hist[ii];
     55     sum_per = 100.0 * sum / total;
     56     printf(" %4d: %6d %6.2f %6.2f\n", ii - kMaxHistEntries2, hist[ii], per, sum_per);
     57   }
     58   per = 100.0 * underflow / total;
     59   printf("under: %6d %6.2f\n", underflow, per);
     60   per = 100.0 * overflow / total;
     61   printf("over:  %6d %6.2f\n", overflow, per);
     62   printf("total: %6d\n", total);
     63   return 0;
     64 }
     65