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

Function AllocateSample

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

Source from the content-addressed store, hash-verified

365///////////////////////////////////////////////////////////////////////////////////////////////
366
367static Sample* AllocateSample(ThreadData* td, uint32_t name_hash)
368{
369 Sample* parent = td->m_CurrentSample;
370
371 // Aggregate samples:
372 // If there already is a child with this name, use that
373 Sample* sample = parent->m_FirstChild;
374 while (sample)
375 {
376 if (sample->m_NameHash == name_hash)
377 {
378 break;
379 }
380 sample = sample->m_Sibling;
381 }
382
383 if (!sample)
384 {
385 sample = AllocateNewSample(td);
386 if (!sample)
387 {
388 return 0;
389 }
390 memset(sample, 0, sizeof(Sample));
391
392 sample->m_NameHash = name_hash;
393
394 // link the sample into the tree
395 Sample* parent = td->m_CurrentSample;
396 sample->m_Parent = parent;
397 if (parent->m_FirstChild == 0)
398 {
399 parent->m_FirstChild = sample;
400 parent->m_LastChild = sample;
401 }
402 else
403 {
404 parent->m_LastChild->m_Sibling = sample;
405 parent->m_LastChild = sample;
406 }
407 }
408
409 sample->m_CallCount++;
410 td->m_CurrentSample = sample;
411 return sample;
412}
413
414namespace dmProfiler
415{

Callers 1

ScopeBeginFunction · 0.70

Calls 1

AllocateNewSampleFunction · 0.85

Tested by

no test coverage detected