!F (Profiling) (DEV-7030) Rewrite of the profiling system to have a unified interface...
[CRYENGINE.git] / Code / CryEngine / CrySystem / Profiling / CryBrofiler.cpp
blobb65c309a192ac25903656b2c09092da9ea74d4ed
1 // Copyright 2001-2018 Crytek GmbH / Crytek Group. All rights reserved.
3 #include "StdAfx.h"
4 #include "CryBrofiler.h"
6 #if ALLOW_BROFILER
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!");
17 s_pInstance = this;
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);
50 return true;
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);
69 #endif