1 // SALOME Utils : general SALOME's definitions and tools
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : Utils_Timer.cxx
27 # include "Utils_Timer.hxx"
31 static struct timezone *tz=(struct timezone*) malloc(sizeof(struct timezone));
34 # define CLK_TCK CLOCKS_PER_SEC
37 Utils_Timer::Utils_Timer() {
38 RefToInitialTMS = new tms;
39 RefToCurrentTMS = new tms;
41 RefToInitialTimeB = new timeval;
42 RefToCurrentTimeB = new timeval;
44 Cumul_user = Cumul_sys = 0.;
48 Utils_Timer::~Utils_Timer() {
49 delete RefToInitialTMS ;
50 delete RefToCurrentTMS ;
52 delete RefToInitialTimeB ;
53 delete RefToCurrentTimeB ;
56 void Utils_Timer::Start() {
59 times(RefToInitialTMS);
60 gettimeofday(RefToInitialTimeB,tz);
64 void Utils_Timer::Stop() {
66 times(RefToCurrentTMS);
67 int diffr_user = RefToCurrentTMS->tms_utime - RefToInitialTMS->tms_utime;
68 int diffr_sys = RefToCurrentTMS->tms_stime - RefToInitialTMS->tms_stime;
69 gettimeofday(RefToCurrentTimeB,tz);
71 Cumul_user += (double) diffr_user / CLK_TCK ;
72 Cumul_sys += (double) diffr_sys / CLK_TCK ;
78 void Utils_Timer::Show() {
79 bool StopSav = Stopped;
81 cout << "CPU user time: " << Cumul_user << " seconds " << endl;
82 cout << "CPU system time: " << Cumul_sys << " seconds " << endl;
83 if (!StopSav) Start();
86 void Utils_Timer::Reset() {
88 Cumul_user = Cumul_sys = 0. ;
91 void Utils_Timer::ShowAbsolute(){
92 unsigned long Absolute_user = (unsigned long) ((timeval*)RefToCurrentTimeB)->tv_sec ;
93 cout << "Absolute time: " << Absolute_user << " seconds " << endl;