00001 00005 00006 #include <stdlib.h> 00007 #include "LBDatabase.h" 00008 #include "LBMachineUtil.h" 00009 00010 inline void LBMachineUtil::IdleStart(double curWallTime) 00011 { 00012 start_idle = curWallTime; 00013 } 00014 00015 inline void LBMachineUtil::IdleEnd(double curWallTime) 00016 { 00017 // skip counting idle time in BigSim 00018 if (state == on) { 00019 const double stop_idle = curWallTime; 00020 total_idletime += (stop_idle - start_idle); 00021 } 00022 } 00023 00024 void LBMachineUtil::staticIdleStart(LBMachineUtil* obj,double curWallTime) 00025 { 00026 obj->IdleStart(curWallTime); 00027 } 00028 void LBMachineUtil::staticIdleEnd(LBMachineUtil* obj,double curWallTime) 00029 { 00030 obj->IdleEnd(curWallTime); 00031 } 00032 00033 LBMachineUtil::LBMachineUtil() 00034 { 00035 state = off; 00036 total_walltime = 0.0; 00037 total_idletime = 0.0; 00038 start_totalwall = -1.; 00039 start_idle = -1.; 00040 #if CMK_LB_CPUTIMER 00041 total_cputime = 0.0; 00042 start_totalcpu = -1.; 00043 #endif 00044 } 00045 00046 void LBMachineUtil::StatsOn() 00047 { 00048 const double cur_wall = CkWallTimer(); 00049 #if CMK_LB_CPUTIMER 00050 const double cur_cpu = CkCpuTimer(); 00051 #endif 00052 00053 if (state == off) { 00054 #if ! CMK_BIGSIM_CHARM 00055 cancel_idleStart=CcdCallOnConditionKeep( 00056 CcdPROCESSOR_BEGIN_IDLE,(CcdVoidFn)staticIdleStart,(void *)this); 00057 cancel_idleEnd=CcdCallOnConditionKeep( 00058 CcdPROCESSOR_END_IDLE,(CcdVoidFn)staticIdleEnd,(void *)this); 00059 #endif 00060 state = on; 00061 } 00062 00063 if (start_totalwall != -1.) { 00064 total_walltime += (cur_wall - start_totalwall); 00065 #if CMK_LB_CPUTIMER 00066 total_cputime += (cur_cpu - start_totalcpu); 00067 #endif 00068 } 00069 start_totalwall = cur_wall; 00070 #if CMK_LB_CPUTIMER 00071 start_totalcpu = cur_cpu; 00072 #endif 00073 } 00074 00075 void LBMachineUtil::StatsOff() 00076 { 00077 if (state == on) { 00078 #if ! CMK_BIGSIM_CHARM 00079 CcdCancelCallOnConditionKeep(CcdPROCESSOR_BEGIN_IDLE,cancel_idleStart); 00080 CcdCancelCallOnConditionKeep(CcdPROCESSOR_END_IDLE,cancel_idleEnd); 00081 #endif 00082 state = off; 00083 } 00084 00085 if (start_totalwall != -1.) { 00086 const double cur_wall = CkWallTimer(); 00087 total_walltime += (cur_wall - start_totalwall); 00088 #if CMK_LB_CPUTIMER 00089 const double cur_cpu = CkCpuTimer(); 00090 total_cputime += (cur_cpu - start_totalcpu); 00091 #endif 00092 } 00093 start_totalwall = -1.; 00094 #if CMK_LB_CPUTIMER 00095 start_totalcpu = -1.; 00096 #endif 00097 } 00098 00099 void LBMachineUtil::Clear() 00100 { 00101 total_walltime = 0.0; 00102 #if CMK_LB_CPUTIMER 00103 total_cputime = 0.0; 00104 #endif 00105 00106 if (state == off) { 00107 start_totalwall = -1.; 00108 #if CMK_LB_CPUTIMER 00109 start_totalcpu = -1.; 00110 #endif 00111 } else { 00112 const double cur_wall = CkWallTimer(); 00113 #if CMK_LB_CPUTIMER 00114 const double cur_cpu = CkCpuTimer(); 00115 #endif 00116 00117 start_totalwall = cur_wall; 00118 #if CMK_LB_CPUTIMER 00119 start_totalcpu = cur_cpu; 00120 #endif 00121 } 00122 total_idletime = 0.0; 00123 start_idle = -1.; 00124 } 00125 00126 void LBMachineUtil::TotalTime(LBRealType* walltime, LBRealType* cputime) 00127 { 00128 if (state == on) { 00129 const double cur_wall = CkWallTimer(); 00130 #if CMK_LB_CPUTIMER 00131 const double cur_cpu = CkCpuTimer(); 00132 #endif 00133 total_walltime += (cur_wall - start_totalwall); 00134 start_totalwall = cur_wall; 00135 #if CMK_LB_CPUTIMER 00136 total_cputime += (cur_cpu - start_totalcpu); 00137 start_totalcpu = cur_cpu; 00138 #endif 00139 } 00140 *walltime = total_walltime; 00141 #if CMK_LB_CPUTIMER 00142 *cputime = total_cputime; 00143 #else 00144 *cputime = *walltime; 00145 #endif 00146 } 00147