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"
30 #include "utilities.h"
33 static struct timezone *tz=(struct timezone*) malloc(sizeof(struct timezone));
36 # define CLK_TCK CLOCKS_PER_SEC
39 Utils_Timer::Utils_Timer() {
40 RefToInitialTMS = new tms;
41 RefToCurrentTMS = new tms;
43 RefToInitialTimeB = new timeval;
44 RefToCurrentTimeB = new timeval;
46 Cumul_user = Cumul_sys = 0.;
50 Utils_Timer::~Utils_Timer() {
51 delete RefToInitialTMS ;
52 delete RefToCurrentTMS ;
54 delete RefToInitialTimeB ;
55 delete RefToCurrentTimeB ;
58 void Utils_Timer::Start() {
61 times(RefToInitialTMS);
62 gettimeofday(RefToInitialTimeB,tz);
66 void Utils_Timer::Stop() {
68 times(RefToCurrentTMS);
69 int diffr_user = RefToCurrentTMS->tms_utime - RefToInitialTMS->tms_utime;
70 int diffr_sys = RefToCurrentTMS->tms_stime - RefToInitialTMS->tms_stime;
71 gettimeofday(RefToCurrentTimeB,tz);
73 Cumul_user += (double) diffr_user / CLK_TCK ;
74 Cumul_sys += (double) diffr_sys / CLK_TCK ;
80 void Utils_Timer::Show() {
81 bool StopSav = Stopped;
83 MESSAGE("CPU user time: " << Cumul_user << " seconds ");
84 MESSAGE("CPU system time: " << Cumul_sys << " seconds ");
85 if (!StopSav) Start();
88 void Utils_Timer::Reset() {
90 Cumul_user = Cumul_sys = 0. ;
93 void Utils_Timer::ShowAbsolute(){
94 unsigned long Absolute_user = (unsigned long) ((timeval*)RefToCurrentTimeB)->tv_sec ;
95 MESSAGE("Absolute time: " << Absolute_user << " seconds ");