timemory 3.3.0
Modular C++ Toolkit for Performance Analysis and Logging. Profiling API and Tools for C, C++, CUDA, Fortran, and Python. The C++ template API is essentially a framework to creating tools: it is designed to provide a unifying interface for recording various performance measurements alongside data logging and interfaces to other tools.
timestamp.hpp
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2020, The Regents of the University of California,
4// through Lawrence Berkeley National Laboratory (subject to receipt of any
5// required approvals from the U.S. Dept. of Energy). All rights reserved.
6//
7// Permission is hereby granted, free of charge, to any person obtaining a copy
8// of this software and associated documentation files (the "Software"), to deal
9// in the Software without restriction, including without limitation the rights
10// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11// copies of the Software, and to permit persons to whom the Software is
12// furnished to do so, subject to the following conditions:
13//
14// The above copyright notice and this permission notice shall be included in all
15// copies or substantial portions of the Software.
16//
17// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23// SOFTWARE.
24
25#pragma once
26
27#include "timemory/components/base.hpp" // for component base class
29#include "timemory/data.hpp" // for data specialization
30#include "timemory/mpl/stl.hpp" // for math specialization
31#include "timemory/tpls/cereal/types.hpp"
32
33#include <chrono>
34#include <cstdint>
35#include <ostream>
36#include <string>
37
38namespace tim
39{
40namespace component
41{
42//
43/// \struct tim::component::timestamp
44/// \brief this component stores the timestamp of when a bundle was started
45/// and is specialized such that the "timeline_storage" type-trait is true.
46/// This means that every entry in the call-graph for this output will be unique
47/// (look in the timestamp.txt output file)
48///
49struct timestamp : base<timestamp, timestamp_entry_t>
50{
53 using clock_type = std::chrono::system_clock;
54 using time_point_type = typename clock_type::time_point;
55 using duration_type = std::chrono::duration<clock_type::rep, std::nano>;
56
57 static std::string label();
58 static std::string description();
59 static value_type record();
61 static std::string as_string(const time_point_type& _tp);
62 static int64_t count();
63
64 template <typename ArchiveT>
65 static void extra_serialization(ArchiveT&);
66
67 void sample();
68 void start();
69 value_type get() const;
71
72 template <typename ArchiveT>
73 void load(ArchiveT& ar, const unsigned);
74
75 template <typename ArchiveT>
76 void save(ArchiveT& ar, const unsigned) const;
77
80 timestamp& operator/=(int64_t);
81
82 friend std::ostream& operator<<(std::ostream& _os, const timestamp& _ts)
83 {
84 _os << _ts.get_display();
85 return _os;
86 }
87};
88
89template <typename ArchiveT>
90void
91timestamp::load(ArchiveT& ar, const unsigned)
92{
93 time_t _val{};
94 ar(cereal::make_nvp("time_since_epoch", _val));
95 set_value(std::chrono::system_clock::from_time_t(_val));
96}
97
98template <typename ArchiveT>
99void
100timestamp::save(ArchiveT& ar, const unsigned) const
101{
102 auto _val = std::chrono::system_clock::to_time_t(get_value());
103 ar(cereal::make_nvp("time_since_epoch", _val));
104}
105
106template <typename ArchiveT>
107void
109{
110 ar(cereal::make_nvp("reference_timestamp", get_reference_ts()));
111}
112
113} // namespace component
114
115//--------------------------------------------------------------------------------------//
116
117namespace data
118{
119namespace base
120{
122//
123template <>
124void
125stream_entry::construct<timestamp_value_t>(const timestamp_value_t& val);
126} // namespace base
127} // namespace data
128} // namespace tim
129
130#if defined(TIMEMORY_COMPONENT_TIMESTAMP_HEADER_ONLY_MODE) && \
131 TIMEMORY_COMPONENT_TIMESTAMP_HEADER_ONLY_MODE > 0
133#endif
std::chrono::time_point< std::chrono::system_clock > timestamp_entry_t
Definition: types.hpp:51
typename component::timestamp::time_point_type timestamp_value_t
Definition: timestamp.hpp:121
Definition: kokkosp.cpp:39
tim::mpl::apply< std::string > string
Definition: macros.hpp:53
this component stores the timestamp of when a bundle was started and is specialized such that the "ti...
Definition: timestamp.hpp:50
static value_type record()
Definition: timestamp.cpp:57
friend std::ostream & operator<<(std::ostream &_os, const timestamp &_ts)
Definition: timestamp.hpp:82
std::chrono::system_clock clock_type
Definition: timestamp.hpp:53
static std::string label()
Definition: timestamp.cpp:43
static std::string as_string(const time_point_type &_tp)
Definition: timestamp.cpp:64
typename clock_type::time_point time_point_type
Definition: timestamp.hpp:54
std::chrono::duration< clock_type::rep, std::nano > duration_type
Definition: timestamp.hpp:55
void save(ArchiveT &ar, const unsigned) const
Definition: timestamp.hpp:100
value_type get() const
Definition: timestamp.cpp:100
static int64_t count()
Definition: timestamp.cpp:77
static value_type get_reference_ts()
Definition: timestamp.cpp:131
timestamp & operator/=(const timestamp &)
Definition: timestamp.cpp:121
static void extra_serialization(ArchiveT &)
Definition: timestamp.hpp:108
timestamp & operator+=(const timestamp &)
Definition: timestamp.cpp:114
std::string get_display() const
Definition: timestamp.cpp:107
static std::string description()
Definition: timestamp.cpp:50
timestamp_entry_t value_type
Definition: timestamp.hpp:51