From a6cc3b7159445eb4da5d17a7b19a3ec19625c318 Mon Sep 17 00:00:00 2001
From: maxim_productengine <mnikolenko@productengine.com>
Date: Mon, 6 May 2019 17:14:55 +0300
Subject: [PATCH] SL-11074 FIXED "Cache Hit Rate" in Statistics is broken

---
 indra/newview/lltexturefetch.cpp  | 4 +++-
 indra/newview/lltexturefetch.h    | 1 +
 indra/newview/llviewertexture.cpp | 5 +++++
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/indra/newview/lltexturefetch.cpp b/indra/newview/lltexturefetch.cpp
index c9133338fb1..f6cb787156c 100644
--- a/indra/newview/lltexturefetch.cpp
+++ b/indra/newview/lltexturefetch.cpp
@@ -66,6 +66,7 @@ bool LLTextureFetchDebugger::sDebuggerEnabled = false ;
 
 LLTrace::CountStatHandle<F64> LLTextureFetch::sCacheHit("texture_cache_hit");
 LLTrace::CountStatHandle<F64> LLTextureFetch::sCacheAttempt("texture_cache_attempt");
+LLTrace::EventStatHandle<LLUnit<F32, LLUnits::Percent> > LLTextureFetch::sCacheHitRate("texture_cache_hits");
 
 LLTrace::SampleStatHandle<F32Seconds> LLTextureFetch::sCacheReadLatency("texture_cache_read_latency");
 LLTrace::SampleStatHandle<F32Seconds> LLTextureFetch::sTexDecodeLatency("texture_decode_latency");
@@ -1311,6 +1312,7 @@ bool LLTextureFetchWorker::doWork(S32 param)
 			LL_DEBUGS(LOG_TXT) << mID << ": Cached. Bytes: " << mFormattedImage->getDataSize()
 							   << " Size: " << llformat("%dx%d",mFormattedImage->getWidth(),mFormattedImage->getHeight())
 							   << " Desired Discard: " << mDesiredDiscard << " Desired Size: " << mDesiredSize << LL_ENDL;
+			record(LLTextureFetch::sCacheHitRate, LLUnits::Ratio::fromValue(1));
 		}
 		else
 		{
@@ -1326,7 +1328,7 @@ bool LLTextureFetchWorker::doWork(S32 param)
 				LL_DEBUGS(LOG_TXT) << mID << ": Not in Cache" << LL_ENDL;
 				setState(LOAD_FROM_NETWORK);
 			}
-			
+			record(LLTextureFetch::sCacheHitRate, LLUnits::Ratio::fromValue(0));
 			// fall through
 		}
 	}
diff --git a/indra/newview/lltexturefetch.h b/indra/newview/lltexturefetch.h
index a01c01847ec..cdf88685970 100644
--- a/indra/newview/lltexturefetch.h
+++ b/indra/newview/lltexturefetch.h
@@ -312,6 +312,7 @@ class LLTextureFetch : public LLWorkerThread
     static LLTrace::SampleStatHandle<F32Seconds> sCacheReadLatency;
     static LLTrace::SampleStatHandle<F32Seconds> sTexDecodeLatency;
     static LLTrace::SampleStatHandle<F32Seconds> sTexFetchLatency;
+    static LLTrace::EventStatHandle<LLUnit<F32, LLUnits::Percent> > sCacheHitRate;
 
 private:
 	LLMutex mQueueMutex;        //to protect mRequestMap and mCommands only
diff --git a/indra/newview/llviewertexture.cpp b/indra/newview/llviewertexture.cpp
index 68a9994beeb..a81b3aaef99 100644
--- a/indra/newview/llviewertexture.cpp
+++ b/indra/newview/llviewertexture.cpp
@@ -1219,6 +1219,7 @@ void LLViewerFetchedTexture::loadFromFastCache()
         F32 cachReadTime = fastCacheTimer.getElapsedTimeF32();
 
         add(LLTextureFetch::sCacheHit, 1.0);
+        record(LLTextureFetch::sCacheHitRate, LLUnits::Ratio::fromValue(1));
         sample(LLTextureFetch::sCacheReadLatency, cachReadTime);
 
 		mFullWidth = mRawImage->getWidth() << mRawDiscardLevel;
@@ -1251,6 +1252,10 @@ void LLViewerFetchedTexture::loadFromFastCache()
 			addToCreateTexture();
 		}
 	}
+    else
+    {
+        record(LLTextureFetch::sCacheHitRate, LLUnits::Ratio::fromValue(0));
+    }
 }
 
 void LLViewerFetchedTexture::setForSculpt()
-- 
GitLab