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

Function ScopeEnd

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

Source from the content-addressed store, hash-verified

683}
684
685static ProfileResult ScopeEnd(void* ctx, const char* name, uint64_t name_hash)
686{
687 (void)ctx;
688 CHECK_INITIALIZED_RETVAL(PROFILE_RESULT_NOT_INITIALIZED);
689 DM_MUTEX_SCOPED_LOCK(g_Lock);
690
691 ThreadData* td = GetOrCreateThreadData(g_ProfileContext, GetThreadId());
692 if (td->m_OverflowDepth != 0)
693 {
694 td->m_OverflowDepth--;
695 return PROFILE_RESULT_OK;
696 }
697
698 uint64_t end = dmTime::GetMonotonicTime();
699
700 Sample* sample = td->m_CurrentSample;
701
702 uint64_t length = 0;
703 if (sample->m_CallCount > 1)
704 length = dmMath::Max(end - sample->m_TempStart, (uint64_t)0);
705 else
706 length = dmMath::Max(end - sample->m_Start, (uint64_t)0);
707
708 sample->m_Length += (uint32_t)length;
709
710 if (sample->m_Parent)
711 {
712 sample->m_Parent->m_LengthChildren += length;
713 }
714
715 td->m_CurrentSample = sample->m_Parent;
716 assert(td->m_CurrentSample != 0);
717
718 if (td->m_CurrentSample == &td->m_Root)
719 {
720 // We've closed a top scope (there may be several) on this thread and are ready to present the info
721 if (g_SampleTreeCallback)
722 {
723 // TODO: ability to show the other threads
724 // Note: the rest of the threads make their own calls to this callback
725 int32_t thread_id = GetThreadId();
726 ThreadData* td = GetOrCreateThreadData(g_ProfileContext, thread_id);
727 td->m_Root.m_Length = td->m_Root.m_LengthChildren;
728 Sample* sibling = td->m_Root.m_FirstChild;
729 while (sibling)
730 {
731 g_SampleTreeCallback(g_SampleTreeCallbackCtx, GetThreadName(thread_id), sibling);
732 sibling = sibling->m_Sibling;
733 }
734 }
735
736 ResetThreadData(td);
737 }
738
739 return PROFILE_RESULT_OK;
740}
741
742// ***************************************************************************************************************

Callers

nothing calls this directly

Calls 7

GetOrCreateThreadDataFunction · 0.85
GetThreadNameFunction · 0.85
ResetThreadDataFunction · 0.85
GetThreadIdFunction · 0.70
GetMonotonicTimeFunction · 0.50
MaxFunction · 0.50
assertFunction · 0.50

Tested by

no test coverage detected