class mrpt::Clock

Clock that is compatible with MRPT TTimeStamp representation.

#include <mrpt/core/Clock.h>

class Clock
{
public:
    // typedefs

    typedef int64_t rep;
    typedef std::ratio<1, 10000000> period;
    typedef std::chrono::duration<rep, period> duration;
    typedef std::chrono::time_point<Clock> time_point;

    // enums

    enum Source;

    //
fields

    static constexpr bool is_steady = std::chrono::system_clock::is_steady;

    //
methods

    static time_point now();
    static time_point fromDouble(const double t);
    static double toDouble(const time_point t);
    static void setActiveClock(const Source s);
    static Source getActiveClock();
    static int64_t resetMonotonicToRealTimeEpoch();
    static uint64_t getMonotonicToRealtimeOffset();
};

Methods

static time_point now()

Returns the current time using the currently selected Clock source.

See also:

setActiveClock(), mrpt::Clock::Source

static time_point fromDouble(const double t)

Create a timestamp from its double representation.

See also:

toDouble

static double toDouble(const time_point t)

Converts a timestamp to a UNIX time_t-like number, with fractional part.

See also:

fromDouble

static void setActiveClock(const Source s)

Changes the selected clock to get time from when calling now().

Default: Realtime. Ignored in non-Linux systems.

static Source getActiveClock()

Returns the currently selected clock.

static int64_t resetMonotonicToRealTimeEpoch()

Monotonic clock might drift over time with respect to Realtime.

The first time a time is requested to now() with Monotonic clock enabled, MRPT internally saves the current values of both, Realtime and Monotonic clocks, then use the difference in all subsequent calls to set Monotonic timepoints in the same epoch than Realtime.

By explicitly calling this static method, a user is able to force a resynchrnization between the two clocks. Potentially useful for systems that run for very long periods of time without interruption.

This method is ignored in non-Linux systems.

Returns:

The mismatch between the former and the new estimations of the epochs differences between the two clocks, in units of nanoseconds.

static uint64_t getMonotonicToRealtimeOffset()

Returns the number of nanoseconds that are added to the output of the POSIX CLOCK_MONOTONIC to make timestamps match the epoch of POSIX CLOCK_REALTIME.