Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

PsBenchController< BenchedController > Class Template Reference

Controller mesuring the time spend computing for each object. More...

#include <PsBenchController.h>

Inheritance diagram for PsBenchController< BenchedController >:

Inheritance graph
[legend]
Collaboration diagram for PsBenchController< BenchedController >:

Collaboration graph
[legend]
List of all members.

Public Methods

 PsBenchController (PsObjectDescriptor &scenario, const PsDate &initialDate)
 constructor for standard controllers

 PsBenchController (PsObjectDescriptor &scenario, const PsDate &initialDate, int argc, char *argv[])
 constructor for distributed controllers

virtual ~PsBenchController ()
 destructor it is the destructor that writes the bench results to a file

virtual PsnSchedulercreateScheduler ()
 create a scheduler than can bench stuff

virtual void advanceSimulatedDate ()
 redefine advanceSimuledDate so that the sample index is incremented

 PsBenchController (PsObjectDescriptor &scenario, const PsDate &initialDate, string nonFichRes)
 constructor

virtual ~PsBenchController ()
 destructor it is the destructor that writes the bench results to a file

virtual void compute ()
 redefine compute so that time is mesured

virtual void init ()
 create data strcutures to hold benching information

virtual PsnSchedulercreateScheduler ()
 create a scheduler than can bench stuff


Protected Methods

virtual void printToStream (ostream &out)
 write the sampled result to a stream

virtual void flushResults ()
 writes the sampled results to a file if a filename was given, to stdout otherwise


Protected Attributes

PsString _resultFilename
 the file name to which the results must be written

int _sampleIndex
 index of the current sample

ofstream * _file
 a pointer to the file to which is written all data collected

long * _stepDurationTab
 a table recording the time it took to calculated each simulation step

long * _slowedDownStepDurationTab
 a table recording the time, it took to calculate and wait for each simualtion step

unsigned int _numberOfSamples
 the number of samples to take

PsDate _startSamplingDate
 the date at wich sampling starts

PsDate _endSamplingDate
 the date at wich sampling finishes

ofstream * _file
 a pointer to the file to which is written all data collected


Detailed Description

template<typename BenchedController>
class PsBenchController< BenchedController >

Controller mesuring the time spend computing for each object.

Author:
David Margery
Version:
1.1 : 0.9 -> 1.0 by David Margery : used this controller to test soft real-time 1.0 -> 1.1 by David Margery : inheritence from the base controller 1.1 -> 1.2 by David Margery (2002/07/22): removed soft real time and ported to OpenMASK, inheritance from the timer controller

Definition at line 36 of file PsBenchController.h.


Constructor & Destructor Documentation

template<typename BenchedController>
PsBenchController< BenchedController >::PsBenchController PsObjectDescriptor   scenario,
const PsDate   initialDate
 

constructor for standard controllers

Definition at line 82 of file PsBenchController.h.

References PsBenchController< BenchedController >::_file, PsBenchController< BenchedController >::_resultFilename, PsConfigurationParameterDescriptor::getAssociatedString(), PsSimulatedObject::getConfigurationParameters(), PsString::getCString(), PsConfigurationParameterDescriptor::getSubDescriptorByName(), and PsDate.

