1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
4 #include "CryBrofiler.h"
7 #include "Cry_Brofiler.h"
8 #include <CryThreading/IThreadManager.h>
10 thread_local
Profiler::ThreadDescription
* tls_pDescription
= nullptr;
12 CBrofiler
* CBrofiler::s_pInstance
= nullptr;
14 CBrofiler::CBrofiler()
16 CRY_ASSERT_MESSAGE(s_pInstance
== nullptr, "Multiple instantiation!");
20 CBrofiler::~CBrofiler()
22 s_pInstance
= nullptr;
25 void CBrofiler::StartThread()
27 CRY_ASSERT(tls_pDescription
== nullptr);
28 tls_pDescription
= new Profiler::ThreadDescription(gEnv
->pThreadManager
->GetThreadName(CryGetCurrentThreadId()));
31 void CBrofiler::EndThread()
33 CRY_ASSERT(tls_pDescription
!= nullptr);
34 delete tls_pDescription
;
37 void CBrofiler::DescriptionCreated(SProfilingSectionDescription
* pDesc
)
39 pDesc
->customData
= (uintptr_t) Profiler::EventDescription::Create(pDesc
->szEventname
, pDesc
->szFilename
, pDesc
->line
, GenerateColorBasedOnName(pDesc
->szEventname
));
42 void CBrofiler::DescriptionDestroyed(SProfilingSectionDescription
* pDesc
)
44 Profiler::EventDescription::DestroyEventDescription((Profiler::EventDescription
*) pDesc
->customData
);
47 bool CBrofiler::StartSection(SProfilingSection
* pSection
)
49 pSection
->customData
= (uintptr_t) Profiler::Event::Start(*(Profiler::EventDescription
*) pSection
->pDescription
->customData
);
53 void CBrofiler::EndSection(SProfilingSection
* pSection
)
55 if (pSection
->customData
)
56 Profiler::Event::Stop(*(Profiler::EventData
*) pSection
->customData
);
59 bool CBrofiler::StartSectionStatic(SProfilingSection
* p
)
61 return s_pInstance
->StartSection(p
);
64 void CBrofiler::EndSectionStatic(SProfilingSection
* p
)
66 s_pInstance
->EndSection(p
);