29#ifndef RT_GRAPH_HPP_GUARD
30#define RT_GRAPH_HPP_GUARD
42using ClockType = std::chrono::high_resolution_clock;
63enum class TimeStampType { Start, Stop, Empty };
66 TimeStamp() : type(TimeStampType::Empty) {}
69 TimeStamp(
const char* identifier,
const TimeStampType& stampType)
70 : time(ClockType::now()), identifierPtr(identifier), type(stampType) {}
72 ClockType::time_point time;
73 const char* identifierPtr;
78 std::string identifier;
79 std::vector<double> timings;
80 std::vector<double> startTimes;
81 std::list<TimingNode> subNodes;
82 double totalTime = 0.0;
84 inline void add_time(
double startTime,
double t) {
85 startTimes.push_back(startTime);
95 TimingResult(std::list<internal::TimingNode> rootNodes, std::string warnings)
96 : rootNodes_(std::move(rootNodes)), warnings_(std::move(warnings)) {}
99 auto json()
const -> std::string;
102 auto get_timings(
const std::string& identifier)
const -> std::vector<double>;
105 auto print(std::vector<Stat> statistic = {Stat::Count, Stat::Total, Stat::Percentage,
106 Stat::ParentPercentage, Stat::Median, Stat::Min,
107 Stat::Max})
const -> std::string;
117 std::list<internal::TimingNode> rootNodes_;
118 std::string warnings_;
127 Timer() { timeStamps_.reserve(2 * 1000 * 1000); }
130 explicit Timer(std::size_t reserveCount) { timeStamps_.reserve(2 * reserveCount); }
133 template <std::
size_t N>
134 inline auto start(
const char (&identifierPtr)[N]) ->
void {
135 atomic_signal_fence(std::memory_order_seq_cst);
136 timeStamps_.emplace_back(identifierPtr, internal::TimeStampType::Start);
137 atomic_signal_fence(std::memory_order_seq_cst);
141 inline auto start(std::string identifier) ->
void {
142 atomic_signal_fence(std::memory_order_seq_cst);
143 identifierStrings_.emplace_back(std::move(identifier));
144 timeStamps_.emplace_back(identifierStrings_.back().c_str(), internal::TimeStampType::Start);
145 atomic_signal_fence(std::memory_order_seq_cst);
149 template <std::
size_t N>
150 inline auto stop(
const char (&identifierPtr)[N]) ->
void {
151 atomic_signal_fence(std::memory_order_seq_cst);
152 timeStamps_.emplace_back(identifierPtr, internal::TimeStampType::Stop);
153 atomic_signal_fence(std::memory_order_seq_cst);
157 inline auto stop(std::string identifier) ->
void {
158 atomic_signal_fence(std::memory_order_seq_cst);
159 identifierStrings_.emplace_back(std::move(identifier));
160 timeStamps_.emplace_back(identifierStrings_.back().c_str(), internal::TimeStampType::Stop);
161 atomic_signal_fence(std::memory_order_seq_cst);
165 inline auto clear(std::size_t reserveCount) ->
void {
167 identifierStrings_.clear();
168 this->reserve(reserveCount);
172 inline auto reserve(std::size_t reserveCount) ->
void { timeStamps_.reserve(reserveCount); }
178 inline auto stop_with_ptr(
const char* identifierPtr) ->
void {
179 atomic_signal_fence(std::memory_order_seq_cst);
180 timeStamps_.emplace_back(identifierPtr, internal::TimeStampType::Stop);
181 atomic_signal_fence(std::memory_order_seq_cst);
186 std::vector<internal::TimeStamp> timeStamps_;
187 std::deque<std::string>
196 template <std::
size_t N>
198 : identifierPtr_(identifierPtr), timer_(timer) {
199 timer_.start(identifierPtr);
203 : identifierPtr_(
nullptr), identifier_(std::move(identifier)), timer_(timer) {
204 timer_.start(identifier_);
213 if (identifierPtr_) {
214 timer_.stop_with_ptr(identifierPtr_);
216 timer_.stop(std::move(identifier_));
221 const char* identifierPtr_;
222 std::string identifier_;
namespace for Niels Lohmann