xref: /openbmc/telemetry/src/utils/clock.hpp (revision 8069771c0db62887b72aa2b8c51cd64eb5f99b2d)
1*8069771cSKrzysztof Grobelny #pragma once
2*8069771cSKrzysztof Grobelny 
3*8069771cSKrzysztof Grobelny #include "interfaces/clock.hpp"
4*8069771cSKrzysztof Grobelny #include "types/duration_type.hpp"
5*8069771cSKrzysztof Grobelny 
6*8069771cSKrzysztof Grobelny #include <chrono>
7*8069771cSKrzysztof Grobelny 
8*8069771cSKrzysztof Grobelny class Clock : public interfaces::Clock
9*8069771cSKrzysztof Grobelny {
10*8069771cSKrzysztof Grobelny   public:
11*8069771cSKrzysztof Grobelny     time_point now() const noexcept override
12*8069771cSKrzysztof Grobelny     {
13*8069771cSKrzysztof Grobelny         return std::chrono::steady_clock::now();
14*8069771cSKrzysztof Grobelny     }
15*8069771cSKrzysztof Grobelny 
16*8069771cSKrzysztof Grobelny     uint64_t timestamp() const noexcept override
17*8069771cSKrzysztof Grobelny     {
18*8069771cSKrzysztof Grobelny         return std::chrono::time_point_cast<Milliseconds>(now())
19*8069771cSKrzysztof Grobelny             .time_since_epoch()
20*8069771cSKrzysztof Grobelny             .count();
21*8069771cSKrzysztof Grobelny     }
22*8069771cSKrzysztof Grobelny };
23