MCPcopy Create free account
hub / github.com/defold/defold / ScopeBegin

Function ScopeBegin

engine/profiler/src/basic/profiler_basic.cpp:651–683  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

649}
650
651static ProfileResult ScopeBegin(void* ctx, const char* name, uint64_t name_hash)
652{
653 (void)ctx;
654 CHECK_INITIALIZED_RETVAL(PROFILE_RESULT_NOT_INITIALIZED);
655 DM_MUTEX_SCOPED_LOCK(g_Lock);
656
657 ThreadData* td = GetOrCreateThreadData(g_ProfileContext, GetThreadId());
658 if (td->m_OverflowDepth != 0)
659 {
660 td->m_OverflowDepth++;
661 return PROFILE_RESULT_OUT_OF_SAMPLES;
662 }
663
664 uint64_t tstart = dmTime::GetMonotonicTime();
665 uint32_t sample_name_hash = GetOrCacheNameHash(name, (uint32_t*)&name_hash);
666 Sample* sample = AllocateSample(td, sample_name_hash); // Adds it to the thread data
667 if (!sample)
668 {
669 // Once the sample pool is exhausted we skip nested scopes until the stack is balanced
670 // again, instead of linking a shared sentinel node into the sample tree.
671 td->m_OverflowDepth = 1;
672 return PROFILE_RESULT_OUT_OF_SAMPLES;
673 }
674
675 InternalizeName(name, &sample_name_hash);
676
677 if (sample->m_CallCount > 1) // we want to preserve the real start of this sample
678 sample->m_TempStart = tstart;
679 else
680 sample->m_Start = tstart;
681
682 return PROFILE_RESULT_OK;
683}
684
685static ProfileResult ScopeEnd(void* ctx, const char* name, uint64_t name_hash)
686{

Callers

nothing calls this directly

Calls 6

GetOrCreateThreadDataFunction · 0.85
GetOrCacheNameHashFunction · 0.85
InternalizeNameFunction · 0.85
GetThreadIdFunction · 0.70
AllocateSampleFunction · 0.70
GetMonotonicTimeFunction · 0.50

Tested by

no test coverage detected