From 38d0583b4bc2ae8d0faf0a3909cfe09a6f19f033 Mon Sep 17 00:00:00 2001
From: Rye Mutt <rye@alchemyviewer.org>
Date: Tue, 17 Jan 2023 15:19:35 -0500
Subject: [PATCH] Profiler cleanup

---
 indra/newview/llappviewer.cpp   | 94 +++++++++++++++------------------
 indra/newview/llviewermedia.cpp |  2 +-
 indra/newview/pipeline.cpp      | 21 +++-----
 indra/newview/rlveffects.cpp    |  4 +-
 4 files changed, 52 insertions(+), 69 deletions(-)

diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 0ab23cea73d..410a0452e86 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -1352,39 +1352,34 @@ bool LLAppViewer::doFrame()
 	LLSD newFrame;
 
 	{
-        LL_PROFILE_ZONE_NAMED_CATEGORY_APP("df LLTrace");
-        if (LLFloaterReg::instanceVisible("block_timers"))
-        {
-	LLTrace::BlockTimer::processTimes();
-        }
-        
-	LLTrace::get_frame_recording().nextPeriod();
-	LLTrace::BlockTimer::logStats();
-	}
+		LL_PROFILE_ZONE_NAMED_CATEGORY_APP("df LLTrace");
+		if (LLFloaterReg::instanceVisible("block_timers"))
+		{
+			LLTrace::BlockTimer::processTimes();
+		}
+
+		LLTrace::get_frame_recording().nextPeriod();
+		LLTrace::BlockTimer::logStats();
 
