Bug 1376496 - Part 3 - MOZ_LOG JAR cache hits/misses in DEBUG. r=mayhemer
authorHaik Aftandilian <haftandilian@mozilla.com>
Fri, 21 Jul 2017 16:14:16 -0700
changeset 419811 20114f663be1e5cb2ec93bc72f841d5610b3be15
parent 419810 4a4f23c6fb22ddb6a288a6f245da985192ee4129
child 419812 53d735d834049453a5883e6d3ccbbd60ef06b218
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmayhemer
bugs1376496
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1376496 - Part 3 - MOZ_LOG JAR cache hits/misses in DEBUG. r=mayhemer MozReview-Commit-ID: IhiNxvt7vY
netwerk/protocol/res/ExtensionProtocolHandler.cpp
--- a/netwerk/protocol/res/ExtensionProtocolHandler.cpp
+++ b/netwerk/protocol/res/ExtensionProtocolHandler.cpp
@@ -66,16 +66,20 @@ public:
 
   operator nsresult() { return mErrorValue; }
 };
 
 namespace net {
 
 using extensions::URLInfo;
 
+LazyLogModule gExtProtocolLog("ExtProtocol");
+#undef LOG
+#define LOG(...) MOZ_LOG(gExtProtocolLog, LogLevel::Debug, (__VA_ARGS__))
+
 StaticRefPtr<ExtensionProtocolHandler> ExtensionProtocolHandler::sSingleton;
 
 static inline Result<Ok, nsresult>
 WrapNSResult(PRStatus aRv)
 {
     if (aRv != PR_SUCCESS) {
         return Err(NS_ERROR_FAILURE);
     }
@@ -764,42 +768,70 @@ ExtensionProtocolHandler::SubstituteRemo
   MOZ_ASSERT(IsNeckoChild());
 
   RefPtr<ExtensionStreamGetter> streamGetter =
     new ExtensionStreamGetter(aURI, aLoadinfo);
 
   NewSimpleChannel(aURI, aLoadinfo, streamGetter, aRetVal);
 }
 
+static Result<Ok, nsresult>
+LogCacheCheck(const nsIJARChannel* aJarChannel,
+              nsIJARURI* aJarURI,
+              bool aIsCached)
+{
+  nsresult rv;
+
+  nsCOMPtr<nsIURI> innerFileURI;
+  NS_TRY(aJarURI->GetJARFile(getter_AddRefs(innerFileURI)));
+
+  nsCOMPtr<nsIFileURL> innerFileURL = do_QueryInterface(innerFileURI, &rv);
+  NS_TRY(rv);
+
+  nsCOMPtr<nsIFile> jarFile;
+  NS_TRY(innerFileURL->GetFile(getter_AddRefs(jarFile)));
+
+  nsAutoCString uriSpec, jarSpec;
+  Unused << aJarURI->GetSpec(uriSpec);
+  Unused << innerFileURI->GetSpec(jarSpec);
+  LOG("[JARChannel %p] Cache %s: %s (%s)",
+      aJarChannel, aIsCached ? "hit" : "miss", uriSpec.get(), jarSpec.get());
+
+  return Ok();
+}
+
 Result<Ok, nsresult>
 ExtensionProtocolHandler::SubstituteRemoteJarChannel(nsIURI* aURI,
                                                      nsILoadInfo* aLoadinfo,
                                                      nsACString& aResolvedSpec,
                                                      nsIChannel** aRetVal)
 {
   MOZ_ASSERT(IsNeckoChild());
   nsresult rv;
 
-  nsCOMPtr<nsIJARChannel> jarChannel = do_QueryInterface(*aRetVal, &rv);
-  NS_TRY(rv);
-
-  bool isCached = false;
-  NS_TRY(jarChannel->EnsureCached(&isCached));
-  if (isCached) {
-    return Ok();
-  }
-
   // Build a JAR URI for this jar:file:// URI and use it to extract the
   // inner file URI.
   nsCOMPtr<nsIURI> uri;
   NS_TRY(NS_NewURI(getter_AddRefs(uri), aResolvedSpec));
 
   nsCOMPtr<nsIJARURI> jarURI = do_QueryInterface(uri, &rv);
   NS_TRY(rv);
 
+  nsCOMPtr<nsIJARChannel> jarChannel = do_QueryInterface(*aRetVal, &rv);
+  NS_TRY(rv);
+
+  bool isCached = false;
+  NS_TRY(jarChannel->EnsureCached(&isCached));
+  if (MOZ_LOG_TEST(gExtProtocolLog, LogLevel::Debug)) {
+    Unused << LogCacheCheck(jarChannel, jarURI, isCached);
+  }
+  if (isCached) {
+    return Ok();
+  }
+
   nsCOMPtr<nsIURI> innerFileURI;
   NS_TRY(jarURI->GetJARFile(getter_AddRefs(innerFileURI)));
 
   nsCOMPtr<nsIFileURL> innerFileURL = do_QueryInterface(innerFileURI, &rv);
   NS_TRY(rv);
 
   nsCOMPtr<nsIFile> jarFile;
   NS_TRY(innerFileURL->GetFile(getter_AddRefs(jarFile)));