CBMC
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
timestamper.cpp
Go to the documentation of this file.
1/*******************************************************************\
2
3Module: Timestamps
4
5Author: 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
18std::unique_ptr<const timestampert>
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 {
28 return std::unique_ptr<const timestampert>(new timestampert());
30 return std::unique_ptr<const monotonic_timestampert>(
33 return std::unique_ptr<const wall_clock_timestampert>(
35 }
37#endif
38}
39
40#ifndef _WIN32
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
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
ait supplies three of the four components needed: an abstract interpreter (in this case handling func...
Definition ai.h:562
virtual std::string stamp() const override
See HELP_TIMESTAMP in util/timestamper.h for time stamp format.
Timestamp class hierarchy.
Definition timestamper.h:42
clockt
Derived types of timestampert.
Definition timestamper.h:46
@ MONOTONIC
monotonic_timestampert
@ WALL_CLOCK
wall_clock_timestampert
@ NONE
timestampert
static std::unique_ptr< const timestampert > make(clockt clock_type)
Factory method to build timestampert subclasses.
virtual std::string stamp() const override
See HELP_TIMESTAMP in util/timestamper.h for time stamp format.
#define UNREACHABLE
This should be used to mark dead code.
Definition invariant.h:525
#define WALL_FORMAT
Emit timestamps.