19 #include <unordered_map>
31 template <
class TTimeUnit>
35 using TimeUnit = TTimeUnit;
37 using Duration = TimeUnit;
39 using Clock = std::chrono::high_resolution_clock;
48 Item(std::size_t CallCount,
49 Duration CumulativeDuration,
54 Item& operator+=(
const Item& rOther);
59 unsigned mRecursionLevel;
61 std::size_t mCallCount;
72 struct SourceLocationHash
74 std::size_t operator()(
const CodeLocation& r_argument)
const
78 return std::hash<std::string>()(string);
82 struct SourceLocationEquality
101 Scope(Item& rItem, std::chrono::high_resolution_clock::time_point Begin);
119 const std::chrono::high_resolution_clock::time_point mBegin;
126 SourceLocationEquality
147 void Write(std::ostream& rStream)
const;
169 std::unordered_map<std::thread::id,std::list<Item>> mItemContainerMap;
175 std::unique_ptr<Scope> mpScope;
186 template <
class TTimeUnit>
193 static std::optional<Profiler<TTimeUnit>> mProfiler;
195 static std::mutex mMutex;
202 #if defined(KRATOS_ENABLE_PROFILING)
203 #define KRATOS_DEFINE_SCOPE_PROFILER(KRATOS_TIME_UNIT, CODE_LOCATION) \
204 thread_local static auto& KRATOS_STATIC_PROFILER_REF = Kratos::Internals::ProfilerSingleton<KRATOS_TIME_UNIT>::Get(); \
205 thread_local static auto& KRATOS_SCOPE_PROFILED_ITEM = KRATOS_STATIC_PROFILER_REF.Create(CODE_LOCATION); \
206 const auto KRATOS_SCOPE_PROFILER = KRATOS_STATIC_PROFILER_REF.Profile(KRATOS_SCOPE_PROFILED_ITEM)
208 #define KRATOS_PROFILE_SCOPE_MILLI(CODE_LOCATION) KRATOS_DEFINE_SCOPE_PROFILER(std::chrono::milliseconds, CODE_LOCATION)
210 #define KRATOS_PROFILE_SCOPE_MICRO(CODE_LOCATION) KRATOS_DEFINE_SCOPE_PROFILER(std::chrono::microseconds, CODE_LOCATION)
212 #define KRATOS_PROFILE_SCOPE_NANO(CODE_LOCATION) KRATOS_DEFINE_SCOPE_PROFILER(std::chrono::nanoseconds, CODE_LOCATION)
214 #define KRATOS_PROFILE_SCOPE(CODE_LOCATION) KRATOS_PROFILE_SCOPE_MICRO(CODE_LOCATION)
217 #define KRATOS_PROFILE_SCOPE_MILLI(CODE_LOCATION)
219 #define KRATOS_PROFILE_SCOPE_MICRO(CODE_LOCATION)
221 #define KRATOS_PROFILE_SCOPE_NANO(CODE_LOCATION)
223 #define KRATOS_PROFILE_SCOPE(CODE_LOCATION)
Definition: code_location.h:31
int GetLineNumber() const
Definition: code_location.cpp:37
const std::string & GetFileName() const
Definition: code_location.cpp:29
RAII wrapper for updating an Item.
Definition: profiler.h:94
~Scope()
Definition: profiler_impl.h:44
Definition: profiler.h:33
std::unordered_map< CodeLocation, Item, SourceLocationHash, SourceLocationEquality > ItemMap
Definition: profiler.h:127
Profiler()
Definition: profiler.cpp:72
Scope Profile(Item &rItem)
Definition: profiler_impl.h:56
Profiler(Profiler &&rOther)=default
Item & Create(CodeLocation &&rItem)
Definition: profiler.cpp:107
Profiler & operator=(Profiler &&rOther)=default
void Write(std::ostream &rStream) const
Definition: profiler.cpp:168
ItemMap Aggregate() const
Collect results from all threads into a single map.
Definition: profiler.cpp:144
~Profiler()
Definition: profiler.cpp:244
Definition: profiler.h:188
static Profiler< TTimeUnit > & Get() noexcept
Definition: profiler.cpp:252
string path
Definition: DEM_run_all_benchmarks_analysis.py:10
Definition: factory.h:208
std::ostream & operator<<(std::ostream &rOStream, AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheMatrix)
Definition: amatrix_interface.h:329