summaryrefslogtreecommitdiff
path: root/src/util/timer.cpp
blob: d56860d193611f51d20308c3feb54e9bac84f145 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef DISABLE_TIMER
#include <mbgl/util/timer.hpp>
#include <mbgl/util/time.hpp>
#include <mbgl/platform/log.hpp>

#include <iostream>
#include <atomic>

using namespace mbgl::util;

timer::timer(Event event)
    : event(event), start(now()) {}

timer::timer(EventSeverity severity, Event event)
    : severity(severity), event(event), start(now()) {}

timer::timer(const std::string &name, Event event)
    : name(name), event(event), start(now()) {}

timer::timer(const std::string &name, EventSeverity severity, Event event)
    : name(name), severity(severity), event(event), start(now()) {}

void timer::report(const std::string &name) {
    timestamp duration = now() - start;

    Log::Record(severity, event, name + ": " + std::to_string((double)(duration) / 1_millisecond) + "ms");
    start += duration;
}

timer::~timer() {
    if (name.size()) {
        report(name);
    }
}
#endif