From 0fd80d09972657e6417193abf577084a3b3b85f1 Mon Sep 17 00:00:00 2001
From: Monty Brandenberg <monty@lindenlab.com>
Date: Wed, 24 Nov 2010 16:46:40 -0500
Subject: [PATCH] ESC-154 ESC-156  Metrics integration across threads Using
 unpause() method in derived class rather than wake() in furthest base class
 solved the stalling problem.  I still think too many levels of the
 LLTextureFetch hierarchy are keeping thread state, however.  The
 LLViewerRegion instance an agent enters doesn't necessarily have its
 region_id yet, that only comes after the handshake, if any.  So add a few
 more metrics insertion points to propagate region into metrics. Finally, try
 to launch a final metrics report when a quit is initiated.

---
 indra/newview/llappviewer.cpp    |  5 +++--
 indra/newview/llappviewer.h      |  2 +-
 indra/newview/lltexturefetch.cpp | 37 +++++++++++++++++---------------
 indra/newview/lltexturefetch.h   |  1 +
 indra/newview/llviewerregion.cpp |  8 +++++++
 5 files changed, 33 insertions(+), 20 deletions(-)

diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index 86fba90ff7a..bf795230786 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -2932,6 +2932,7 @@ void LLAppViewer::requestQuit()
 	LLSideTray::getInstance()->notifyChildren(LLSD().with("request","quit"));
 
 	send_stats();
+	metricsSend(!gDisconnected);
 
 	gLogoutTimer.reset();
 	mQuitRequested = true;
@@ -3719,7 +3720,7 @@ void LLAppViewer::idle()
 		// *TODO:  Add configuration controls for this
 		if (report_interval.getElapsedTimeF32() >= app_metrics_interval)
 		{
-			metricsIdle(! gDisconnected);
+			metricsSend(! gDisconnected);
 			report_interval.reset();
 		}
 	}
@@ -4601,7 +4602,7 @@ void LLAppViewer::metricsUpdateRegion(const LLUUID & region_id)
  * Attempts to start a multi-threaded metrics report to be sent back to
  * the grid for consumption.
  */
-void LLAppViewer::metricsIdle(bool enable_reporting)
+void LLAppViewer::metricsSend(bool enable_reporting)
 {
 	if (! gViewerAssetStatsMain)
 		return;
diff --git a/indra/newview/llappviewer.h b/indra/newview/llappviewer.h
index 909f191ab13..27c104626a3 100644
--- a/indra/newview/llappviewer.h
+++ b/indra/newview/llappviewer.h
@@ -170,7 +170,7 @@ class LLAppViewer : public LLApp
 
 	// Metrics policy helper statics.
 	static void metricsUpdateRegion(const LLUUID & region_id);
-	static void metricsIdle(bool enable_reporting);
+	static void metricsSend(bool enable_reporting);
 	
 protected:
 	virtual bool initWindow(); // Initialize the viewer's window.
diff --git a/indra/newview/lltexturefetch.cpp b/indra/newview/lltexturefetch.cpp
index 2e05a67791d..2be3ba3280c 100644
--- a/indra/newview/lltexturefetch.cpp
+++ b/indra/newview/lltexturefetch.cpp
@@ -2105,6 +2105,21 @@ bool LLTextureFetch::runCondition()
 
 //////////////////////////////////////////////////////////////////////////////
 
+// MAIN THREAD (unthreaded envs), WORKER THREAD (threaded envs)
+void LLTextureFetch::commonUpdate()
+{
+	// Run a cross-thread command, if any.
+	cmdDoWork();
+	
+	// Update Curl on same thread as mCurlGetRequest was constructed
+	S32 processed = mCurlGetRequest->process();
+	if (processed > 0)
+	{
+		lldebugs << "processed: " << processed << " messages." << llendl;
+	}	
+}
+
+
 // MAIN THREAD
 //virtual
 S32 LLTextureFetch::update(U32 max_time_ms)
@@ -2130,12 +2145,7 @@ S32 LLTextureFetch::update(U32 max_time_ms)
 
 	if (!mThreaded)
 	{
-		// Update Curl on same thread as mCurlGetRequest was constructed
-		S32 processed = mCurlGetRequest->process();
-		if (processed > 0)
-		{
-			lldebugs << "processed: " << processed << " messages." << llendl;
-		}
+		commonUpdate();
 	}
 
 	return res;
@@ -2190,15 +2200,7 @@ void LLTextureFetch::threadedUpdate()
 	}
 	process_timer.reset();
 	
-	// Run a cross-thread command, if any.
-	cmdDoWork();
-	
-	// Update Curl on same thread as mCurlGetRequest was constructed
-	S32 processed = mCurlGetRequest->process();
-	if (processed > 0)
-	{
-		lldebugs << "processed: " << processed << " messages." << llendl;
-	}
+	commonUpdate();
 
 #if 0
 	const F32 INFO_TIME = 1.0f; 
@@ -2657,6 +2659,7 @@ void LLTextureFetch::commandSetRegion(const LLUUID & region_id)
 	TFReqSetRegion * req = new TFReqSetRegion(region_id);
 
 	cmdEnqueue(req);
+	LL_INFOS("Texture") << "COMMANDING SET REGION" << LL_ENDL;
 }
 
 void LLTextureFetch::commandSendMetrics(const std::string & caps_url,
@@ -2683,7 +2686,7 @@ void LLTextureFetch::cmdEnqueue(TFRequest * req)
 	mCommands.push_back(req);
 	unlockQueue();
 
-	wake();
+	unpause();
 }
 
 TFRequest * LLTextureFetch::cmdDequeue()
@@ -2818,7 +2821,7 @@ TFReqSendMetrics::doWork(LLTextureFetch * fetcher)
 	LLViewerAssetStatsFF::merge_stats(main_stats, thread1_stats);
 
 	// *TODO:  Consider putting a report size limiter here.
-
+	LL_INFOS("Texture") << "PROCESSING SENDMETRICS REQUEST" << LL_ENDL;
 	if (! mCapsURL.empty())
 	{
 		LLCurlRequest::headers_t headers;
diff --git a/indra/newview/lltexturefetch.h b/indra/newview/lltexturefetch.h
index d46d2da7bc6..bad0a1498fc 100644
--- a/indra/newview/lltexturefetch.h
+++ b/indra/newview/lltexturefetch.h
@@ -109,6 +109,7 @@ class LLTextureFetch : public LLWorkerThread
 	/*virtual*/ void startThread(void);
 	/*virtual*/ void endThread(void);
 	/*virtual*/ void threadedUpdate(void);
+	void commonUpdate();
 
 	// Metrics command helpers
 	/**
diff --git a/indra/newview/llviewerregion.cpp b/indra/newview/llviewerregion.cpp
index 79b45a459fa..717ef404654 100644
--- a/indra/newview/llviewerregion.cpp
+++ b/indra/newview/llviewerregion.cpp
@@ -1341,6 +1341,14 @@ void LLViewerRegion::unpackRegionHandshake()
 	msg->nextBlock("RegionInfo");
 	msg->addU32("Flags", 0x0 );
 	msg->sendReliable(host);
+
+	// Inform metrics when a region associated with an agent
+	// receives a regionID.
+	if (gAgent.getRegion() == this)
+	{
+		// Region is active in agent, tell metrics about the region ID
+		LLAppViewer::metricsUpdateRegion(region_id);
+	}
 }
 
 void LLViewerRegion::setSeedCapability(const std::string& url)
-- 
GitLab