aboutsummaryrefslogtreecommitdiffstats
path: root/emulator/qtools/hist_trace.cpp
blob: d2c6a90e51f25e505e7cd6c258e6dc447b105d77 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include "trace_reader.h"

static const int kMaxHistEntries = 256;
static const int kMaxHistEntries2 = kMaxHistEntries /  2;
int hist[kMaxHistEntries];
int underflow, overflow;

int main(int argc, char **argv) {
  if (argc != 2) {
    fprintf(stderr, "Usage: %s trace_file\n", argv[0]);
    exit(1);
  }

  char *trace_filename = argv[1];
  TraceReaderBase *trace = new TraceReaderBase;
  trace->Open(trace_filename);

  uint64_t prev_bb_num = 0;
  uint64_t prev_time = 0;
  int total = 0;
  
  while (1) {
    BBEvent event;

    if (trace->ReadBB(&event))
      break;
    int bb_diff = event.bb_num - prev_bb_num;
    //int time_diff = event.time - prev_time;
    //printf("bb_num: %llu prev: %llu, diff: %d\n",
    // event.bb_num, prev_bb_num, bb_diff);
    prev_bb_num = event.bb_num;
    prev_time = event.time;

    bb_diff += kMaxHistEntries2;
    if (bb_diff < 0)
      underflow += 1;
    else if (bb_diff >= kMaxHistEntries)
      overflow += 1;
    else
      hist[bb_diff] += 1;
    total += 1;
  }

  int sum = 0;
  double sum_per = 0;
  double per = 0;
  for (int ii = 0; ii < kMaxHistEntries; ++ii) {
    if (hist[ii] == 0)
      continue;
    per = 100.0 * hist[ii] / total;
    sum += hist[ii];
    sum_per = 100.0 * sum / total;
    printf(" %4d: %6d %6.2f %6.2f\n", ii - kMaxHistEntries2, hist[ii], per, sum_per);
  }
  per = 100.0 * underflow / total;
  printf("under: %6d %6.2f\n", underflow, per);
  per = 100.0 * overflow / total;
  printf("over:  %6d %6.2f\n", overflow, per);
  printf("total: %6d\n", total);
  return 0;
}