1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SALOME Utils : general SALOME's definitions and tools
23 // File : Utils_Timer.cxx
26 # include "Utils_Timer.hxx"
30 #include "utilities.h"
33 static struct timezone *tz=(struct timezone*) malloc(sizeof(struct timezone));
35 //timezone *tz=_timezone;
39 # define CLK_TCK CLOCKS_PER_SEC
42 Utils_Timer::Utils_Timer() {
44 RefToInitialTMS = new tms;
45 RefToCurrentTMS = new tms;
47 RefToInitialTimeB = new timeval;
48 RefToCurrentTimeB = new timeval;
50 RefToInitialTMS = new FILETIME;
51 RefToCurrentTMS = new FILETIME;
53 RefToInitialTimeB = new time_t;
54 RefToCurrentTimeB = new time_t;
57 Cumul_user = Cumul_sys = 0.;
61 Utils_Timer::~Utils_Timer() {
62 delete RefToInitialTMS ;
63 delete RefToCurrentTMS ;
65 delete RefToInitialTimeB ;
66 delete RefToCurrentTimeB ;
69 void Utils_Timer::Start() {
73 times(RefToInitialTMS);
74 gettimeofday(RefToInitialTimeB,tz);
78 SystemTimeToFileTime(&st, RefToInitialTMS);
79 time(RefToCurrentTimeB);
84 void Utils_Timer::Stop() {
87 times(RefToCurrentTMS);
88 int diffr_user = RefToCurrentTMS->tms_utime - RefToInitialTMS->tms_utime;
89 int diffr_sys = RefToCurrentTMS->tms_stime - RefToInitialTMS->tms_stime;
90 gettimeofday(RefToCurrentTimeB,tz);
92 Cumul_user += (double) diffr_user / CLK_TCK ;
93 Cumul_sys += (double) diffr_sys / CLK_TCK ;
97 SystemTimeToFileTime(&st, RefToCurrentTMS);
98 Cumul_user += (int)(((ULARGE_INTEGER*)(RefToCurrentTMS))->QuadPart - ((ULARGE_INTEGER*)(RefToInitialTMS))->QuadPart) / 10000000;
99 Cumul_sys = Cumul_user;
100 time(RefToCurrentTimeB);
106 void Utils_Timer::Show() {
107 bool StopSav = Stopped;
108 if (!StopSav) Stop();
109 MESSAGE("CPU user time: " << Cumul_user << " seconds ");
110 MESSAGE("CPU system time: " << Cumul_sys << " seconds ");
111 if (!StopSav) Start();
114 void Utils_Timer::Reset() {
116 Cumul_user = Cumul_sys = 0. ;
119 void Utils_Timer::ShowAbsolute(){
120 #if defined(_DEBUG_) || defined(_DEBUG)
122 unsigned long Absolute_user = (unsigned long) ((timeval*)RefToCurrentTimeB)->tv_sec ;
124 unsigned long Absolute_user = *RefToCurrentTimeB;
126 MESSAGE("Absolute time: " << Absolute_user << " seconds ");