aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/metrics/clock.h
blob: e1b0a7da00316eff5b070cad2972c9dd22b733c2 (plain) (blame)
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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include <chrono>
#include <memory>

namespace vespalib::metrics {

using TimeStamp = std::chrono::duration<double, std::ratio<1,1>>;

/**
 * Simple interface abstracting both timing and time measurement for
 * threads wanting to do stuff at regular intervals and also knowing
 * at what time stuff was done. The 'next' function blocks until the
 * next tick is due and returns the current number of seconds since
 * epoch. The parameter passed to the 'next' function should be its
 * previous return value, except the first time it is called, then 0
 * should be used. A convenience function called 'first' is added for
 * this purpose.
 **/
struct Tick {
    using UP = std::unique_ptr<Tick>;
    virtual TimeStamp next(TimeStamp prev) = 0;
    virtual TimeStamp first() = 0;
    virtual void kill() = 0;
    virtual bool alive() const = 0;
    virtual ~Tick() {}
};

} // namespace vespalib::metrics