Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Profiler.cpp
Go to the documentation of this file.
1
2
3#include "Headers/Profiler.h"
5
6namespace Divide::Profiler
7{
8 namespace
9 {
11 }
12
14 {
15 if ( g_appPtr != nullptr ) [[likely]]
16 {
18 }
19
20 return true;
21 }
22
23 static constexpr bool g_TrackOptickStateChange = false;
24 static bool OnOptickStateChanged( const Optick::State::Type state )
25 {
26 switch(state)
27 {
28 case Optick::State::START_CAPTURE: return OnProfilerStateChanged( Profiler::State::STARTED );
29 case Optick::State::STOP_CAPTURE:
30 case Optick::State::CANCEL_CAPTURE: return OnProfilerStateChanged( Profiler::State::STOPPED );
31 case Optick::State::DUMP_CAPTURE: break;
32 }
33
35 }
36
38 {
39 g_appPtr = app;
40 }
41
43 {
44 if constexpr( detail::enabled )
45 {
46 OPTICK_SET_MEMORY_ALLOCATOR([](size_t size) -> void*
47 {
48 return mi_new(size);
49 },
50 []( void* p )
51 {
52 mi_free(p);
53 },
54 []()
55 {
56 // Thread allocator
57 NOP();
58 })
59 if constexpr (g_TrackOptickStateChange)
60 {
61 OPTICK_SET_STATE_CHANGED_CALLBACK( OnOptickStateChanged )
62 }
63 }
64 }
65
66 void Shutdown()
67 {
68 g_appPtr = nullptr;
69
70 if constexpr (detail::enabled)
71 {
72 OPTICK_SHUTDOWN()
73 }
74 }
75
76 void OnThreadStart( const std::string_view threadName )
77 {
78 if constexpr( detail::enabled )
79 {
80 OPTICK_START_THREAD(threadName.data())
81 }
82 }
84 {
85 if constexpr( detail::enabled )
86 {
87 OPTICK_STOP_THREAD()
88 }
89 }
90}; //namespace Divide::Profiler
#define NOP()
Class that provides an interface between our framework and the OS (start/stop, display support,...
Definition: Application.h:97
static bool onProfilerStateChanged(Application *app, const Profiler::State state)
Definition: Application.h:213
constexpr bool enabled
Definition: Profiler.h:48
bool OnProfilerStateChanged(const Profiler::State state)
Definition: Profiler.cpp:13
void OnThreadStart(std::string_view threadName)
Definition: Profiler.cpp:76
void RegisterApp(Application *app)
Definition: Profiler.cpp:37
void OnThreadStop()
Definition: Profiler.cpp:83
void Initialise()
Definition: Profiler.cpp:42
static constexpr bool g_TrackOptickStateChange
Definition: Profiler.cpp:23
static bool OnOptickStateChanged(const Optick::State::Type state)
Definition: Profiler.cpp:24