/*
|
/*
|
Asynchronous SDM NoC
|
Asynchronous SDM NoC
|
(C)2011 Wei Song
|
(C)2011 Wei Song
|
Advanced Processor Technologies Group
|
Advanced Processor Technologies Group
|
Computer Science, the Univ. of Manchester, UK
|
Computer Science, the Univ. of Manchester, UK
|
|
|
Authors:
|
Authors:
|
Wei Song wsong83@gmail.com
|
Wei Song wsong83@gmail.com
|
|
|
License: LGPL 3.0 or later
|
License: LGPL 3.0 or later
|
|
|
Simulation analyzer, gethering info. for performance analyses.
|
Simulation analyzer, gethering info. for performance analyses.
|
|
|
Possible bugs:
|
Possible bugs:
|
* the histograph function has not been tested yet.
|
* the histograph function has not been tested yet.
|
|
|
|
|
History:
|
History:
|
29/06/2010 Initial version. <wsong83@gmail.com>
|
29/06/2010 Initial version. <wsong83@gmail.com>
|
27/05/2011 Clean up for opensource. <wsong83@gmail.com>
|
27/05/2011 Clean up for opensource. <wsong83@gmail.com>
|
|
|
*/
|
*/
|
|
|
#include "sim_ana.h"
|
#include "sim_ana.h"
|
|
|
bool sim_ana::set_ana_parameters(double mwt, double mrp) {
|
bool sim_ana::set_ana_parameters(double mwt, double mrp) {
|
if((mwt < 0) || (mrp < 0))
|
if((mwt < 0) || (mrp < 0))
|
return false;
|
return false;
|
|
|
warm_time = mwt;
|
warm_time = mwt;
|
record_period = mrp;
|
record_period = mrp;
|
return true;
|
return true;
|
}
|
}
|
|
|
bool sim_ana::analyze_delay(string mfname) {
|
bool sim_ana::analyze_delay(string mfname) {
|
ofstream file_handle;
|
ofstream file_handle;
|
|
|
delay_ana = true;
|
delay_ana = true;
|
delay_file = mfname;
|
delay_file = mfname;
|
|
|
file_handle.open(delay_file.data(), fstream::trunc);
|
file_handle.open(delay_file.data(), fstream::trunc);
|
file_handle.close();
|
file_handle.close();
|
|
|
return true;
|
return true;
|
}
|
}
|
|
|
bool sim_ana::analyze_throughput(string mfname) {
|
bool sim_ana::analyze_throughput(string mfname) {
|
ofstream file_handle;
|
ofstream file_handle;
|
|
|
throughput_ana = true;
|
throughput_ana = true;
|
throughput_file = mfname;
|
throughput_file = mfname;
|
|
|
file_handle.open(throughput_file.data(), fstream::trunc);
|
file_handle.open(throughput_file.data(), fstream::trunc);
|
file_handle.close();
|
file_handle.close();
|
|
|
return true;
|
return true;
|
}
|
}
|
|
|
bool sim_ana::analyze_delay_histo(string mframe, double tstart, double tend, unsigned int binnum) {
|
bool sim_ana::analyze_delay_histo(string mframe, double tstart, double tend, unsigned int binnum) {
|
ofstream file_handle;
|
ofstream file_handle;
|
|
|
if((tstart < 0) || (tend <= tstart) || (binnum < 3))
|
if((tstart < 0) || (tend <= tstart) || (binnum < 3))
|
return false;
|
return false;
|
|
|
delay_histo_ana = true;
|
delay_histo_ana = true;
|
delay_histo_file = mframe;
|
delay_histo_file = mframe;
|
|
|
file_handle.open(delay_histo_file.data(), fstream::trunc);
|
file_handle.open(delay_histo_file.data(), fstream::trunc);
|
file_handle.close();
|
file_handle.close();
|
|
|
delay_histo_start = tstart;
|
delay_histo_start = tstart;
|
delay_histo_end = tend;
|
delay_histo_end = tend;
|
delay_histo_gap = (tstart - tend) / (binnum - 2);
|
delay_histo_gap = (tstart - tend) / (binnum - 2);
|
delay_histo_binnum = binnum;
|
delay_histo_binnum = binnum;
|
|
|
histo_data = new unsigned long [binnum];
|
histo_data = new unsigned long [binnum];
|
|
|
for(unsigned int i=0; i<binnum; i++)
|
for(unsigned int i=0; i<binnum; i++)
|
histo_data[i] = 0;
|
histo_data[i] = 0;
|
|
|
return true;
|
return true;
|
}
|
}
|
|
|
bool sim_ana::start(long mkey, double mtime) {
|
bool sim_ana::start(long mkey, double mtime) {
|
sim_record<2> * mrd;
|
sim_record<2> * mrd;
|
|
|
mrd = new sim_record<2> (mtime, mkey);
|
mrd = new sim_record<2> (mtime, mkey);
|
|
|
ANA.insert(*mrd);
|
ANA.insert(*mrd);
|
|
|
return true;
|
return true;
|
}
|
}
|
|
|
bool sim_ana::stop(long mkey, double mtime, unsigned int payload) {
|
bool sim_ana::stop(long mkey, double mtime, unsigned int payload) {
|
ofstream file_handle;
|
ofstream file_handle;
|
sim_record<2> * mrd;
|
sim_record<2> * mrd;
|
|
|
mrd = ANA.find(mkey);
|
mrd = ANA.find(mkey);
|
|
|
if(mrd == NULL)
|
if(mrd == NULL)
|
return false;
|
return false;
|
|
|
// cout << mtime << " " << mtime - mrd->stamp[0] << endl;
|
// cout << mtime << " " << mtime - mrd->stamp[0] << endl;
|
|
|
if(mtime < warm_time) {
|
if(mtime < warm_time) {
|
ANA.clear(mrd);
|
ANA.clear(mrd);
|
return true;
|
return true;
|
}
|
}
|
|
|
if(delay_ana) {
|
if(delay_ana) {
|
fm_dly += (mtime - mrd->stamp[0]);
|
fm_dly += (mtime - mrd->stamp[0]);
|
pth_dly += (mrd->stamp[1] - mrd->stamp[0]);
|
pth_dly += (mrd->stamp[1] - mrd->stamp[0]);
|
}
|
}
|
|
|
if(throughput_ana) {
|
if(throughput_ana) {
|
th_value += payload;
|
th_value += payload;
|
}
|
}
|
|
|
if(delay_histo_ana) {
|
if(delay_histo_ana) {
|
double delay = mtime - mrd->stamp[0];
|
double delay = mtime - mrd->stamp[0];
|
|
|
if(delay >= delay_histo_end)
|
if(delay >= delay_histo_end)
|
histo_data[delay_histo_binnum-1]++;
|
histo_data[delay_histo_binnum-1]++;
|
else {
|
else {
|
delay -= delay_histo_start;
|
delay -= delay_histo_start;
|
if(delay < 0)
|
if(delay < 0)
|
histo_data[0]++;
|
histo_data[0]++;
|
else {
|
else {
|
histo_data[(unsigned long)(1 + delay/delay_histo_gap)]++;
|
histo_data[(unsigned long)(1 + delay/delay_histo_gap)]++;
|
}
|
}
|
}
|
}
|
}
|
}
|
|
|
ANA.clear(mrd);
|
ANA.clear(mrd);
|
|
|
// check whether need to write out
|
// check whether need to write out
|
if(floor(mtime/record_period) > floor(last_time/record_period)) {
|
if(floor(mtime/record_period) > floor(last_time/record_period)) {
|
if(delay_ana) {
|
if(delay_ana) {
|
file_handle.open(delay_file.data(), fstream::app);
|
file_handle.open(delay_file.data(), fstream::app);
|
file_handle << mtime << "\t" << fm_dly.avalue() << "\t" << pth_dly.avalue() << endl;
|
file_handle << mtime << "\t" << fm_dly.avalue() << "\t" << pth_dly.avalue() << endl;
|
file_handle.close();
|
file_handle.close();
|
}
|
}
|
|
|
if(throughput_ana) {
|
if(throughput_ana) {
|
file_handle.open(throughput_file.data(), fstream::app);
|
file_handle.open(throughput_file.data(), fstream::app);
|
file_handle << mtime << "\t" << th_value.value() << endl;
|
file_handle << mtime << "\t" << th_value.value() << endl;
|
file_handle.close();
|
file_handle.close();
|
}
|
}
|
|
|
last_time = mtime;
|
last_time = mtime;
|
}
|
}
|
|
|
|
|
return true;
|
return true;
|
}
|
}
|
|
|
bool sim_ana::record(long mkey, double mtime) {
|
bool sim_ana::record(long mkey, double mtime) {
|
sim_record<2> * mrd;
|
sim_record<2> * mrd;
|
|
|
mrd = ANA.find(mkey);
|
mrd = ANA.find(mkey);
|
|
|
if(mrd == NULL)
|
if(mrd == NULL)
|
return false;
|
return false;
|
|
|
mrd->stamp[mrd->index] = mtime;
|
mrd->stamp[mrd->index] = mtime;
|
|
|
return true;
|
return true;
|
}
|
}
|
|
|
|
|
sim_ana::~sim_ana() {
|
sim_ana::~sim_ana() {
|
ofstream file_handle;
|
ofstream file_handle;
|
|
|
if(delay_histo_ana) {
|
if(delay_histo_ana) {
|
file_handle.open(delay_histo_file.data(), fstream::app);
|
file_handle.open(delay_histo_file.data(), fstream::app);
|
|
|
for(unsigned int i=0; i<delay_histo_binnum; i++)
|
for(unsigned int i=0; i<delay_histo_binnum; i++)
|
file_handle << (double)(delay_histo_start + i*delay_histo_gap) << "\t" << histo_data[i] << endl;
|
file_handle << (double)(delay_histo_start + i*delay_histo_gap) << "\t" << histo_data[i] << endl;
|
|
|
file_handle.close();
|
file_handle.close();
|
}
|
}
|
|
|
if(histo_data != NULL)
|
if(histo_data != NULL)
|
delete[] histo_data;
|
delete[] histo_data;
|
}
|
}
|
|
|
|
|