ignore idle timers for BigSim, changed CmiWallTimer to CkWallTimer() to better handle...
[charm.git] / src / ck-ldb / LBMachineUtil.C
1 /*****************************************************************************
2  * $Source$
3  * $Author$
4  * $Date$
5  * $Revision$
6  *****************************************************************************/
7
8 /**
9  * \addtogroup CkLdb
10 */
11 /*@{*/
12
13 #include "LBMachineUtil.h"
14 #include <stdlib.h>
15
16 inline void LBMachineUtil::IdleStart(double curWallTime)
17 {
18   start_idle = curWallTime;
19 }
20
21 inline void LBMachineUtil::IdleEnd(double curWallTime)
22 {
23 // skip counting idle time in BigSim
24   if (state == on) {
25     const double stop_idle = curWallTime;
26     total_idletime += (stop_idle - start_idle);
27   }
28 }
29
30 void LBMachineUtil::staticIdleStart(LBMachineUtil* obj,double curWallTime)
31 {
32   obj->IdleStart(curWallTime);
33 }
34 void LBMachineUtil::staticIdleEnd(LBMachineUtil* obj,double curWallTime)
35 {
36   obj->IdleEnd(curWallTime);
37 }
38
39 LBMachineUtil::LBMachineUtil()
40 {
41   state = off;
42   total_walltime = total_cputime = 0.0;
43   total_idletime = 0;
44   start_totalwall = start_totalcpu = -1.;
45   total_idletime = 0;
46 };
47
48 void LBMachineUtil::StatsOn()
49 {
50   const double cur_wall = CkWallTimer();
51   const double cur_cpu = CkCpuTimer();
52
53   if (state == off) {
54 #if ! CMK_BLUEGENE_CHARM
55     cancel_idleStart=CcdCallOnConditionKeep(
56          CcdPROCESSOR_BEGIN_IDLE,(CcdVoidFn)staticIdleStart,(void *)this);
57     cancel_idleEnd=CcdCallOnConditionKeep(
58          CcdPROCESSOR_END_IDLE,(CcdVoidFn)staticIdleEnd,(void *)this);
59 #endif
60     state = on;
61   }
62
63   if (start_totalwall != -1.) {
64     total_walltime += (cur_wall - start_totalwall);
65     total_cputime += (cur_cpu - start_totalcpu);
66   }
67   start_totalwall = cur_wall;
68   start_totalcpu = cur_cpu;
69 }
70
71 void LBMachineUtil::StatsOff()
72 {
73   if (state == on) {
74 #if ! CMK_BLUEGENE_CHARM
75     CcdCancelCallOnConditionKeep(CcdPROCESSOR_BEGIN_IDLE,cancel_idleStart);
76     CcdCancelCallOnConditionKeep(CcdPROCESSOR_END_IDLE,cancel_idleEnd);
77 #endif
78     state = off;
79   }
80
81   if (start_totalwall != -1.) {
82     const double cur_wall = CkWallTimer();
83     const double cur_cpu = CkCpuTimer();
84     total_walltime += (cur_wall - start_totalwall);
85     total_cputime += (cur_cpu - start_totalcpu);
86   }
87   start_totalwall = start_totalcpu = -1.;
88 };
89
90 void LBMachineUtil::Clear()
91 {
92   total_walltime = total_cputime = 0;
93
94   if (state == off) {
95     start_totalwall = start_totalcpu = -1.;
96   } else {
97     const double cur_wall = CkWallTimer();
98     const double cur_cpu = CkCpuTimer();
99
100     start_totalwall = cur_wall;
101     start_totalcpu = cur_cpu;
102   }
103   total_idletime = 0;
104 }
105
106 void LBMachineUtil::TotalTime(double* walltime, double* cputime)
107 {
108   if (state == on) {
109     const double cur_wall = CkWallTimer();
110     const double cur_cpu = CkCpuTimer();
111     total_walltime += (cur_wall - start_totalwall);
112     total_cputime += (cur_cpu - start_totalcpu);
113     start_totalwall = cur_wall;
114     start_totalcpu = cur_cpu;
115   }
116   *walltime = total_walltime;
117   *cputime = total_cputime;
118 }
119
120 /*@}*/