|
libraries/onchipcommunication/systemc/Monitor.hGo to the documentation of this file.00001 //============================================================================ 00002 // Author : Alessandro Pinto <apinto@eecs.berkeley.edu> 00003 // University of California, Berkeley 00004 // 545 Cory Hall, Berkeley, CA 94720 00005 // Copyright : See COPYING file that comes with this distribution 00006 //============================================================================ 00007 00008 #ifndef MONITOR_H_ 00009 #define MONITOR_H_ 00010 00011 #include "systemc.h" 00012 #include "DestIp.h" 00013 #include <vector> 00014 #include <map> 00015 #include <fstream> 00016 00017 using namespace std ; 00018 00019 template<int FlitWidth> 00020 class Monitor : public sc_module { 00021 00022 public: 00023 00024 SC_HAS_PROCESS( Monitor ) ; 00025 00026 00027 Monitor( sc_module_name n , double Step , vector< DestIp<FlitWidth>* > DestVector ) : sc_module( n ) { 00028 00029 mStep = Step ; 00030 mDestVector = DestVector ; 00031 00032 SC_THREAD( Tick ) ; 00033 00034 } ; 00035 00036 void Tick( ) { 00037 00038 while( true) { 00039 00040 wait( mStep , SC_SEC ) ; 00041 cout << "Simulation time " << sc_simulation_time( )*1e-9 << " sec " << endl ; 00042 //report destination bandwidth 00043 00044 vector< map<int,int> > ReceivedBits ; 00045 double Average = 0 ; 00046 double Min = DBL_MAX ; 00047 double Max = 0 ; 00048 for( int i = 0 ; i < mDestVector.size( ) ; i++ ) { 00049 ReceivedBits.push_back( ( mDestVector[i] )->GetReceivedBits() ) ; 00050 mDestVector[i]->Report( ) ; 00051 Average += mDestVector[i]->GetAverageLatency( ) ; 00052 if ( mDestVector[i]->GetMinLatency( ) < Min ) 00053 Min = mDestVector[i]->GetMinLatency( ) ; 00054 if ( mDestVector[i]->GetMaxLatency( ) > Max ) 00055 Max = mDestVector[i]->GetMaxLatency( ) ; 00056 } 00057 mReceivedBits[ sc_simulation_time( )*1e-9 ] = ReceivedBits ; 00058 cout << "Average lantecy = " << Average / (double) mDestVector.size( ) << endl; 00059 cout << "Maximum latency = " << Max << " Minimum latency = " << Min << endl ; 00060 } 00061 00062 } ; 00063 00064 00065 void WriteReport( ) { 00066 00067 map< double , vector< map< int , int > > >::iterator It ; 00068 map<int,int>::iterator Sit; 00069 for( int i = 0 ; i < mDestVector.size( ) ; i++ ) { 00070 ofstream f; 00071 string fname ; 00072 fname = string( mDestVector[i]->name( ) ) + ".trace" ; 00073 f.open( fname.c_str( ) ) ; 00074 for( It = mReceivedBits.begin( ) ; It != mReceivedBits.end( ) ; It++ ) { 00075 f << It->first << " " ; 00076 for( Sit = (It->second)[i].begin( ) ; Sit != (It->second)[i].end( ) ; Sit++ ) { 00077 f << Sit->second << " " ; 00078 } 00079 f << endl ; 00080 } 00081 f.close( ) ; 00082 } 00083 } 00084 00085 double mStep ; 00086 vector< DestIp<FlitWidth>* > mDestVector ; 00087 map< double , vector< map<int,int> > > mReceivedBits ; 00088 00089 } ; 00090 00091 #endif Generated on Sun Sep 7 18:37:42 2008 for COSI by 1.5.4 |