00001 /* 00002 * This file is part of openMask © INRIA, CNRS, Universite de Rennes 1 1993-2002, thereinafter the Software 00003 * 00004 * The Software has been developped within the Siames Project. 00005 * INRIA, the University of Rennes 1 and CNRS jointly hold intellectual property rights 00006 * 00007 * The Software has been registered with the Agence pour la Protection des 00008 * Programmes (APP) under registration number IDDN.FR.001.510008.00.S.P.2001.000.41200 00009 * 00010 * This file may be distributed under the terms of the Q Public License 00011 * version 1.0 as defined by Trolltech AS of Norway and appearing in the file 00012 * LICENSE.QPL included in the packaging of this file. 00013 * 00014 * Licensees holding valid specific licenses issued by INRIA, CNRS or Université de Rennes 1 00015 * for the software may use this file in accordance with that specific license 00016 * 00017 */ 00018 #include "PsnBenchScheduler.h" 00019 00020 #include <fstream> 00021 #include <sys/time.h> 00022 #include <unistd.h> 00023 #include "PsnBenchScheduler.h" 00024 #include "PsnReferenceObjectHandle.h" 00025 #include "PsSimulatedObject.h" 00026 00027 PsnBenchScheduler::PsnBenchScheduler(unsigned int numberOfSteps, 00028 const int & _sampleIndex, 00029 unsigned int _numberOfSamples, 00030 ostream & outputFile ) 00031 : PsnFrameScheduler ( numberOfSteps ), 00032 _sampleIndex ( _sampleIndex ), 00033 _numberOfSamples( _numberOfSamples ), 00034 _outputFile ( outputFile ) 00035 { 00036 00037 } 00038 00039 PsnBenchScheduler::~PsnBenchScheduler() 00040 { 00041 assert (_outputFile.good() ) ; 00042 map<PsnReferenceObjectHandle *, long*>::iterator pTab; 00043 long moyenne ; 00044 long nbValeurs ; 00045 for (pTab= _tabVitesse.begin(); 00046 pTab != _tabVitesse.end(); 00047 pTab++) 00048 { 00049 //make sure the object still exists 00050 assert ( dynamic_cast<const PsSimulatedObject *>( &((*pTab).first->getSimulatedObject() ) ) ); 00051 _outputFile<<"Table des temps pour "<<(*pTab).first->getSimulatedObject().getObjectDescriptor().getName()<<endl;; 00052 moyenne=0; 00053 nbValeurs=0; 00054 for(int i=0;i<_numberOfSamples;i++) { 00055 long duree=(*pTab).second[i]; 00056 _outputFile<<duree<<endl; 00057 if (duree>=0) { 00058 #ifdef _SGI 00059 moyenne = moyenne+(duree/1000); 00060 #else 00061 moyenne +=duree ; 00062 #endif 00063 nbValeurs++; 00064 } 00065 } 00066 _outputFile<<"Average running time for "<<(*pTab).first->getSimulatedObject().getName()<<": "<<moyenne/nbValeurs<<" microseconds"<<endl; 00067 } 00068 } 00069 00070 void PsnBenchScheduler::addToScheduable(PsnReferenceObjectHandle * ref, unsigned int when ) { 00071 PsnFrameScheduler::addToScheduable( ref , when ) ; 00072 if ( _tabVitesse.find (ref) == _tabVitesse.end() ) { 00073 //to avoid multiple creation in multi-fréquential mode 00074 _tabVitesse [ ref ] = new long[ _numberOfSamples ]; 00075 } 00076 } 00077 00078 00079 00080 void PsnBenchScheduler::removeFromScheduable(PsnReferenceObjectHandle * ref) { 00081 PsnFrameScheduler::removeFromScheduable( ref ) ; 00082 assert ( _tabVitesse.find (ref) != _tabVitesse.end() ) ; 00083 00084 map<PsnReferenceObjectHandle *, long*>::iterator pTab = _tabVitesse.find (ref) ; 00085 00086 assert ( dynamic_cast<const PsSimulatedObject *>( &(*pTab).first->getSimulatedObject() ) ); 00087 00088 long moyenne=0; 00089 long nbValeurs=0; 00090 for(int i=0;i<_numberOfSamples;i++) { 00091 long duree=(*pTab).second[i]; 00092 //_outputFile<<duree<<endl; 00093 if (duree>=0) { 00094 #ifdef _SGI 00095 moyenne = moyenne+(duree/1000); 00096 #else 00097 moyenne +=duree ; 00098 #endif 00099 nbValeurs++; 00100 } 00101 } 00102 _outputFile<<"Average compute time of "<<(*pTab).first->getSimulatedObject().getObjectDescriptor().getName()<<": "<<moyenne/nbValeurs<<" microsecondes (computed using "<<nbValeurs<<" samples)"<<endl; 00103 delete [] ( _tabVitesse[ ref ] ) ; 00104 _tabVitesse.erase( ref ) ; 00105 } 00106 00107 00108 00109 void PsnBenchScheduler::runStep(unsigned int which) { 00110 #ifdef _SGI 00111 timespec avant, apres; 00112 #else 00113 timeval avant, apres ; 00114 #endif 00115 // Un pas de simulation pour les ObjetSimul de tous les referentiels 00116 PsnDoubleListElement * pListe ; 00117 for (pListe = Frames [which]->begin () ; 00118 pListe != NULL ; 00119 pListe = Frames[which]->next (pListe)) { 00120 //initialisation du compteur de cet objet 00121 #ifdef _SGI 00122 clock_gettime(CLOCK_SGI_CYCLE, &avant); 00123 #else 00124 gettimeofday(&avant, NULL); 00125 #endif 00126 (*pListe).listeElem->compute () ; 00127 #ifdef _COUTPOLATION 00128 cout<<"Calcul de "<<(*pListe).listeElem->objetSimul ()->getName()<<endl; 00129 #endif 00130 //lecture du compteur 00131 #ifdef _SGI 00132 clock_gettime(CLOCK_SGI_CYCLE, &apres); 00133 #else 00134 gettimeofday(&apres, NULL); 00135 #endif 00136 //mise à jour de la structure de donnée 00137 if( _sampleIndex >= 0 ) { 00138 #ifdef _SGI 00139 _tabVitesse[(*pListe).listeElem][_sampleIndex] = apres.tv_nsec - avant.tv_nsec; 00140 #else 00141 assert (_tabVitesse.find( (*pListe).listeElem ) != _tabVitesse.end() ) ; 00142 _tabVitesse[(*pListe).listeElem][_sampleIndex] = apres.tv_usec - avant.tv_usec; 00143 #endif 00144 } 00145 } 00146 } 00147 00148 00149 00150
| Documentation generated on Mon Nov 25 15:25:00 2002 |
Generated with doxygen 1.2.12 by Dimitri van Heesch , 1997-2001 |