// Highlight all script nodes bool CProfileNodeTable::IsHighlightRow(size_t row) { size_t nrchildren = node->GetChildren()->size(); size_t nrscriptchildren = node->GetScriptChildren()->size(); return (row >= nrchildren && row < (nrchildren + nrscriptchildren)); }
CProfileNode* CDebugProf::RequestNode( String name, CProfileNode* parent ) { if( m_NodeCount < NODE_POOL_SIZE ) { CProfileNode* n = &m_NodePool[m_NodeCount++]; n->Initialize( name, parent ); return n; } return NULL; }
CProfileNode * CProfileNode::GetChild( UInt32 index ) { UInt32 i=0; CProfileNode * child = m_Child; while( child ) { if( i == index ) return child; i++; child = child->GetSibling(); } return NULL; }
Void CProfileNode::Reset() { m_TotalCalls = 0; m_TotalSamplingTime = 0; m_RecursionCounter = 0; m_SamplingStart = 0; CProfileNode* tmp = m_Child; while( tmp ) { tmp->Reset(); tmp = tmp->GetSibling(); } m_Child = NULL; }
IProfileNode * CProfileNode::GetSubNode( const char * name ) { CProfileNode * child = Child; while ( child ) { #ifdef NO_STR_CPY if(child->Name == name) { #else if ( strcmp(child->Name , name ) == 0) { #endif return child; } child = child->Sibling; } CProfileNode * node = new CProfileNode( name, this ); CProfileNode *pTemp = Child; CProfileNode *pPre = 0; while(pTemp) { pPre = pTemp; pTemp = (CProfileNode*)pTemp->GetSibling(); } if(pPre) { pPre->Sibling = node; } else { Child = node; } return node; } void CProfileNode::Reset( void ) { TotalCalls = 0; TotalTime = 0.0f; MinTime = (float)_I64_MAX; MaxTime = 0; if ( Child ) { Child->Reset(); } if ( Sibling ) { Sibling->Reset(); } }
// Return a pointer to the child table if the child node is expandable AbstractProfileTable* CProfileNodeTable::GetChild(size_t row) { CProfileNode* child; size_t nrchildren = node->GetChildren()->size(); size_t nrscriptchildren = node->GetScriptChildren()->size(); if (row < nrchildren) child = (*node->GetChildren())[row]; else if (row < nrchildren + nrscriptchildren) child = (*node->GetScriptChildren())[row - nrchildren]; else return 0; if (child->CanExpand()) return child->display_table; return 0; }
Void CDebugProfView::Format( ) { DebugProfile( "CDebugProfView::Format" ); String parentName; #ifndef SETUP_USE_PROF m_Buffer[0] = 0; return ; #endif Char* buffer = m_Buffer.GetBuffer(); Int32 s = m_Buffer.GetItemCount(); Int32 off; UInt32 frameCount = CoreManager.GetDebugProf().GetSampledFrameCount(); parentName = m_CurrentNode->GetName(); off = StringSetFormattedText( buffer, s,"| Profiling Data | Depth Level: %d \n" \ "| Parent: %s \n" \ "-----------------------------------------------------\n", m_NavigationHistory.GetItemCount(), parentName ); buffer += off; Float32 selfTotalTime = 0.0f; Float32 parentTotalTime = 0.0f; if( frameCount >= PROFVIEW_FRAMEDELAY ) { CProfileNode* childNode = NULL; parentTotalTime = m_CurrentNode->GetTotalSamplingTime() / (Float32) frameCount; m_EntryCount = 0; Float32 time; Int32 percent; childNode = m_CurrentNode->GetChild(); while( childNode ) { time = childNode->GetTotalSamplingTime(); time = time / (Float32) frameCount; selfTotalTime += time; childNode = childNode->GetSibling(); } childNode = m_CurrentNode->GetChild(); while( childNode ) { time = childNode->GetTotalSamplingTime()/ (Float32) frameCount; if( parentTotalTime > 0.0f ) percent = ( Int32 ) ( time / parentTotalTime * 100.0f ); else percent = 0; if( m_EntryCount != m_SelectionMark ) off = StringSetFormattedText( buffer, s, "| %s : %.5f ms %d %%\n", childNode->GetName(), time * 1000.0f, percent ); else off = StringSetFormattedText( buffer, s, "|>> %s : %.5f ms %d %%\n", childNode->GetName(), time * 1000.0f, percent ); buffer += off; m_EntryCount++; childNode = childNode->GetSibling(); } } else { off = StringSetFormattedText( buffer, s, "Sampling...\n"); buffer += off; } Float32 totalTime = parentTotalTime; Float32 profiledTime = selfTotalTime; Float32 unProfiledTime = parentTotalTime - selfTotalTime; if( unProfiledTime < 0 ) unProfiledTime = 0; off = StringSetFormattedText( buffer, s, "-----------------------------------------------------\n"); buffer += off; off = StringSetFormattedText( buffer, s, "| Total time: %.5f ms \n", totalTime * 1000.0f ); buffer += off; off = StringSetFormattedText( buffer, s, "| Profiled time: %.5f ms \n", profiledTime * 1000.0f ); buffer += off; off = StringSetFormattedText( buffer, s, "| UnProfiled time: %.5f ms \n", unProfiledTime * 1000.0f ); buffer += off; }
// Retrieve cell text CStr CProfileNodeTable::GetCellText(size_t row, size_t col) { CProfileNode* child; size_t nrchildren = node->GetChildren()->size(); size_t nrscriptchildren = node->GetScriptChildren()->size(); char buf[256] = "?"; if (row < nrchildren) child = (*node->GetChildren())[row]; else if (row < nrchildren + nrscriptchildren) child = (*node->GetScriptChildren())[row - nrchildren]; else if (row > nrchildren + nrscriptchildren) return "!bad row!"; else { // "unlogged" row if (col == 0) return "unlogged"; else if (col == 1) return ""; else if (col == 4) return ""; double unlogged_time_frame = node->GetFrameTime(); double unlogged_time_turn = node->GetTurnTime(); double unlogged_mallocs_frame = node->GetFrameMallocs(); double unlogged_mallocs_turn = node->GetTurnMallocs(); CProfileNode::const_profile_iterator it; for (it = node->GetChildren()->begin(); it != node->GetChildren()->end(); ++it) { unlogged_time_frame -= (*it)->GetFrameTime(); unlogged_time_turn -= (*it)->GetTurnTime(); unlogged_mallocs_frame -= (*it)->GetFrameMallocs(); unlogged_mallocs_turn -= (*it)->GetTurnMallocs(); } for (it = node->GetScriptChildren()->begin(); it != node->GetScriptChildren()->end(); ++it) { unlogged_time_frame -= (*it)->GetFrameTime(); unlogged_time_turn -= (*it)->GetTurnTime(); unlogged_mallocs_frame -= (*it)->GetFrameMallocs(); unlogged_mallocs_turn -= (*it)->GetTurnMallocs(); } // The root node can't easily count per-turn values (since Turn isn't called until // halfway though a frame), so just reset them the zero to prevent weird displays if (!node->GetParent()) { unlogged_time_turn = 0.0; unlogged_mallocs_turn = 0.0; } if (col == 2) sprintf_s(buf, ARRAY_SIZE(buf), "%.3f", unlogged_time_frame * 1000.0f); else if (col == 3) sprintf_s(buf, ARRAY_SIZE(buf), "%.1f", unlogged_mallocs_frame); else if (col == 5) sprintf_s(buf, ARRAY_SIZE(buf), "%.3f", unlogged_time_turn * 1000.f); else if (col == 6) sprintf_s(buf, ARRAY_SIZE(buf), "%.1f", unlogged_mallocs_turn); return CStr(buf); } switch(col) { default: case 0: return child->GetName(); case 1: sprintf_s(buf, ARRAY_SIZE(buf), "%.1f", child->GetFrameCalls()); break; case 2: sprintf_s(buf, ARRAY_SIZE(buf), "%.3f", child->GetFrameTime() * 1000.0f); break; case 3: sprintf_s(buf, ARRAY_SIZE(buf), "%.1f", child->GetFrameMallocs()); break; case 4: sprintf_s(buf, ARRAY_SIZE(buf), "%.1f", child->GetTurnCalls()); break; case 5: sprintf_s(buf, ARRAY_SIZE(buf), "%.3f", child->GetTurnTime() * 1000.0f); break; case 6: sprintf_s(buf, ARRAY_SIZE(buf), "%.1f", child->GetTurnMallocs()); break; } return CStr(buf); }
// Total number of children size_t CProfileNodeTable::GetNumberRows() { return node->GetChildren()->size() + node->GetScriptChildren()->size() + 1; }
// Title (= explanatory text plus time totals) CStr CProfileNodeTable::GetTitle() { char buf[512]; sprintf_s(buf, ARRAY_SIZE(buf), "Profiling Information for: %s (Time in node: %.3f msec/frame)", node->GetName(), node->GetFrameTime() * 1000.0f ); return buf; }
// Short name (= name of profile node) CStr CProfileNodeTable::GetName() { return node->GetName(); }