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 // VISU VISUGUI : GUI of VISU component
23 // File : VisuGUI_Timer.cxx
26 #include "VisuGUI_Timer.h"
28 #include "SUIT_Desktop.h"
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 VisuGUI_Timer::VisuGUI_Timer() :
47 VisuGUI_Timer::~VisuGUI_Timer()
51 void VisuGUI_Timer::Start()
56 times(RefToInitialTMS);
57 gettimeofday(RefToInitialTimeB,tz);
61 SystemTimeToFileTime(&st, RefToInitialTMS);
62 time(RefToCurrentTimeB);
67 void VisuGUI_Timer::Stop()
71 times(RefToCurrentTMS);
72 int diffr_user = RefToCurrentTMS->tms_utime - RefToInitialTMS->tms_utime;
73 int diffr_sys = RefToCurrentTMS->tms_stime - RefToInitialTMS->tms_stime;
74 gettimeofday(RefToCurrentTimeB,tz);
76 static long aCLK_TCK=sysconf(_SC_CLK_TCK);
77 Cumul_user += (double) diffr_user / aCLK_TCK ;
78 Cumul_sys += (double) diffr_sys / aCLK_TCK ;
82 SystemTimeToFileTime(&st, RefToCurrentTMS);
83 Cumul_user += (int)(((ULARGE_INTEGER*)(RefToCurrentTMS))->QuadPart - ((ULARGE_INTEGER*)(RefToInitialTMS))->QuadPart) / 10000000;
84 Cumul_sys = Cumul_user;
85 time(RefToCurrentTimeB);
91 void VisuGUI_Timer::Reset() {
93 Cumul_user = Cumul_sys = 0. ;
96 QString VisuGUI_Timer::GetTime() {
97 bool StopSav = Stopped;
100 return QString::number( Cumul_user );
102 if (!StopSav) Start();