Bug 1529894 - Change zip logging initialization. r=aklotz
☠☠ backed out by 24e79b0a187f ☠ ☠
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 05 Mar 2019 23:33:21 +0000
changeset 520430 e93f4871731b8e658c7febf013cd985738ad1435
parent 520429 c36dc28ad5d0fd3fb3819471f6b05a8fa6646688
child 520431 3c37fd9d30d50b66b9b899c3f85758079f8e31d1
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaklotz
bugs1529894
milestone67.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 1529894 - Change zip logging initialization. r=aklotz Instead of checking the MOZ_JAR_LOG_FILE for each log entry, only check it once, and only check whether to log once per archive rather than once per item. Differential Revision: https://phabricator.services.mozilla.com/D21655
modules/libjar/nsZipArchive.cpp
--- a/modules/libjar/nsZipArchive.cpp
+++ b/modules/libjar/nsZipArchive.cpp
@@ -73,24 +73,18 @@ static const uint16_t kSyntheticTime = 0
 static const uint16_t kSyntheticDate = (1 + (1 << 5) + (0 << 9));
 
 static uint16_t xtoint(const uint8_t *ii);
 static uint32_t xtolong(const uint8_t *ll);
 static uint32_t HashName(const char *aName, uint16_t nameLen);
 
 class ZipArchiveLogger {
  public:
-  void Write(const nsACString &zip, const char *entry) const {
-    if (!XRE_IsParentProcess()) {
-      return;
-    }
+  void Init(const char *env) {
     if (!fd) {
-      char *env = PR_GetEnv("MOZ_JAR_LOG_FILE");
-      if (!env) return;
-
       nsCOMPtr<nsIFile> logFile;
       nsresult rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(env), false,
                                     getter_AddRefs(logFile));
       if (NS_FAILED(rv)) return;
 
       // Create the log file and its parent directory (in case it doesn't exist)
       rv = logFile->Create(nsIFile::NORMAL_FILE_TYPE, 0644);
       if (NS_FAILED(rv)) return;
@@ -111,21 +105,26 @@ class ZipArchiveLogger {
       if (!file) return;
 #else
       rv = logFile->OpenNSPRFileDesc(PR_WRONLY | PR_CREATE_FILE | PR_APPEND,
                                      0644, &file);
       if (NS_FAILED(rv)) return;
 #endif
       fd = file;
     }
-    nsCString buf(zip);
-    buf.Append(' ');
-    buf.Append(entry);
-    buf.Append('\n');
-    PR_Write(fd, buf.get(), buf.Length());
+  }
+
+  void Write(const nsACString &zip, const char *entry) const {
+    if (fd) {
+      nsCString buf(zip);
+      buf.Append(' ');
+      buf.Append(entry);
+      buf.Append('\n');
+      PR_Write(fd, buf.get(), buf.Length());
+    }
   }
 
   void AddRef() {
     MOZ_ASSERT(refCnt >= 0);
     ++refCnt;
   }
 
   void Release() {
@@ -133,17 +132,17 @@ class ZipArchiveLogger {
     if ((0 == --refCnt) && fd) {
       PR_Close(fd);
       fd = nullptr;
     }
   }
 
  private:
   int refCnt;
-  mutable PRFileDesc *fd;
+  PRFileDesc *fd;
 };
 
 static ZipArchiveLogger zipLog;
 
 //***********************************************************
 // For every inflation the following allocations are done:
 // malloc(1 * 9520)
 // malloc(32768 * 1)
@@ -331,17 +330,23 @@ nsZipHandle::~nsZipHandle() {
 //  nsZipArchive::OpenArchive
 //---------------------------------------------
 nsresult nsZipArchive::OpenArchive(nsZipHandle *aZipHandle, PRFileDesc *aFd) {
   mFd = aZipHandle;
 
   //-- get table of contents for archive
   nsresult rv = BuildFileList(aFd);
   if (NS_SUCCEEDED(rv)) {
-    if (aZipHandle->mFile) aZipHandle->mFile.GetURIString(mURI);
+    if (aZipHandle->mFile && XRE_IsParentProcess()) {
+      static char *env = PR_GetEnv("MOZ_JAR_LOG_FILE");
+      if (env) {
+        zipLog.Init(env);
+        aZipHandle->mFile.GetURIString(mURI);
+      }
+    }
   }
   return rv;
 }
 
 nsresult nsZipArchive::OpenArchive(nsIFile *aFile) {
   RefPtr<nsZipHandle> handle;
 #if defined(XP_WIN)
   mozilla::AutoFDClose fd;
@@ -422,17 +427,19 @@ nsZipItem *nsZipArchive::GetItem(const c
     }
     MOZ_WIN_MEM_TRY_BEGIN
     nsZipItem *item = mFiles[HashName(aEntryName, len)];
     while (item) {
       if ((len == item->nameLength) &&
           (!memcmp(aEntryName, item->Name(), len))) {
         // Successful GetItem() is a good indicator that the file is about to be
         // read
-        zipLog.Write(mURI, aEntryName);
+        if (mURI.Length()) {
+          zipLog.Write(mURI, aEntryName);
+        }
         return item;  //-- found it
       }
       item = item->next;
     }
     MOZ_WIN_MEM_TRY_CATCH(return nullptr)
   }
   return nullptr;
 }