cprover
Toggle main menu visibility
Loading...
Searching...
No Matches
timestamper.cpp
Go to the documentation of this file.
1
/*******************************************************************\
2
3
Module: Timestamps
4
5
Author: Kareem Khazem <karkhaz@karkhaz.com>
6
7
\*******************************************************************/
8
9
#include "
timestamper.h
"
10
11
#include <chrono>
12
#include <cstdlib>
13
#include <iomanip>
14
#include <sstream>
15
16
#include "
invariant.h
"
17
18
std::unique_ptr<const timestampert>
19
timestampert::make
(
timestampert::clockt
clock_type)
20
{
21
#ifdef _WIN32
22
(void)clock_type;
// unused parameter
23
return
std::unique_ptr<const timestampert>(
new
timestampert
());
24
#else
25
switch
(clock_type)
26
{
27
case
timestampert::clockt::NONE
:
28
return
std::unique_ptr<const timestampert>(
new
timestampert
());
29
case
timestampert::clockt::MONOTONIC
:
30
return
std::unique_ptr<const monotonic_timestampert>(
31
new
monotonic_timestampert
());
32
case
timestampert::clockt::WALL_CLOCK
:
33
return
std::unique_ptr<const wall_clock_timestampert>(
34
new
wall_clock_timestampert
());
35
}
36
UNREACHABLE
;
37
#endif
38
}
39
40
#ifndef _WIN32
41
std::string
monotonic_timestampert::stamp
()
const
42
{
43
std::chrono::time_point<std::chrono::steady_clock, std::chrono::microseconds>
44
time_stamp = std::chrono::time_point_cast<std::chrono::microseconds>(
45
std::chrono::steady_clock::now());
46
47
auto
cnt = time_stamp.time_since_epoch().count();
48
std::lldiv_t divmod = lldiv(cnt, 1000000);
49
50
std::stringstream ss;
51
ss << divmod.quot <<
"."
<< std::setfill(
'0'
) << std::setw(6) << divmod.rem;
52
return
ss.str();
53
}
54
55
#define WALL_FORMAT "%Y-%m-%dT%H:%M:%S."
56
57
std::string
wall_clock_timestampert::stamp
()
const
58
{
59
std::chrono::time_point<std::chrono::system_clock, std::chrono::microseconds>
60
time_stamp = std::chrono::time_point_cast<std::chrono::microseconds>(
61
std::chrono::system_clock::now());
62
63
unsigned
u_seconds = time_stamp.time_since_epoch().count() % 1000000;
64
65
std::time_t tt = std::chrono::system_clock::to_time_t(time_stamp);
66
std::tm local = *std::localtime(&tt);
67
68
std::stringstream ss;
69
ss << std::put_time(&local,
WALL_FORMAT
) << std::setfill(
'0'
) << std::setw(6)
70
<< u_seconds;
71
return
ss.str();
72
}
73
#endif
monotonic_timestampert
Definition
timestamper.h:68
monotonic_timestampert::stamp
virtual std::string stamp() const override
See HELP_TIMESTAMP in util/timestamper.h for time stamp format.
Definition
timestamper.cpp:41
timestampert
Timestamp class hierarchy.
Definition
timestamper.h:42
timestampert::clockt
clockt
Derived types of timestampert.
Definition
timestamper.h:46
timestampert::clockt::MONOTONIC
@ MONOTONIC
monotonic_timestampert
Definition
timestamper.h:50
timestampert::clockt::WALL_CLOCK
@ WALL_CLOCK
wall_clock_timestampert
Definition
timestamper.h:52
timestampert::clockt::NONE
@ NONE
timestampert
Definition
timestamper.h:48
timestampert::make
static std::unique_ptr< const timestampert > make(clockt clock_type)
Factory method to build timestampert subclasses.
Definition
timestamper.cpp:19
wall_clock_timestampert
Definition
timestamper.h:76
wall_clock_timestampert::stamp
virtual std::string stamp() const override
See HELP_TIMESTAMP in util/timestamper.h for time stamp format.
Definition
timestamper.cpp:57
invariant.h
UNREACHABLE
#define UNREACHABLE
This should be used to mark dead code.
Definition
invariant.h:525
WALL_FORMAT
#define WALL_FORMAT
Definition
timestamper.cpp:55
timestamper.h
Emit timestamps.
util
timestamper.cpp
Generated by
1.17.0