//----------------------------------------------------------------------------- // Purpose: Sorts sections by time usage //----------------------------------------------------------------------------- void CMeasureSection::SortSections( void ) { // Not enough to be sortable if ( s_nCount <= 1 ) return; CMeasureSection *sortarray[ 128 ]; CMeasureSection *ms; memset(sortarray,sizeof(CMeasureSection*)*128,0); ms = GetList(); int i; int c = 0; while ( ms ) { sortarray[ c++ ] = ms; ms = ms->GetNext(); } // Sort the array alphabetically qsort( sortarray, c , sizeof( CMeasureSection * ), SectionCompare ); // Fix next pointers for ( i = 0; i < c-1; i++ ) { sortarray[ i ]->m_pNext = sortarray[ i + 1 ]; } sortarray[i]->m_pNext = NULL; // Point head of list at it s_pSections = sortarray[ 0 ]; }
//----------------------------------------------------------------------------- // Purpose: Re-sort all data and determine whether sort keys should be reset too ( after // re-doing sort if needed ). //----------------------------------------------------------------------------- void ResetTimeMeasurements( void ) { #if defined( _DEBUG ) || defined( FORCE_MEASURE ) bool sort_reset = false; // Time to redo sort? if ( measure_resort.GetFloat() > 0.0 && GetRealTime() >= CMeasureSection::m_dNextResort ) { // Redo it CMeasureSection::SortSections(); // Set next time CMeasureSection::m_dNextResort = GetRealTime() + measure_resort.GetFloat(); // Flag to reset sort accumulator, too sort_reset = true; } // Iterate through the sections now CMeasureSection *p = CMeasureSection::GetList(); while ( p ) { // Reset regular accum. p->Reset(); // Reset sort accum less often if ( sort_reset ) { p->SortReset(); } p = p->GetNext(); } #endif }
void DrawMeasuredSections(void) { int row = 1; float rowheight = 0.025; CMeasureSection *p = CMeasureSection::GetList(); while ( p ) { char str[256]; Q_snprintf(str,sizeof(str),"%s",p->GetName()); NDebugOverlay::ScreenText( 0.01,0.51+(row*rowheight),str, 255,255,255,255, 0.0 ); Q_snprintf(str,sizeof(str),"%5.2f\n",p->GetTime().GetMillisecondsF()); //Q_snprintf(str,sizeof(str),"%3.3f\n",p->GetTime().GetSeconds() * 100.0 / engine->Time()); NDebugOverlay::ScreenText( 0.28,0.51+(row*rowheight),str, 255,255,255,255, 0.0 ); Q_snprintf(str,sizeof(str),"%5.2f\n",p->GetMaxTime().GetMillisecondsF()); //Q_snprintf(str,sizeof(str),"%3.3f\n",p->GetTime().GetSeconds() * 100.0 / engine->Time()); NDebugOverlay::ScreenText( 0.34,0.51+(row*rowheight),str, 255,255,255,255, 0.0 ); row++; p = p->GetNext(); } bool sort_reset = false; // Time to redo sort? if ( measure_resort.GetFloat() > 0.0 && engine->Time() >= CMeasureSection::m_dNextResort ) { // Redo it CMeasureSection::SortSections(); // Set next time CMeasureSection::m_dNextResort = engine->Time() + measure_resort.GetFloat(); // Flag to reset sort accumulator, too sort_reset = true; } // Iterate through the sections now p = CMeasureSection::GetList(); while ( p ) { // Update max p->UpdateMax(); // Reset regular accum. p->Reset(); // Reset sort accum less often if ( sort_reset ) { p->SortReset(); } p = p->GetNext(); } }