OpenCores
URL https://opencores.org/ocsvn/async_sdm_noc/async_sdm_noc/trunk

Subversion Repositories async_sdm_noc

[/] [async_sdm_noc/] [trunk/] [common/] [tb/] [sim_ana.h] - Blame information for rev 37

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 29 wsong0210
/*
2
 Asynchronous SDM NoC
3
 (C)2011 Wei Song
4
 Advanced Processor Technologies Group
5
 Computer Science, the Univ. of Manchester, UK
6
 
7
 Authors:
8
 Wei Song     wsong83@gmail.com
9
 
10
 License: LGPL 3.0 or later
11
 
12
 Simulation analyzer, gethering info. for performance analyses.
13
 
14
 Possible bugs:
15
 * the histograph function has not been tested yet.
16
 
17
 
18
 History:
19
 29/06/2010  Initial version. <wsong83@gmail.com>
20 30 wsong0210
 28/05/2011  Clean up for opensource. <wsong83@gmail.com>
21 29 wsong0210
 
22
*/
23
 
24
#ifndef SIM_ANA_H_
25
#define SIM_ANA_H_
26
 
27
#include <cstdlib>
28
#include <cmath>
29
#include <iostream>
30
#include <fstream>
31
#include <string>
32
#include "sim_record.h"
33
#include "hash_table.h"
34
 
35
using namespace std;
36
 
37
// a data type for accumulative performance, such as throughput analysis
38
class accu_record{
39
 private:
40
  double V1, V2;                /* two values to avoid loss of accuracy, V1 save the accumulated V2 of at least 512 records */
41
  unsigned int N1, N2;
42
 public:
43
  accu_record()
44
    :V1(0), V2(0), N1(0), N2(0)
45
    {}
46
 
47
  accu_record& operator+= (const double m) {
48
    N2++;
49
    V2 += m;
50
    if(N2 >= N1/512) {
51
      N1 += N2;
52
      V1 += V2;
53
      N2 = 0;
54
      V2 = 0;
55
    }
56
    return(*this);
57
  }
58
 
59
  double avalue() {             /* return averged value */
60
    double rt;
61
 
62
    if(0 == N1+N2)
63
      rt = 0;
64
    else
65
      rt = (V1 + V2) / (N1 + N2);
66
 
67
    V1 = 0;
68
    V2 = 0;
69
    N1 = 0;
70
    N2 = 0;
71
    return rt;
72
  }
73
 
74
  double value() {              /* return the accumulative value */
75
    double rt;
76
 
77
    if(0 == N1+N2)
78
      rt = 0;
79
    else
80
      rt = (V1 + V2);
81
 
82
    V1 = 0;
83
    V2 = 0;
84
    N1 = 0;
85
    N2 = 0;
86
    return rt;
87
  }
88
};
89
 
90
/* the major simulation record class, only one such object in one simulation */
91
class sim_ana {
92
 public:
93
 
94
  sim_ana()
95
    : warm_time(0), record_period(0),last_time(0),
96
    delay_ana(false), throughput_ana(false), delay_histo_ana(false),
97
    histo_data(NULL) {}
98
 
99
  sim_ana(double mwt, double mrp)
100
    : warm_time(mwt), record_period(mrp), last_time(0),
101
    delay_ana(false), throughput_ana(false), delay_histo_ana(false),
102
    histo_data(NULL) {}
103
 
104
  ~sim_ana();
105
 
106
  /* currently 16 table entries is enough and good for memory efficiency */
107
  hash_table<sim_record<2>,16> ANA;
108
 
109
  bool start(long, double);     /* start to record a new record */
110
  bool record(long, double);    /* record a time stamp */
111
  bool stop(long, double, unsigned int);        /* stop an old record */
112
 
113
  bool set_ana_parameters(double, double); /* set analysis time parameters */
114
  bool analyze_delay(string);   /* enable delay analysis */
115
  bool analyze_throughput(string); /* enable throughput analysis */
116
  bool analyze_delay_histo(string, double, double, unsigned int); /* enable delay histo analysis */
117
 
118
 private:
119
  double warm_time;
120
  double record_period;
121
  double last_time;
122
 
123
  bool delay_ana;               /* whether analyze frame delay */
124
  bool throughput_ana;          /* whether analyze throughput */
125
  bool delay_histo_ana;         /* whether analyze frame delay histo */
126
  unsigned int delay_histo_binnum; /* bin number of the histo graph */
127
  double delay_histo_start;        /* histo begin level */
128
  double delay_histo_end;          /* histo end level */
129
  double delay_histo_gap;          /* gap bewteen two levels (gap = (start-end)/(binnum-2)) */
130
  unsigned long * histo_data;
131
 
132
  string delay_file;            /* the name for delay analyses result file */
133
  string throughput_file;       /* the name for throughput analyses result file */
134
  string delay_histo_file;      /* the name for histograph analyses file */
135
 
136
  accu_record fm_dly;           /* records of frame delay */
137
  accu_record pth_dly;          /* records of path delay */
138
  accu_record th_value;         /* records of throughput */
139
};
140
 
141
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.