GlPortal Class Reference  0.1.1
Source code documentation of the free and open 3D action puzzle game.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Profiler.hpp
Go to the documentation of this file.
1 #ifndef RADIX_UTIL_PROFILER_HPP
2 #define RADIX_UTIL_PROFILER_HPP
3 
4 #include <chrono>
5 #include <map>
6 #include <string>
7 
8 namespace radix {
9 namespace util {
10 
11 class Profiler {
12 protected:
13  std::string m_name;
14  std::chrono::time_point<std::chrono::high_resolution_clock> m_begin, m_end;
15  std::map<std::string, Profiler> m_subprofilers;
16 
17 public:
18  Profiler(const std::string &name) :
19  m_name(name) {
20  }
21 
22  Profiler& operator[](const std::string &key) {
23  decltype(m_subprofilers)::iterator it = m_subprofilers.find(key);
24  if (it == m_subprofilers.end()) {
25  return m_subprofilers.emplace(std::piecewise_construct,
26  std::forward_as_tuple(key),
27  std::forward_as_tuple(key)
28  ).first->second;
29  }
30  return it->second;
31  }
32 
33  void start() {
34  m_begin = std::chrono::high_resolution_clock::now();
35  }
36 
37  void stop() {
38  m_end = std::chrono::high_resolution_clock::now();
39  }
40 
41  std::string name() const {
42  return m_name;
43  }
44 
45  decltype(m_begin) begin() const {
46  return m_begin;
47  }
48 
49  decltype(m_end) end() const {
50  return m_end;
51  }
52 
53  decltype(m_end - m_begin) delta() const {
54  return m_end - m_begin;
55  }
56 
57  std::string dump() const;
58 };
59 
60 } /* namespace util */
61 } /* namespace radix */
62 
63 #endif /* RADIX_UTIL_PROFILER_HPP */
Definition: Profiler.hpp:11
std::chrono::time_point< std::chrono::high_resolution_clock > m_end
Definition: Profiler.hpp:14
Definition: GameController.hpp:7
std::chrono::time_point< std::chrono::high_resolution_clock > m_begin
Definition: Profiler.hpp:14
void stop()
Definition: Profiler.hpp:37
std::string name() const
Definition: Profiler.hpp:41
Profiler & operator[](const std::string &key)
Definition: Profiler.hpp:22
decltype(m_begin) begin() const
Definition: Profiler.hpp:45
void start()
Definition: Profiler.hpp:33
decltype(m_end) end() const
Definition: Profiler.hpp:49
Profiler(const std::string &name)
Definition: Profiler.hpp:18
std::string m_name
Definition: Profiler.hpp:13
std::map< std::string, Profiler > m_subprofilers
Definition: Profiler.hpp:15
std::string dump() const
Definition: Profiler.cpp:13