00001 // Copyright (C) 2006-2011 CEA/DEN, EDF R&D, OPEN CASCADE 00002 // 00003 // This library is free software; you can redistribute it and/or 00004 // modify it under the terms of the GNU Lesser General Public 00005 // License as published by the Free Software Foundation; either 00006 // version 2.1 of the License. 00007 // 00008 // This library is distributed in the hope that it will be useful, 00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00011 // Lesser General Public License for more details. 00012 // 00013 // You should have received a copy of the GNU Lesser General Public 00014 // License along with this library; if not, write to the Free Software 00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00016 // 00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com 00018 // 00019 00020 #include "chrono.hxx" 00021 #include "utilities.h" 00022 00023 using namespace std; 00024 00025 cntStruct* counters::_ctrs = 0; 00026 int counters::_nbChrono = 0; 00027 00028 counters::counters(int nb) 00029 { 00030 MESSAGE("counters::counters(int nb)"); 00031 _nbChrono = nb; 00032 _ctrs = new cntStruct[_nbChrono]; 00033 00034 for (int i = 0; i < _nbChrono; i++) 00035 { 00036 _ctrs[i]._ctrNames = 0; 00037 _ctrs[i]._ctrLines = 0; 00038 _ctrs[i]._ctrOccur = 0; 00039 _ctrs[i]._ctrCumul = 0; 00040 } 00041 00042 MESSAGE("counters::counters()"); 00043 } 00044 00045 counters::~counters() 00046 { 00047 stats(); 00048 } 00049 00050 void counters::stats() 00051 { 00052 MESSAGE("counters::stats()"); 00053 for (int i = 0; i < _nbChrono; i++) 00054 if (_ctrs[i]._ctrOccur) 00055 { 00056 MESSAGE("Compteur[" << i << "]: "<< _ctrs[i]._ctrNames << "[" << _ctrs[i]._ctrLines << "]"); 00057 MESSAGE(" " << _ctrs[i]._ctrOccur); 00058 MESSAGE(" " << _ctrs[i]._ctrCumul); 00059 } 00060 } 00061 00062 chrono::chrono(int i) : 00063 _ctr(i), _run(true) 00064 { 00065 //MESSAGE("chrono::chrono " << _ctr << " " << _run); 00066 _start = clock(); 00067 } 00068 00069 chrono::~chrono() 00070 { 00071 if (_run) 00072 stop(); 00073 } 00074 00075 void chrono::stop() 00076 { 00077 //MESSAGE("chrono::stop " << _ctr << " " << _run); 00078 if (_run) 00079 { 00080 _run = false; 00081 _end = clock(); 00082 double elapse = double(_end - _start) / double(CLOCKS_PER_SEC); 00083 counters::_ctrs[_ctr]._ctrOccur++; 00084 counters::_ctrs[_ctr]._ctrCumul += elapse; 00085 } 00086 }