Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / bases / chrono.cxx
diff --git a/src/bases/chrono.cxx b/src/bases/chrono.cxx
new file mode 100644 (file)
index 0000000..115794a
--- /dev/null
@@ -0,0 +1,67 @@
+
+#include "chrono.hxx"
+
+#define _DEVDEBUG_
+#include "YacsTrace.hxx"
+
+using namespace std;
+
+cntStruct* counters::_ctrs = 0;
+  
+counters::counters(int nb)
+{
+  DEBTRACE("counters::counters(int nb)");
+  _nbChrono = nb;
+  _ctrs = new cntStruct[_nbChrono];
+
+  for (int i=0; i< _nbChrono; i++)
+    {
+      _ctrs[i]._ctrNames = 0;
+      _ctrs[i]._ctrLines = 0;
+      _ctrs[i]._ctrOccur = 0;
+      _ctrs[i]._ctrCumul = 0;
+    }
+
+  DEBTRACE("counters::counters()");
+}
+
+counters::~counters()
+{
+  stats();
+}
+
+void counters::stats()
+{
+  DEBTRACE("counters::stats()");
+  for (int i=0; i < _nbChrono; i++)
+    if (_ctrs[i]._ctrOccur)
+      {
+        DEBTRACE("Compteur[" << i << "]: "<< _ctrs[i]._ctrNames << "[" << _ctrs[i]._ctrLines << "]");
+        DEBTRACE("  " << _ctrs[i]._ctrOccur);
+        DEBTRACE("  " << _ctrs[i]._ctrCumul);
+      }
+}
+
+
+
+chrono::chrono(int i) : _ctr(i), _run(true)
+{
+  _start = clock();    
+}
+
+chrono::~chrono()
+{
+  if (_run) stop();
+}
+
+void chrono::stop()
+{
+  if (_run)
+    {
+      _run = false;
+      _end = clock();
+      double elapse = double(_end - _start)/double(CLOCKS_PER_SEC);
+      counters::_ctrs[_ctr]._ctrOccur++;
+      counters::_ctrs[_ctr]._ctrCumul += elapse;
+    }
+}