1 // Copyright (C) 2007-2012 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
23 // SALOME Utils : general SALOME's definitions and tools
24 // File : Utils_Timer.cxx
27 # include "Utils_Timer.hxx"
31 #include "utilities.h"
34 static struct timezone *tz=(struct timezone*) malloc(sizeof(struct timezone));
36 //timezone *tz=_timezone;
40 # define CLK_TCK CLOCKS_PER_SEC
43 Utils_Timer::Utils_Timer() {
45 RefToInitialTMS = new tms;
46 RefToCurrentTMS = new tms;
48 RefToInitialTimeB = new timeval;
49 RefToCurrentTimeB = new timeval;
51 RefToInitialTMS = new FILETIME;
52 RefToCurrentTMS = new FILETIME;
54 RefToInitialTimeB = new time_t;
55 RefToCurrentTimeB = new time_t;
58 Cumul_user = Cumul_sys = 0.;
62 Utils_Timer::~Utils_Timer() {
63 delete RefToInitialTMS ;
64 delete RefToCurrentTMS ;
66 delete RefToInitialTimeB ;
67 delete RefToCurrentTimeB ;
70 void Utils_Timer::Start() {
74 times(RefToInitialTMS);
75 gettimeofday(RefToInitialTimeB,tz);
79 SystemTimeToFileTime(&st, RefToInitialTMS);
80 time(RefToCurrentTimeB);
85 void Utils_Timer::Stop() {
88 times(RefToCurrentTMS);
89 int diffr_user = RefToCurrentTMS->tms_utime - RefToInitialTMS->tms_utime;
90 int diffr_sys = RefToCurrentTMS->tms_stime - RefToInitialTMS->tms_stime;
91 gettimeofday(RefToCurrentTimeB,tz);
93 Cumul_user += (double) diffr_user / CLK_TCK ;
94 Cumul_sys += (double) diffr_sys / CLK_TCK ;
98 SystemTimeToFileTime(&st, RefToCurrentTMS);
99 Cumul_user += (int)(((ULARGE_INTEGER*)(RefToCurrentTMS))->QuadPart - ((ULARGE_INTEGER*)(RefToInitialTMS))->QuadPart) / 10000000;
100 Cumul_sys = Cumul_user;
101 time(RefToCurrentTimeB);
107 void Utils_Timer::Show() {
108 bool StopSav = Stopped;
109 if (!StopSav) Stop();
110 MESSAGE("CPU user time: " << Cumul_user << " seconds ");
111 MESSAGE("CPU system time: " << Cumul_sys << " seconds ");
112 if (!StopSav) Start();
115 void Utils_Timer::Reset() {
117 Cumul_user = Cumul_sys = 0. ;
120 void Utils_Timer::ShowAbsolute(){
121 #if defined(_DEBUG_) || defined(_DEBUG)
123 unsigned long Absolute_user = (unsigned long) ((timeval*)RefToCurrentTimeB)->tv_sec ;
125 unsigned long Absolute_user = (unsigned long) *RefToCurrentTimeB;
127 MESSAGE("Absolute time: " << Absolute_user << " seconds ");