Oops, forgot to add yesterday
authorcheckout <checkout>
Wed, 10 Nov 1999 17:51:02 +0000 (17:51 +0000)
committercheckout <checkout>
Wed, 10 Nov 1999 17:51:02 +0000 (17:51 +0000)
src/ck-ldb/LBMachineUtil.C [new file with mode: 0644]
src/ck-ldb/LBMachineUtil.h [new file with mode: 0644]

diff --git a/src/ck-ldb/LBMachineUtil.C b/src/ck-ldb/LBMachineUtil.C
new file mode 100644 (file)
index 0000000..c3daf08
--- /dev/null
@@ -0,0 +1,101 @@
+#include "LBMachineUtil.h"
+
+CpvStaticDeclare(void*,machineUtilPtr);
+
+extern "C" void staticIdleStart()
+{
+  ((LBMachineUtil*)(CpvAccess(machineUtilPtr)))->IdleStart();
+}
+
+extern "C" void staticIdleEnd()
+{
+  ((LBMachineUtil*)(CpvAccess(machineUtilPtr)))->IdleEnd();
+}
+
+
+void LBMachineUtil::IdleStart()
+{
+  start_idle = CmiWallTimer();
+}
+
+void LBMachineUtil::IdleEnd()
+{
+  if (state == on) {
+    const double stop_idle = CmiWallTimer();
+    total_idletime += (stop_idle - start_idle);
+  }
+}
+
+LBMachineUtil::LBMachineUtil()
+{
+  state = off;
+  total_walltime = total_cputime = -1.;
+  total_idletime = 0;
+  CpvInitialize(void*,machineUtilPtr);
+  CpvAccess(machineUtilPtr) = (void*)this;
+  CsdSetNotifyIdle(staticIdleStart,staticIdleEnd);
+};
+
+void LBMachineUtil::StatsOn()
+{
+  const double cur_wall = CmiWallTimer();
+  const double cur_cpu = CmiCpuTimer();
+
+  if (state == off) {
+    CsdStartNotifyIdle();
+    state = on;
+  }
+
+  if (start_totalwall != -1.) {
+    total_walltime += (cur_wall - start_totalwall);
+    total_cputime += (cur_cpu - start_totalcpu);
+  }
+  start_totalwall = cur_wall;
+  start_totalcpu = cur_cpu;
+}
+
+void LBMachineUtil::StatsOff()
+{
+  if (state == on) {
+    CsdStopNotifyIdle();
+    state = off;
+  }
+
+  if (start_totalwall != -1.) {
+    const double cur_wall = CmiWallTimer();
+    const double cur_cpu = CmiCpuTimer();
+    total_walltime += (cur_wall - start_totalwall);
+    total_cputime += (cur_cpu - start_totalcpu);
+  }
+  start_totalwall = start_totalcpu = -1.;
+};
+
+void LBMachineUtil::Clear()
+{
+  total_walltime = total_cputime = 0;
+
+  if (state == off) {
+    start_totalwall = start_totalcpu = -1.;
+  } else {
+    const double cur_wall = CmiWallTimer();
+    const double cur_cpu = CmiCpuTimer();
+
+    start_totalwall = cur_wall;
+    start_totalcpu = cur_cpu;
+  }
+  total_idletime = 0;
+}
+
+void LBMachineUtil::TotalTime(double* walltime, double* cputime)
+{
+  if (state == on) {
+    const double cur_wall = CmiWallTimer();
+    const double cur_cpu = CmiCpuTimer();
+    total_walltime += (cur_wall - start_totalwall);
+    total_cputime += (cur_cpu - start_totalcpu);
+    start_totalwall = cur_wall;
+    start_totalcpu = cur_cpu;
+  }
+  *walltime = total_walltime;
+  *cputime = total_cputime;
+}
diff --git a/src/ck-ldb/LBMachineUtil.h b/src/ck-ldb/LBMachineUtil.h
new file mode 100644 (file)
index 0000000..7cc77df
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef _LDMACHINEUTIL_H_
+#define _LDMACHINEUTIL_H_
+
+#include "converse.h"
+
+class LBMachineUtil {
+public:
+  LBMachineUtil();
+  void StatsOn();
+  void StatsOff();
+  void Clear();
+  void TotalTime(double* walltime, double* cputime);
+  void IdleTime(double* walltime) { *walltime = total_idletime; };
+  void IdleStart();
+  void IdleEnd();
+  
+private:
+  enum { off, on } state;
+  double total_walltime;
+  double total_cputime;
+  double total_idletime;
+  double start_totalwall;
+  double start_totalcpu;
+  double start_idle;
+
+};
+
+#endif  // _LDMACHINEUTIL_H_