Switch to unified view

a b/src/chrono.h
1
/* Copyright (C) 2016 J.F.Dockes
2
 *   This program is free software; you can redistribute it and/or modify
3
 *   it under the terms of the GNU General Public License as published by
4
 *   the Free Software Foundation; either version 2 of the License, or
5
 *   (at your option) any later version.
6
 *
7
 *   This program is distributed in the hope that it will be useful,
8
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 *   GNU General Public License for more details.
11
 *
12
 *   You should have received a copy of the GNU General Public License
13
 *   along with this program; if not, write to the
14
 *   Free Software Foundation, Inc.,
15
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16
 */
17
#ifndef _CHRONO_H_
18
#define _CHRONO_H_
19
#include <chrono>
20
21
/** Easy interface to measuring time intervals */
22
class Chrono {
23
public:
24
    /** Initialize, setting the origin time */
25
    Chrono();
26
27
    /** Re-store current time and return mS since init or last call */
28
    long restart();
29
    /** Re-store current time and return uS since init or last call */
30
    long urestart();
31
32
    /** Snapshot current time to static storage */
33
    static void refnow();
34
35
    /** Return interval value in various units.
36
     *
37
     * Frozen means give time since the last refnow call (this is to
38
     * allow for using one actual system call to get values from many
39
     * chrono objects, like when examining timeouts in a queue
40
     */
41
    long millis(bool frozen = false);
42
    long micros(bool frozen = false);
43
    float secs(bool frozen = false);
44
45
private:
46
    typedef std::chrono::time_point<std::chrono::steady_clock> TimePoint;
47
    TimePoint m_orig;
48
    static TimePoint o_now;
49
};
50
51
#endif /* _CHRONO_H_ */