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.cpp] - Blame information for rev 48

Go to most recent revision | 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
 27/05/2011  Clean up for opensource. <wsong83@gmail.com>
21
 
22
*/
23
 
24
#include "sim_ana.h"
25
 
26
bool sim_ana::set_ana_parameters(double mwt, double mrp) {
27
  if((mwt < 0) || (mrp < 0))
28
    return false;
29
 
30
  warm_time = mwt;
31
  record_period = mrp;
32
  return true;
33
}
34
 
35
bool sim_ana::analyze_delay(string mfname) {
36
  ofstream file_handle;
37
 
38
  delay_ana = true;
39
  delay_file = mfname;
40
 
41
  file_handle.open(delay_file.data(), fstream::trunc);
42
  file_handle.close();
43
 
44
  return true;
45
}
46
 
47
bool sim_ana::analyze_throughput(string mfname) {
48
  ofstream file_handle;
49
 
50
  throughput_ana = true;
51
  throughput_file = mfname;
52
 
53
  file_handle.open(throughput_file.data(), fstream::trunc);
54
  file_handle.close();
55
 
56
  return true;
57
}
58
 
59
bool sim_ana::analyze_delay_histo(string mframe, double tstart, double tend, unsigned int binnum) {
60
  ofstream file_handle;
61
 
62
  if((tstart < 0) || (tend <= tstart) || (binnum < 3))
63
    return false;
64
 
65
  delay_histo_ana = true;
66
  delay_histo_file = mframe;
67
 
68
  file_handle.open(delay_histo_file.data(), fstream::trunc);
69
  file_handle.close();
70
 
71
  delay_histo_start = tstart;
72
  delay_histo_end = tend;
73
  delay_histo_gap = (tstart - tend) / (binnum - 2);
74
  delay_histo_binnum = binnum;
75
 
76
  histo_data = new unsigned long [binnum];
77
 
78
  for(unsigned int i=0; i<binnum; i++)
79
    histo_data[i] = 0;
80
 
81
  return true;
82
}
83
 
84
bool sim_ana::start(long mkey, double mtime) {
85
  sim_record<2> * mrd;
86
 
87
  mrd = new sim_record<2> (mtime, mkey);
88
 
89
  ANA.insert(*mrd);
90
 
91
  return true;
92
}
93
 
94
bool sim_ana::stop(long mkey, double mtime, unsigned int payload) {
95
  ofstream file_handle;
96
  sim_record<2> * mrd;
97
 
98
  mrd = ANA.find(mkey);
99
 
100
  if(mrd == NULL)
101
    return false;
102
 
103
  //  cout << mtime << "   "  << mtime - mrd->stamp[0] << endl;
104
 
105
  if(mtime < warm_time) {
106
    ANA.clear(mrd);
107
    return true;
108
  }
109
 
110
  if(delay_ana) {
111
    fm_dly += (mtime - mrd->stamp[0]);
112
    pth_dly += (mrd->stamp[1] -  mrd->stamp[0]);
113
  }
114
 
115
  if(throughput_ana) {
116
    th_value += payload;
117
  }
118
 
119
  if(delay_histo_ana) {
120
    double delay = mtime - mrd->stamp[0];
121
 
122
    if(delay >= delay_histo_end)
123
      histo_data[delay_histo_binnum-1]++;
124
    else {
125
      delay -= delay_histo_start;
126
      if(delay < 0)
127
        histo_data[0]++;
128
      else {
129
        histo_data[(unsigned long)(1 + delay/delay_histo_gap)]++;
130
      }
131
    }
132
  }
133
 
134
    ANA.clear(mrd);
135
 
136
  // check whether need to write out
137
  if(floor(mtime/record_period) > floor(last_time/record_period)) {
138
    if(delay_ana) {
139
      file_handle.open(delay_file.data(), fstream::app);
140
      file_handle << mtime << "\t" << fm_dly.avalue() << "\t" << pth_dly.avalue() << endl;
141
      file_handle.close();
142
    }
143
 
144
    if(throughput_ana) {
145
      file_handle.open(throughput_file.data(), fstream::app);
146
      file_handle << mtime << "\t" << th_value.value() << endl;
147
      file_handle.close();
148
    }
149
 
150
    last_time = mtime;
151
  }
152
 
153
 
154
  return true;
155
}
156
 
157
bool sim_ana::record(long mkey, double mtime) {
158
  sim_record<2> * mrd;
159
 
160
  mrd = ANA.find(mkey);
161
 
162
  if(mrd == NULL)
163
    return false;
164
 
165
  mrd->stamp[mrd->index] = mtime;
166
 
167
  return true;
168
}
169
 
170
 
171
sim_ana::~sim_ana() {
172
  ofstream file_handle;
173
 
174
  if(delay_histo_ana) {
175
    file_handle.open(delay_histo_file.data(), fstream::app);
176
 
177
    for(unsigned int i=0; i<delay_histo_binnum; i++)
178
      file_handle << (double)(delay_histo_start + i*delay_histo_gap) << "\t" << histo_data[i] << endl;
179
 
180
    file_handle.close();
181
  }
182
 
183
  if(histo_data != NULL)
184
    delete[] histo_data;
185
}
186
 

powered by: WebSVN 2.1.0

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