Shkyera Engine
Easy to use, game engine for Python
Loading...
Searching...
No Matches
Profiler.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <map>
5#include <mutex>
6#include <string>
7#include <thread>
8
9namespace shkyera {
10
17
19 public:
20 ProfileGuard(std::string&& name);
22
23 private:
24 std::string mProfileName;
25 std::chrono::high_resolution_clock::time_point mStartTime;
26};
27
28class Profiler {
29 public:
30 using BlocksPerThread = std::map<std::thread::id, std::map<std::string, ProfileBlock>>;
31
32 static Profiler& getInstance();
33
34 void clear();
35 void addBlock(std::string&& name, std::chrono::nanoseconds time);
37
38 private:
39 Profiler() = default;
40
41 std::mutex mMutex;
43};
44
45#define SHKYERA_PROFILE(name) ProfileGuard __SHKYERA_UNIQUE_NAME(__LINE__)(name)
46#define SHKYERA_READ_PROFILE Profiler::getInstance().getProfiles()
47#define SHKYERA_CLEAR_PROFILE Profiler::getInstance().clear()
48
49#define __SHKYERA_UNIQUE_NAME(LINE) __SHKYERA_CONCAT(profileGuard_, LINE)
50#define __SHKYERA_CONCAT(X, Y) __SHKYERA_CONCAT_IMPL(X, Y)
51#define __SHKYERA_CONCAT_IMPL(X, Y) X##Y
52
53} // namespace shkyera
Definition Profiler.hpp:18
std::chrono::high_resolution_clock::time_point mStartTime
Definition Profiler.hpp:25
~ProfileGuard()
Definition Profiler.cpp:16
std::string mProfileName
Definition Profiler.hpp:24
Definition Profiler.hpp:28
void addBlock(std::string &&name, std::chrono::nanoseconds time)
Definition Profiler.cpp:33
static Profiler & getInstance()
Definition Profiler.cpp:23
BlocksPerThread getProfiles()
Definition Profiler.cpp:41
Profiler()=default
void clear()
Definition Profiler.cpp:28
std::mutex mMutex
Definition Profiler.hpp:41
std::map< std::thread::id, std::map< std::string, ProfileBlock > > BlocksPerThread
Definition Profiler.hpp:30
BlocksPerThread mProfileBlocks
Definition Profiler.hpp:42
Definition Asset.hpp:6
Definition Clock.hpp:9
Definition Profiler.hpp:11
ProfileBlock & operator+=(const ProfileBlock &other)
Definition Profiler.cpp:5
size_t numberOfCalls
Definition Profiler.hpp:13
double totalLengthInNanoSeconds
Definition Profiler.hpp:12