Salome HOME
d78348b59c947f94b6a35bb3632bdcb87a77d31a
[modules/visu.git] / src / VISUGUI / VisuGUI_Timer.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  VISU VISUGUI : GUI of VISU component
23 //  File   : VisuGUI_Timer.cxx
24 //  Module : SALOME
25 //
26 #include "VisuGUI_Timer.h"
27
28 #include "SUIT_Desktop.h"
29
30 #include "utilities.h"
31
32 #ifndef WNT
33 static struct timezone *tz=(struct timezone*) malloc(sizeof(struct timezone));
34 #else
35 //timezone *tz=_timezone;
36 #endif
37
38 #ifndef CLK_TCK
39 # define CLK_TCK      CLOCKS_PER_SEC
40 #endif
41
42 VisuGUI_Timer::VisuGUI_Timer() :
43   Utils_Timer()
44 {
45 }
46
47 VisuGUI_Timer::~VisuGUI_Timer()
48 {
49 }
50
51 void VisuGUI_Timer::Start()
52 {
53   if (Stopped) {
54     Stopped = 0;
55 #ifndef WNT
56     times(RefToInitialTMS);
57     gettimeofday(RefToInitialTimeB,tz);
58 #else
59     SYSTEMTIME st;
60     GetSystemTime(&st);
61     SystemTimeToFileTime(&st, RefToInitialTMS);
62           time(RefToCurrentTimeB);
63 #endif
64   }
65 }
66
67 void VisuGUI_Timer::Stop()
68 {
69   if (!Stopped) {
70 #ifndef WNT
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);
75
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 ;
79 #else
80     SYSTEMTIME st;
81     GetSystemTime(&st);
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);
86 #endif
87    Stopped = 1;
88   }
89 }
90
91 void VisuGUI_Timer::Reset() {
92   Stopped     = 1;
93   Cumul_user  = Cumul_sys = 0. ;
94 }
95
96 QString VisuGUI_Timer::GetTime() {
97   bool StopSav = Stopped;
98   if (!StopSav) Stop();
99
100   return QString::number( Cumul_user );
101
102   if (!StopSav) Start();
103 }