WSF
TimedRegion.hpp
Go to the documentation of this file.
1// ****************************************************************************
2// CUI
3//
4// The Advanced Framework for Simulation, Integration, and Modeling (AFSIM)
5//
6// Copyright (C) 2022 Stellar Science; U.S. Government has Unlimited Rights.
7//
8// The use, dissemination or disclosure of data in this file is subject to
9// limitation or restriction. See accompanying README and LICENSE for details.
10// ****************************************************************************
11
12#ifndef PROFILINGTIMEDREGION_HPP
13#define PROFILINGTIMEDREGION_HPP
14
15#include "profiling_export.h"
16
17#include <functional>
18#include <memory>
19
20#include "ProfilingRegion.hpp"
21#include "UtLog.hpp"
22#include "UtLogStream.hpp"
23#include "UtProcessorTime.hpp"
24#include "UtWallClock.hpp"
25
26namespace profiling
27{
85class PROFILING_EXPORT TimedRegion final
86{
87public:
93 enum class Mode
94 {
95 REGION,
96 SUBREGION
97 };
98
104 TimedRegion(const char* aRegionLabel,
105 Mode aMode = Mode::REGION,
106 std::function<void(ut::log::MessageStream&)> aExtraStartingOutputFunc = nullptr,
107 ut::log::MessageStream aOutputStream = ut::log::info());
108
109 ~TimedRegion();
110
119 void StartSubregion(const std::string& aStartMessage = "");
120
129 void StopSubregion(const std::string& aEndMessage = "");
130
132 double GetWallTime();
133
135 double GetCpuTime();
136
137 TimedRegion() = delete;
138 TimedRegion(const TimedRegion&) = delete;
142
143private:
144 void LogStart(const std::string& aStartMessage = "");
145 void LogEnd(const std::string& aEndMessage = "");
146
148 std::unique_ptr<ProfilingRegion> mProfilingRegion;
150 std::string mRegionLabel;
152 Mode mMode;
154 std::function<void(ut::log::MessageStream&)> mExtraStartingOutputFunc;
156 ut::log::MessageStream mOutputStream;
157
158 UtWallClock mWallClock;
159 UtProcessorTime mProcessorTime;
160
162 double mCpuOffset = 0.0;
164 double mWallOffset = 0.0;
165};
166
167} // namespace profiling
168
169#endif // PROFILINGTIMEDREGION_HPP
Scope guard that records wall clock time elapsed and marks region beginning and end by writing to a g...
Definition TimedRegion.hpp:86
TimedRegion & operator=(TimedRegion &&)=delete
Mode
In Mode::REGION, TimedRegion must be used as a scope guard.
Definition TimedRegion.hpp:94
TimedRegion(const char *aRegionLabel, Mode aMode=Mode::REGION, std::function< void(ut::log::MessageStream &)> aExtraStartingOutputFunc=nullptr, ut::log::MessageStream aOutputStream=ut::log::info())
Definition TimedRegion.cpp:21
TimedRegion & operator=(const TimedRegion &)=delete
TimedRegion(TimedRegion &&)=delete
TimedRegion(const TimedRegion &)=delete
Definition of utility struct and function used by the profiling targets.
Definition ProfilingCommon.hpp:23
Copyrights Multiple, All Rights Reserved