-	LLTrace::get_thread_recorder()->pullFromChildren();
+		LLTrace::get_thread_recorder()->pullFromChildren();
+	}
 
 	//clear call stack records
 	LL_CLEAR_CALLSTACKS();
 
 	{
-		LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df processMiscNativeEvents" )
-		pingMainloopTimeout("Main:MiscNativeWindowEvents");
-
 		if (gViewerWindow)
 		{
-			LL_RECORD_BLOCK_TIME(FTM_MESSAGES);
+			LL_PROFILE_ZONE_NAMED_CATEGORY_APP("df processMiscNativeEvents")
+			pingMainloopTimeout("Main:MiscNativeWindowEvents");
 			gViewerWindow->getWindow()->processMiscNativeEvents();
 		}
 
-		{
-			LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df gatherInput" )
-		pingMainloopTimeout("Main:GatherInput");
-		}
 
 		if (gViewerWindow)
 		{
-			LL_RECORD_BLOCK_TIME(FTM_MESSAGES);
+			LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df gatherInput" )
+			pingMainloopTimeout("Main:GatherInput");
 			if (!restoreErrorTrap())
 			{
 				LL_WARNS() << " Someone took over my signal/exception handler (post messagehandling)!" << LL_ENDL;
@@ -1406,21 +1401,20 @@ bool LLAppViewer::doFrame()
 
 		{
 			LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df mainloop" )
-		// canonical per-frame event
-		mainloop.post(newFrame);
+			// canonical per-frame event
+			mainloop.post(newFrame);
 		}
 
 		{
 			LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df suspend" )
-		// give listeners a chance to run
-		llcoro::suspend();
-		// if one of our coroutines threw an uncaught exception, rethrow it now
-		LLCoros::instance().rethrow();
+			// give listeners a chance to run
+			llcoro::suspend();
+			// if one of our coroutines threw an uncaught exception, rethrow it now
+			LLCoros::instance().rethrow();
 		}
 
 		if (!LLApp::isExiting())
 		{
-			LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df JoystickKeyboard" )
 			pingMainloopTimeout("Main:JoystickKeyboard");
 
 			// Scan keyboard for movement keys.  Command keys and typing
@@ -1434,6 +1428,7 @@ bool LLAppViewer::doFrame()
 				&& (gHeadlessClient || !gViewerWindow->getShowProgress())
 				&& !gFocusMgr.focusLocked())
 			{
+				LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df JoystickKeyboard" )
 				joystick->scanJoystick();
 				gKeyboard->scanKeyboard();
                 gViewerInput.scanMouse();
@@ -1443,24 +1438,23 @@ bool LLAppViewer::doFrame()
 
 			// Update state based on messages, user input, object idle.
 			{
-				{
-					LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df pauseMainloopTimeout" )
-					pauseMainloopTimeout(); // *TODO: Remove. Messages shouldn't be stalling for 20+ seconds!
-				}
+				LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df idle pauseMainloopTimeout" )
+				pauseMainloopTimeout(); // *TODO: Remove. Messages shouldn't be stalling for 20+ seconds!
+			}
 
-				{
-					LL_PROFILE_ZONE_NAMED_CATEGORY_APP("df idle"); //LL_RECORD_BLOCK_TIME(FTM_IDLE);
-					idle();
-				}
+			{
+				LL_PROFILE_ZONE_NAMED_CATEGORY_APP("df idle"); //LL_RECORD_BLOCK_TIME(FTM_IDLE);
+				idle();
+			}
 
-				{
-					LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df resumeMainloopTimeout" )
-					resumeMainloopTimeout();
-				}
+			{
+				LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df idle resumeMainloopTimeout" )
+				resumeMainloopTimeout();
 			}
 
 			if (gDoDisconnect && (LLStartUp::getStartupState() == STATE_STARTED))
 			{
+				LL_PROFILE_ZONE_NAMED_CATEGORY_APP("Shutdown:SaveSnapshot");
 				pauseMainloopTimeout();
 				saveFinalSnapshot();
 
@@ -1484,20 +1478,20 @@ bool LLAppViewer::doFrame()
 				display();
 
 				{
-					LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df Snapshot" )
-				pingMainloopTimeout("Main:Snapshot");
-				LLFloaterSnapshot::update(); // take snapshots
+					LL_PROFILE_ZONE_NAMED_CATEGORY_APP("df Snapshot")
+					pingMainloopTimeout("Main:Snapshot");
+					LLFloaterSnapshot::update(); // take snapshots
                 LLFloaterSimpleOutfitSnapshot::update();
-				gGLActive = FALSE;
+					gGLActive = FALSE;
+				}
 			}
 		}
-		}
 
 		{
-			LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df pauseMainloopTimeout" )
-		pingMainloopTimeout("Main:Sleep");
+			LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df pauseMainloopTimeout2" )
+			pingMainloopTimeout("Main:Sleep");
 
-		pauseMainloopTimeout();
+			pauseMainloopTimeout();
 		}
 
 		// Sleep and run background threads
@@ -1544,7 +1538,7 @@ bool LLAppViewer::doFrame()
 
 			if (mRandomizeFramerate)
 			{
-				ms_sleep(ll_rand() % 200);
+				ms_sleep(rand() % 200);
 			}
 
 			if (mPeriodicSlowFrame
@@ -1580,7 +1574,7 @@ bool LLAppViewer::doFrame()
 
 			{
 				LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df gMeshRepo" )
-			gMeshRepo.update() ;
+				gMeshRepo.update() ;
 			}
 
 			if(!total_work_pending) //pause texture fetching threads if nothing to process.
@@ -1609,8 +1603,8 @@ bool LLAppViewer::doFrame()
 			}
 
 			{
-				LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df resumeMainloopTimeout" )
-			resumeMainloopTimeout();
+				LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df bg resumeMainloopTimeout" )
+				resumeMainloopTimeout();
 			}
 			pingMainloopTimeout("Main:End");
 		}
diff --git a/indra/newview/llviewermedia.cpp b/indra/newview/llviewermedia.cpp
index acdf87679b8..716fd15a30d 100644
--- a/indra/newview/llviewermedia.cpp
+++ b/indra/newview/llviewermedia.cpp
@@ -2079,7 +2079,7 @@ void LLViewerMediaImpl::setMute(bool mute)
 //////////////////////////////////////////////////////////////////////////////////////////
 void LLViewerMediaImpl::updateVolume()
 {
-    LL_RECORD_BLOCK_TIME(FTM_MEDIA_UPDATE_VOLUME);
+	LL_PROFILE_ZONE_NAMED_CATEGORY_MEDIA("media update volume");
 	if(mMediaSource)
 	{
 		// always scale the volume by the global media volume
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index 3c9e325f70e..65690846b2a 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -273,7 +273,6 @@ LLTrace::BlockTimerStatHandle FTM_DEFERRED_POOLRENDER("RenderPool (Deferred)");
 LLTrace::BlockTimerStatHandle FTM_DEFERRED_POOLS("Pools (Deferred)");
 LLTrace::BlockTimerStatHandle FTM_POST_DEFERRED_POOLRENDER("RenderPool (Post)");
 LLTrace::BlockTimerStatHandle FTM_POST_DEFERRED_POOLS("Pools (Post)");
-LLTrace::BlockTimerStatHandle FTM_RENDER_DEFERRED_BLOOM("HDRBloom");
 LLTrace::BlockTimerStatHandle FTM_STATESORT("Sort Draw State");
 LLTrace::BlockTimerStatHandle FTM_PIPELINE("Pipeline");
 LLTrace::BlockTimerStatHandle FTM_CLIENT_COPY("Client Copy");
@@ -3090,7 +3089,7 @@ void LLPipeline::updateGeom(F32 max_dtime)
 	LLTimer update_timer;
 	LLPointer<LLDrawable> drawablep;
 
-	LL_RECORD_BLOCK_TIME(FTM_GEO_UPDATE);
+	LL_PROFILE_ZONE_NAMED_CATEGORY_DRAWABLE("updateGeom") //LL_RECORD_BLOCK_TIME(FTM_GEO_UPDATE);
 
 	assertInitialized();
 
@@ -7591,13 +7590,10 @@ void LLPipeline::bindScreenToTexture()
 	
 }
 
-static LLTrace::BlockTimerStatHandle FTM_RENDER_FINALIZE("Render Finalize");
-
-static LLTrace::BlockTimerStatHandle FTM_RENDER_BLOOM("Bloom");
-
 void LLPipeline::renderFinalize()
 {
-    LLVertexBuffer::unbind();
+	LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
+	LLVertexBuffer::unbind();
     LLGLState::checkStates();
     LLGLState::checkTextureChannels();
 
@@ -7611,7 +7607,6 @@ void LLPipeline::renderFinalize()
     LLVector2 tc1(0, 0);
     LLVector2 tc2((F32) mScreen.getWidth() * 2, (F32) mScreen.getHeight() * 2);
 
-    LL_RECORD_BLOCK_TIME(FTM_RENDER_FINALIZE);
     gGL.color4f(1, 1, 1, 1);
     LLGLDepthTest depth(GL_FALSE);
     LLGLDisable blend(GL_BLEND);
@@ -7633,7 +7628,7 @@ void LLPipeline::renderFinalize()
 
 	if (!sRenderDeferred)
 	{
-		LL_RECORD_BLOCK_TIME(FTM_RENDER_BLOOM);
+		LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("forward Bloom")
 		if (sRenderGlow)
 		{
 			mGlow[1].bindTarget();
@@ -8654,8 +8649,6 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget *screen_target)
         return;
     }
 
-	LL_RECORD_BLOCK_TIME(FTM_RENDER_DEFERRED);
-
     LLRenderTarget *deferred_target       = &mDeferredScreen;
     LLRenderTarget *deferred_depth_target = &mDeferredDepth;
     LLRenderTarget *deferred_light_target = &mDeferredLight;
@@ -9181,7 +9174,7 @@ void LLPipeline::renderDeferredLighting(LLRenderTarget *screen_target)
 		LLVector2 tc1(0, 0);
 		LLVector2 tc2((F32)mScreen.getWidth() * 2, (F32)mScreen.getHeight() * 2);
 
-		LL_RECORD_BLOCK_TIME(FTM_RENDER_DEFERRED_BLOOM);
+		LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("renderDeferredLighting - bloom");
 		LLGLDepthTest depth(GL_FALSE);
 		LLGLDisable blend(GL_BLEND);
 		LLGLDisable cull(GL_CULL_FACE);
@@ -11135,11 +11128,9 @@ void LLPipeline::renderRiggedGroups(LLRenderPass* pass, U32 type, U32 mask, bool
     }
 }
 
-static LLTrace::BlockTimerStatHandle FTM_GENERATE_IMPOSTOR("Generate Impostor");
-
 void LLPipeline::generateImpostor(LLVOAvatar* avatar, bool preview_avatar)
 {
-    LL_RECORD_BLOCK_TIME(FTM_GENERATE_IMPOSTOR);
+	LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("Generate Impostor");
 	LLGLState::checkStates();
 	LLGLState::checkTextureChannels();
 
diff --git a/indra/newview/rlveffects.cpp b/indra/newview/rlveffects.cpp
index 74e74fcc73c..ee983e7382a 100644
--- a/indra/newview/rlveffects.cpp
+++ b/indra/newview/rlveffects.cpp
@@ -395,11 +395,9 @@ void RlvSphereEffect::renderPass(LLGLSLShader* pShader, const LLShaderEffectPara
 	}
 }
 
-LLTrace::BlockTimerStatHandle FTM_RLV_EFFECT_SPHERE("Post-process (RLVa sphere)");
-
 void RlvSphereEffect::run(const LLVisualEffectParams* pParams)
 {
-	LL_RECORD_BLOCK_TIME(FTM_RLV_EFFECT_SPHERE);
+	LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("Post-process (RLVa sphere)");
 	LLGLDepthTest depth(GL_FALSE, GL_FALSE);
 
 	gRlvSphereProgram.bind();
-- 
GitLab