A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
system-wall-clock-timestamp.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Lawrence Livermore National Laboratory
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
7 */
8
10
11/**
12 * \file
13 * \ingroup system
14 * ns3::SystemWallClockTimestamp implementation.
15 */
16
17namespace ns3
18{
19
21 : m_last(0),
22 m_diff(0)
23{
24 Stamp();
25}
26
27void
29{
30 std::time_t seconds = std::time(nullptr);
31 m_diff = seconds - m_last;
32 m_last = seconds;
33}
34
35std::string
37{
38 std::string now = std::ctime(&m_last);
39 now.resize(now.length() - 1); // trim trailing newline
40 return now;
41}
42
43std::time_t
45{
46 return m_last;
47}
48
49std::time_t
54
55} // namespace ns3
std::time_t GetInterval() const
Get the last recorded interval.
std::time_t GetLast() const
Get the last recorded raw value.
std::string ToString() const
Get the last time stamp as a string.
std::time_t m_diff
Difference between the two previous time stamps.
void Stamp()
Record the current wall-clock time and delta since the last stamp().
std::time_t m_last
The last time stamp.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::SystemWallClockTimestamp declaration.