Commit in projects/lcdd/trunk/include/lcdd/util on MAIN
TimerUtil.hh+58added 3115
Change name of class to avoid naming clash with SLIC.

projects/lcdd/trunk/include/lcdd/util
TimerUtil.hh added at 3115
--- projects/lcdd/trunk/include/lcdd/util/TimerUtil.hh	                        (rev 0)
+++ projects/lcdd/trunk/include/lcdd/util/TimerUtil.hh	2014-05-08 23:24:03 UTC (rev 3115)
@@ -0,0 +1,58 @@
+#ifndef lcdd_util_TimerUtil_hh_
+#define lcdd_util_TimerUtil_hh_ 1
+
+#include <sys/time.h>
+
+#include <string>
+#include <map>
+#include <iostream>
+
+class TimerUtil {
+
+    static std::map<std::string, long> _timerMap;
+
+public:
+
+    static long getNanoTime() {
+        timespec ts;
+        clock_gettime(CLOCK_REALTIME, &ts);
+        return ts.tv_nsec;
+    }
+
+    static bool haveTimer(const std::string& name) {
+        return _timerMap.count(name) != 0;
+    }
+
+    static void startTimer(const std::string& name) {
+        _timerMap[name] = getNanoTime();
+    }
+
+    static long stopTimer(const std::string& name) {
+        _timerMap[name] = getNanoTime() - _timerMap[name];
+        return _timerMap[name];
+    }
+
+    static void addTime(const std::string& name, long nanos) {
+        if (!haveTimer(name))
+            createTimer(name);
+        _timerMap[name] += nanos;
+    }
+
+    static void createTimer(const std::string& name) {
+        _timerMap[name] = 0;
+    }
+
+    static long getTime(const std::string& name) {
+        return _timerMap[name];
+    }
+
+    static void printOut(const std::string& name, std::ostream& os) {
+        os << name << ": " << _timerMap[name] << std::endl;
+    }
+
+    static void clearTimers() {
+        _timerMap.clear();
+    }
+};
+
+#endif
SVNspam 0.1


Use REPLY-ALL to reply to list

To unsubscribe from the LCDET-SVN list, click the following link:
https://listserv.slac.stanford.edu/cgi-bin/wa?SUBED1=LCDET-SVN&A=1