Skip to content

Commit

Permalink
add MonotonicTimer
Browse files Browse the repository at this point in the history
  • Loading branch information
asmuth committed Jul 22, 2017
1 parent 00efa3c commit 896b40d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/showtime/util/time.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ uint64_t MonotonicClock::now() {
#endif
}

MonotonicTimer::MonotonicTimer() { reset(); }

MonotonicTimer::Tick MonotonicTimer::next() {
auto tB = MonotonicClock::now();
auto t = tB - t0_;
auto dt = tB - tA_;
tA_ = tB;

return Tick {
.t = t,
.dt = dt
};
}

void MonotonicTimer::reset() {
t0_ = tA_ = MonotonicClock::now();
}

UnixTime::UnixTime() :
utc_micros_(WallClock::unixMicros()) {}

Expand Down
17 changes: 17 additions & 0 deletions src/showtime/util/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,23 @@ class MonotonicClock {
static uint64_t now();
};

class MonotonicTimer {
public:

struct Tick {
uint64_t t;
uint64_t dt;
};

MonotonicTimer();
Tick next();
void reset();

protected:
uint64_t t0_;
uint64_t tA_;
};

class UnixTime {
public:

Expand Down

0 comments on commit 896b40d

Please sign in to comment.