00001
00002 #include "interconnect_profile.hh"
00003 #include "sim/builder.hh"
00004
00005 #include <fstream>
00006
00007 using namespace std;
00008
00009 class Interconnect;
00010
00011 InterconnectProfile::InterconnectProfile(const std::string &_name,
00012 bool _traceSends,
00013 bool _traceChannelUtil,
00014 Tick _startTick,
00015 Interconnect* _interconnect)
00016 : SimObject(_name)
00017 {
00018 assert(_interconnect != NULL);
00019
00020 traceSends = _traceSends;
00021 traceChannelUtil = _traceChannelUtil;
00022 startTick = _startTick;
00023 interconnect = _interconnect;
00024
00025 interconnect->registerProfiler(this);
00026
00027 sendFileName = "interconnectSendProfile.txt";
00028 channelFileName = "interconnectChannelProfile.txt";
00029 channelExplFileName = "interconnectChannelExplanation.txt";
00030
00031 initSendFile();
00032
00033 sendEvent = new InterconnectProfileEvent(this, SEND);
00034 sendEvent->schedule(startTick);
00035
00036 bool doChannelTrace = initChannelFile();
00037
00038 if(doChannelTrace){
00039 channelEvent = new InterconnectProfileEvent(this, CHANNEL);
00040 channelEvent->schedule(startTick);
00041 }
00042 }
00043
00044 void
00045 InterconnectProfile::initSendFile(){
00046 ofstream sendfile(sendFileName.c_str());
00047 sendfile << "Clock Cycle;Data Sends;Instruction Sends;"
00048 << "Coherence Sends;Total Sends\n";
00049 sendfile.flush();
00050 sendfile.close();
00051 }
00052
00053 void
00054 InterconnectProfile::writeSendEntry(){
00055
00056
00057 int data = 0, insts = 0, coherence = 0, total = 0;
00058 interconnect->getSendSample(&data, &insts, &coherence, &total);
00059 assert(data + insts + coherence == total);
00060
00061
00062 ofstream sendfile(sendFileName.c_str(), ofstream::app);
00063 sendfile << curTick << ";"
00064 << data << ";"
00065 << insts << ";"
00066 << coherence << ";"
00067 << total << "\n";
00068 sendfile.flush();
00069 sendfile.close();
00070 }
00071
00072 bool
00073 InterconnectProfile::initChannelFile(){
00074
00075 int channelCount = interconnect->getChannelCount();
00076
00077 if(channelCount != -1){
00078
00079
00080 ofstream chanfile(channelFileName.c_str());
00081 chanfile << "Clock Cycle; ";
00082
00083 for(int i =0;i<channelCount;i++){
00084 chanfile << "Channel " << i;
00085
00086 if(i == channelCount-1) chanfile << "\n";
00087 else chanfile << "; ";
00088 }
00089
00090 chanfile.flush();
00091 chanfile.close();
00092
00093
00094 ofstream explFile(channelExplFileName.c_str());
00095 interconnect->writeChannelDecriptor(explFile);
00096 explFile.flush();
00097 explFile.close();
00098
00099 return true;
00100 }
00101
00102
00103 return false;
00104
00105 }
00106
00107 void
00108 InterconnectProfile::writeChannelEntry(){
00109
00110 int channelCount = interconnect->getChannelCount();
00111 vector<int> res = interconnect->getChannelSample();
00112 assert(res.size() == channelCount);
00113
00114 ofstream channelfile(channelFileName.c_str(), ofstream::app);
00115 channelfile << curTick << ";";
00116
00117 for(int i=0;i<res.size();i++){
00118 channelfile << ((double) res[i] / (double) RESOLUTION);
00119 if(i == res.size()-1) channelfile << "\n";
00120 else channelfile << ";";
00121 }
00122
00123 channelfile.flush();
00124 channelfile.close();
00125 }
00126
00127 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00128
00129 BEGIN_DECLARE_SIM_OBJECT_PARAMS(InterconnectProfile)
00130 Param<bool> traceSends;
00131 Param<bool> traceChannelUtil;
00132 Param<Tick> traceStartTick;
00133 SimObjectParam<Interconnect*> interconnect;
00134 END_DECLARE_SIM_OBJECT_PARAMS(InterconnectProfile)
00135
00136 BEGIN_INIT_SIM_OBJECT_PARAMS(InterconnectProfile)
00137 INIT_PARAM(traceSends, "Trace number of sends?"),
00138 INIT_PARAM(traceChannelUtil, "Trace channel utilisation?"),
00139 INIT_PARAM(traceStartTick, "The clock cycle to start the trace"),
00140 INIT_PARAM(interconnect, "The interconnect to profile")
00141 END_INIT_SIM_OBJECT_PARAMS(InterconnectProfile)
00142
00143 CREATE_SIM_OBJECT(InterconnectProfile)
00144 {
00145 return new InterconnectProfile(getInstanceName(),
00146 traceSends,
00147 traceChannelUtil,
00148 traceStartTick,
00149 interconnect);
00150 }
00151
00152 REGISTER_SIM_OBJECT("InterconnectProfile", InterconnectProfile)
00153
00154 #endif //DOXYGEN_SHOULD_SKIP_THIS