summaryrefslogtreecommitdiff
path: root/src/mbgl/util/stopwatch.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbgl/util/stopwatch.cpp')
-rw-r--r--src/mbgl/util/stopwatch.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/mbgl/util/stopwatch.cpp b/src/mbgl/util/stopwatch.cpp
new file mode 100644
index 0000000000..14b4f4018b
--- /dev/null
+++ b/src/mbgl/util/stopwatch.cpp
@@ -0,0 +1,36 @@
+#ifndef DISABLE_STOPWATCH
+#include <mbgl/util/stopwatch.hpp>
+#include <mbgl/util/time.hpp>
+#include <mbgl/util/string.hpp>
+#include <mbgl/platform/log.hpp>
+
+#include <iostream>
+#include <atomic>
+
+using namespace mbgl::util;
+
+stopwatch::stopwatch(Event event_)
+ : event(event_), start(now()) {}
+
+stopwatch::stopwatch(EventSeverity severity_, Event event_)
+ : severity(severity_), event(event_), start(now()) {}
+
+stopwatch::stopwatch(const std::string &name_, Event event_)
+ : name(name_), event(event_), start(now()) {}
+
+stopwatch::stopwatch(const std::string &name_, EventSeverity severity_, Event event_)
+ : name(name_), severity(severity_), event(event_), start(now()) {}
+
+void stopwatch::report(const std::string &name_) {
+ timestamp duration = now() - start;
+
+ Log::Record(severity, event, name_ + ": " + util::toString(double(duration) / 1_millisecond) + "ms");
+ start += duration;
+}
+
+stopwatch::~stopwatch() {
+ if (name.size()) {
+ report(name);
+ }
+}
+#endif