00083                                                                                                                   : 
00084    PsTimerController<BenchedController>(scenario, initialDate),
00085    _resultFilename (""),
00086    _sampleIndex ( -1 ),
00087    _file (NULL )
00088 {
00089    if (getConfigurationParameters() != NULL )
00090       {
00091          const PsConfigurationParameterDescriptor * param = getConfigurationParameters()->getSubDescriptorByName("BenchResultFile") ;
00092          if ( param != NULL )
00093             {
00094                _resultFilename = param->getAssociatedString() ;
00095                _file = new ofstream ( _resultFilename.getCString() );
00096                assert ( _file->good() ) ;
00097             }
00098       }

template<typename BenchedController>
PsBenchController< BenchedController >::PsBenchController PsObjectDescriptor   scenario,
const PsDate   initialDate,
int    argc,
char *    argv[]
 

constructor for distributed controllers

Definition at line 101 of file PsBenchController.h.

References PsBenchController< BenchedController >::_file, PsBenchController< BenchedController >::_resultFilename, PsConfigurationParameterDescriptor::getAssociatedString(), PsSimulatedObject::getConfigurationParameters(), PsString::getCString(), PsConfigurationParameterDescriptor::getSubDescriptorByName(), and PsDate.

00103    :  PsTimerController<BenchedController>(scenario, initialDate, argc, argv),
00104       _resultFilename (""),
00105       _sampleIndex ( 0 ),
00106       _file (NULL )
00107 {
00108    if (getConfigurationParameters() != NULL )
00109       {
00110          const PsConfigurationParameterDescriptor * param = getConfigurationParameters()->getSubDescriptorByName("BenchResultFile") ;
00111          if ( param != NULL )
00112             {
00113                _resultFilename = param->getAssociatedString() ;
00114                _file = new ofstream ( _resultFilename.getCString() );
00115                assert ( _file->good() ) ;
00116             }
00117       }

template<typename BenchedController>
PsBenchController< BenchedController >::~PsBenchController   [virtual]
 

destructor it is the destructor that writes the bench results to a file

Definition at line 120 of file PsBenchController.h.

References PsBenchController< BenchedController >::_file, and PsController::_scheduler.

00122 {
00123    // delete the scheduler because it has a pointer to the file we opened   
00124   if ( _scheduler != NULL ) 
00125      {
00126         delete _scheduler ;
00127         _scheduler = NULL ;
00128      }
00129 
00130    if ( _file != NULL )
00131       {
00132          _file->close() ;
00133          delete _file ;
00134          _file = NULL ;
00135       }

template<typename BenchedController>
PsBenchController< BenchedController >::PsBenchController PsObjectDescriptor   scenario,
const PsDate   initialDate,
string    nonFichRes
 

constructor

template<typename BenchedController>
virtual PsBenchController< BenchedController >::~PsBenchController   [virtual]
 

destructor it is the destructor that writes the bench results to a file


Member Function Documentation

template<typename BenchedController>
void PsBenchController< BenchedController >::advanceSimulatedDate   [virtual]
 

redefine advanceSimuledDate so that the sample index is incremented

Reimplemented from PsController.

Definition at line 165 of file PsBenchController.h.

References PsController::_date, PsBenchController< BenchedController >::_endSamplingDate, PsBenchController< BenchedController >::_sampleIndex, and PsBenchController< BenchedController >::_startSamplingDate.

00167 {
00168    if ( (_date >= _startSamplingDate) && 
00169         (_date <= _endSamplingDate) )
00170       {
00171          ++_sampleIndex ;
00172       }
00173    PsTimerController<BenchedController>::advanceSimulatedDate() ;

template<typename BenchedController>
void PsBenchController< BenchedController >::compute   [virtual]
 

redefine compute so that time is mesured

Reimplemented from PsController.

Reimplemented in PsPvmBenchController< APvmController >, and PsPvmBenchController< PsMultiThreadedPvmController >.

Definition at line 121 of file PsSoftRealTimeController.cxx.

References PsController::_date, PsBenchController< BenchedController >::_endSamplingDate, PsBenchController< BenchedController >::_numberOfSamples, PsController::_numberOfSimulatedSteps, PsBenchController< BenchedController >::_sampleIndex, PsBenchController< BenchedController >::_slowedDownStepDurationTab, PsBenchController< BenchedController >::_startSamplingDate, PsBenchController< BenchedController >::_stepDurationTab, PsController::_stepPeriod, PsController::compute(), and PsBenchController< BenchedController >::flushResults().

Referenced by PsPvmBenchController< APvmController >::compute().

00121                                 {
00122    static long avance = 0 ;
00123    //initialisation des compteurs du pas de calcul
00124    if ((_startSamplingDate<=_date)&&(_date<=_endSamplingDate)) {
00125       static timespec avant, apres;
00126       clock_gettime(CLOCK_SGI_CYCLE, &avant);
00127       PsController::compute ();
00128       //lecture des compteurs du pas de calcul
00129       clock_gettime(CLOCK_SGI_CYCLE, &apres);
00130       //remplissage de la table globale
00131       long duree = apres.tv_nsec - avant.tv_nsec ;
00132       if (duree < 0 ) duree =  apres.tv_nsec + ( LONG_MAX/2 - avant.tv_nsec ) ;
00133       _stepDurationTab[_sampleIndex] = duree ;
00134       _sampleIndex++;
00135       //Les 4 lignes qui suivent sont une tentative primitive d'atteinte du temps réel
00136       avance += _stepPeriod * 1000  - duree / 1000 ;
00137       if (avance > 10000) {
00138          usleep( avance );
00139          clock_gettime(CLOCK_SGI_CYCLE, &apres);
00140          if (apres.tv_nsec > avant.tv_nsec) {
00141             avance = avance - (apres.tv_nsec - avant.tv_nsec) / 1000 ;
00142          }
00143          else {
00144             avance =  avance - (( LONG_MAX/2 - avant.tv_nsec ) + apres.tv_nsec ) / 1000 ;
00145          }
00146       }
00147       _slowedDownStepDurationTab[_numberOfSimulatedSteps%_numberOfSamples] = apres.tv_nsec - avant.tv_nsec ;
00148       if (_slowedDownStepDurationTab[_numberOfSimulatedSteps%_numberOfSamples] < 0) {
00149          _slowedDownStepDurationTab[_numberOfSimulatedSteps%_numberOfSamples] = ( LONG_MAX/2 - avant.tv_nsec ) + apres.tv_nsec ;
00150       }
00151       if (_date==_endSamplingDate) {
00152          flushResults();
00153          _sampleIndex=-1;
00154       }
00155    }
00156    else {
00157       PsController::compute ();
00158    }
00159 }

template<typename BenchedController>
virtual PsnScheduler* PsBenchController< BenchedController >::createScheduler   [virtual]
 

create a scheduler than can bench stuff

Reimplemented from PsController.

Reimplemented in PsMultiThreadedBenchmarkingController, PsMultiThreadedPvmBenchmarkingController, PsPvmBenchController< APvmController >, and PsPvmBenchController< PsMultiThreadedPvmController >.

template<typename BenchedController>
PsnScheduler * PsBenchController< BenchedController >::createScheduler   [virtual]
 

create a scheduler than can bench stuff

Reimplemented from PsController.

Reimplemented in PsMultiThreadedBenchmarkingController, PsMultiThreadedPvmBenchmarkingController, PsPvmBenchController< APvmController >, and PsPvmBenchController< PsMultiThreadedPvmController >.

Definition at line 140 of file PsBenchController.h.

References PsBenchController< BenchedController >::_endSamplingDate, PsBenchController< BenchedController >::_file, PsController::_nbStepsByCycle, PsBenchController< BenchedController >::_numberOfSamples, PsBenchController< BenchedController >::_sampleIndex, PsBenchController< BenchedController >::_startSamplingDate, PsController::_stepPeriod, and PsController::initialSimulationDate.

Referenced by PsPvmBenchController< APvmController >::createScheduler().

00142 {
00143    PsnScheduler * res ;
00144 
00145    if (_startSamplingDate<PsController::initialSimulationDate) 
00146       {
00147          _startSamplingDate=PsController::initialSimulationDate;
00148          cout<<"PsBenchController::WARNING : no values before PsController::initialSimulationDate ("
00149              <<PsController::initialSimulationDate<<")"<<endl;
00150       }
00151 
00152    _numberOfSamples = (_endSamplingDate-_startSamplingDate)/_stepPeriod + 1;
00153 
00154    if ( _file != NULL ) 
00155       {
00156          res = new PsnBenchScheduler(_nbStepsByCycle, _sampleIndex, _numberOfSamples,*_file) ;
00157       }
00158    else 
00159       {
00160          res = new PsnBenchScheduler(_nbStepsByCycle, _sampleIndex, _numberOfSamples, cout ) ;
00161       }
00162    return res ;

template<typename BenchedController>
void PsBenchController< BenchedController >::flushResults   [protected, virtual]
 

writes the sampled results to a file if a filename was given, to stdout otherwise

Definition at line 68 of file PsSoftRealTimeController.cxx.

References PsBenchController< BenchedController >::_file, and PsBenchController< BenchedController >::printToStream().

Referenced by PsBenchController< BenchedController >::compute().

00069 {
00070    if(_file == NULL) 
00071       {
00072          printToStream(cout);
00073       }
00074    else 
00075       {
00076          printToStream(*_file);
00077       }
00078 }

template<typename BenchedController>
void PsBenchController< BenchedController >::init   [virtual]
 

create data strcutures to hold benching information

Reimplemented from PsController.

Definition at line 89 of file PsSoftRealTimeController.cxx.

References PsBenchController< BenchedController >::_endSamplingDate, PsBenchController< BenchedController >::_numberOfSamples, PsBenchController< BenchedController >::_sampleIndex, PsBenchController< BenchedController >::_slowedDownStepDurationTab, PsBenchController< BenchedController >::_startSamplingDate, PsBenchController< BenchedController >::_stepDurationTab, PsController::_stepPeriod, PsController::init(), and PsController::initialSimulationDate.

00090 {
00091    PsController::init() ;
00092 
00093    if (_startSamplingDate<PsController::initialSimulationDate) 
00094       {
00095          _startSamplingDate=PsController::initialSimulationDate;
00096          cout<<"PsBenchController::WARNING : no values PsController::initialSimulationDate ("
00097              <<PsController::initialSimulationDate<<")"<<endl;
00098       }
00099 
00100    _numberOfSamples = (_endSamplingDate-_startSamplingDate)/_stepPeriod + 1;
00101 
00102    _sampleIndex=0;
00103 
00104    _stepDurationTab = new long[_numberOfSamples];
00105    _slowedDownStepDurationTab = new long[_numberOfSamples];
00106 }

template<typename BenchedController>
void PsBenchController< BenchedController >::printToStream ostream &    out [protected, virtual]
 

write the sampled result to a stream

Parameters:
out the stream to print the result to

Definition at line 161 of file PsSoftRealTimeController.cxx.

References PsBenchController< BenchedController >::_numberOfSamples, PsBenchController< BenchedController >::_slowedDownStepDurationTab, PsBenchController< BenchedController >::_stepDurationTab, and PsController::_stepPeriod.

Referenced by PsBenchController< BenchedController >::flushResults().

00161                                                    {
00162    timespec resolutionHorloge;
00163    long moyenne;
00164    long averageTimeSlowed = 0 ;
00165    int nbValeurs;
00166    long duree;
00167    out<<syssgi(SGI_CYCLECNTR_SIZE) ;
00168    clock_getres(CLOCK_SGI_CYCLE,&resolutionHorloge);   
00169    out<<"resolution de l'horloge en secondes : "<<resolutionHorloge.tv_sec<<endl;
00170    out<<"resolution de l'horloge en nanosecondes : "<<resolutionHorloge.tv_nsec<<endl;
00171    moyenne=0;
00172    nbValeurs=0;
00173    for(int i=0;i<_numberOfSamples;i++) {
00174       duree=_stepDurationTab[i];
00175       out<<duree/1000<<" "<<_slowedDownStepDurationTab[i]/1000<<endl;
00176           if (duree>=0) {
00177              moyenne = moyenne+(duree/1000);
00178              averageTimeSlowed = averageTimeSlowed + (_slowedDownStepDurationTab[i]/1000);
00179              nbValeurs++;
00180           }
00181    }
00182    out<<"Soit une moyenne corrigée de : "<<moyenne/nbValeurs<<" microsecondes"<<endl; 
00183    out<<"Soit une moyenne ralentie de : "<<averageTimeSlowed/(1000*nbValeurs)<<" millisecondes "<<_stepPeriod<<endl; 
00184 }


Member Data Documentation

template<typename BenchedController>
PsDate PsBenchController< BenchedController >::_endSamplingDate [protected]
 

the date at wich sampling finishes

Reimplemented from PsTimerController< BenchedController >.

Definition at line 76 of file PsSoftRealTimeController.h.

Referenced by PsBenchController< BenchedController >::advanceSimulatedDate(), PsBenchController< BenchedController >::compute(), PsBenchController< BenchedController >::createScheduler(), and PsBenchController< BenchedController >::init().

template<typename BenchedController>
ofstream* PsBenchController< BenchedController >::_file [protected]
 

a pointer to the file to which is written all data collected

Definition at line 82 of file PsSoftRealTimeController.h.

template<typename BenchedController>
ofstream* PsBenchController< BenchedController >::_file [protected]
 

a pointer to the file to which is written all data collected

Definition at line 63 of file PsBenchController.h.

Referenced by PsBenchController< BenchedController >::createScheduler(), PsBenchController< BenchedController >::flushResults(), PsBenchController< BenchedController >::PsBenchController(), and PsBenchController< BenchedController >::~PsBenchController().

template<typename BenchedController>
unsigned int PsBenchController< BenchedController >::_numberOfSamples [protected]
 

the number of samples to take

Reimplemented from PsTimerController< BenchedController >.

Definition at line 70 of file PsSoftRealTimeController.h.

Referenced by PsBenchController< BenchedController >::compute(), PsBenchController< BenchedController >::createScheduler(), PsBenchController< BenchedController >::init(), and PsBenchController< BenchedController >::printToStream().

template<typename BenchedController>
PsString PsBenchController< BenchedController >::_resultFilename [protected]
 

the file name to which the results must be written

Definition at line 61 of file PsSoftRealTimeController.h.

Referenced by PsBenchController< BenchedController >::PsBenchController().

template<typename BenchedController>
int PsBenchController< BenchedController >::_sampleIndex [protected]
 

index of the current sample

Definition at line 79 of file PsSoftRealTimeController.h.

Referenced by PsBenchController< BenchedController >::advanceSimulatedDate(), PsBenchController< BenchedController >::compute(), PsBenchController< BenchedController >::createScheduler(), and PsBenchController< BenchedController >::init().

template<typename BenchedController>
long* PsBenchController< BenchedController >::_slowedDownStepDurationTab [protected]
 

a table recording the time, it took to calculate and wait for each simualtion step

Definition at line 67 of file PsSoftRealTimeController.h.

Referenced by PsBenchController< BenchedController >::compute(), PsBenchController< BenchedController >::init(), and PsBenchController< BenchedController >::printToStream().

template<typename BenchedController>
PsDate PsBenchController< BenchedController >::_startSamplingDate [protected]
 

the date at wich sampling starts

Reimplemented from PsTimerController< BenchedController >.

Definition at line 73 of file PsSoftRealTimeController.h.

Referenced by PsBenchController< BenchedController >::advanceSimulatedDate(), PsBenchController< BenchedController >::compute(), PsBenchController< BenchedController >::createScheduler(), and PsBenchController< BenchedController >::init().

template<typename BenchedController>
long* PsBenchController< BenchedController >::_stepDurationTab [protected]
 

a table recording the time it took to calculated each simulation step

Reimplemented in PsPvmBenchController< APvmController >, and PsPvmBenchController< PsMultiThreadedPvmController >.

Definition at line 64 of file PsSoftRealTimeController.h.

Referenced by PsBenchController< BenchedController >::compute(), PsBenchController< BenchedController >::init(), and PsBenchController< BenchedController >::printToStream().


The documentation for this class was generated from the following files:
logo OpenMask

Documentation generated on Mon Nov 25 15:25:52 2002

Generated with doxygen 1.2.12 by Dimitri van Heesch ,   1997-2001