KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
profiler_impl.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Máté Kelemen
11 //
12 
13 #pragma once
14 
15 // Project includes
16 #include "utilities/profiler.h" // <== help the language server
17 
18 // System includes
19 #include <string>
20 #include <chrono>
21 
22 
23 namespace Kratos::Internals {
24 
25 
26 template <class T>
27 Profiler<T>::Scope::Scope(Profiler::Item& rItem)
28  : Scope(rItem, Clock::now())
29 {
30 }
31 
32 
33 template <class T>
34 Profiler<T>::Scope::Scope(Profiler::Item& rItem, std::chrono::high_resolution_clock::time_point Begin)
35  : mrItem(rItem),
36  mBegin(Begin)
37 {
38  ++mrItem.mCallCount;
39  ++mrItem.mRecursionLevel;
40 }
41 
42 
43 template <class T>
45 {
46  if (!--mrItem.mRecursionLevel) {
47  const auto duration = std::chrono::duration_cast<Profiler::TimeUnit>(Clock::now() - mBegin);
48  mrItem.mCumulative += duration;
49  mrItem.mMin = std::min(mrItem.mMin, duration);
50  mrItem.mMax = std::max(mrItem.mMax, duration);
51  }
52 }
53 
54 
55 template <class T>
57 {
58  return Scope(rItem);
59 }
60 
61 
62 } // namespace Kratos::Internals
RAII wrapper for updating an Item.
Definition: profiler.h:94
Definition: profiler.h:33
static double max(double a, double b)
Definition: GeometryFunctions.h:79
static double min(double a, double b)
Definition: GeometryFunctions.h:71
Definition: factory.h:208