Backed out changeset d89a7ed61c19 (bug 1035396) for asan failures
authorEd Morley <emorley@mozilla.com>
Fri, 11 Jul 2014 15:58:21 +0100
changeset 193602 9396c2c95b0036b703e609e2f1578b8c6a0f7a91
parent 193601 11f7830bc276e5d73c0cd8bb18d36762f1ff7823
child 193603 5373a38e3306a385e75e3500c0aadebc72059d5c
push id27123
push userryanvm@gmail.com
push dateFri, 11 Jul 2014 20:35:05 +0000
treeherdermozilla-central@84bd8d9f4256 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1035396
milestone33.0a1
backs outd89a7ed61c1924133e5e70633dd5ff9a25a8b4b7
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
Backed out changeset d89a7ed61c19 (bug 1035396) for asan failures
xpcom/base/nsMemoryReporterManager.cpp
--- a/xpcom/base/nsMemoryReporterManager.cpp
+++ b/xpcom/base/nsMemoryReporterManager.cpp
@@ -40,19 +40,16 @@ using namespace mozilla;
 
 #if defined(MOZ_MEMORY)
 #  define HAVE_JEMALLOC_STATS 1
 #  include "mozmemory.h"
 #endif  // MOZ_MEMORY
 
 #if defined(XP_LINUX)
 
-#include <string.h>
-#include <stdlib.h>
-
 static nsresult
 GetProcSelfStatmField(int aField, int64_t* aN)
 {
   // There are more than two fields, but we're only interested in the first
   // two.
   static const int MAX_FIELD = 2;
   size_t fields[MAX_FIELD];
   MOZ_ASSERT(aField < MAX_FIELD, "bad field number");
@@ -66,58 +63,40 @@ GetProcSelfStatmField(int aField, int64_
     }
   }
   return NS_ERROR_FAILURE;
 }
 
 static nsresult
 GetProcSelfSmapsPrivate(int64_t* aN)
 {
-  // You might be tempted to calculate USS by subtracting the "shared" value
-  // from the "resident" value in /proc/<pid>/statm. But at least on Linux,
-  // statm's "shared" value actually counts pages backed by files, which has
-  // little to do with whether the pages are actually shared. /proc/self/smaps
-  // on the other hand appears to give us the correct information.
+  // You might be tempted to calculate USS by subtracting the "shared"
+  // value from the "resident" value in /proc/<pid>/statm. But at least
+  // on Linux, statm's "shared" value actually counts pages backed by
+  // files, which has little to do with whether the pages are actually
+  // shared. /proc/self/smaps on the other hand appears to give us the
+  // correct information.
 
   FILE* f = fopen("/proc/self/smaps", "r");
   if (NS_WARN_IF(!f)) {
     return NS_ERROR_UNEXPECTED;
   }
 
-  // We carry over the end of the buffer to make sure we don't accidentally
-  // break on an interesting line.
-  static const uint32_t carryOver = 32;
-  static const uint32_t readSize = 4096;
-
   int64_t amount = 0;
-  char buffer[carryOver + readSize + 1];
-  memset(buffer, ' ', carryOver);
-
-  for (;;) {
-    size_t bytes = fread(buffer + carryOver, sizeof(*buffer), readSize, f);
-    char* end = buffer + bytes;
-    char* ptr = buffer;
-    end[carryOver] = '\0';
-    // We are looking for lines like "Private_{Clean,Dirty}: 4 kB".
-    while (ptr = strstr(ptr, "Private")) {
-      ptr += sizeof("Private_Xxxxx:");
-      amount += atoi(ptr);
-      if (ptr >= end) {
-        break;
-      }
+  char line[256];
+  while (fgets(line, sizeof(line), f)) {
+    long long val = 0;
+    if (sscanf(line, "Private_Dirty: %lld kB", &val) == 1 ||
+        sscanf(line, "Private_Clean: %lld kB", &val) == 1) {
+      amount += val * 1024; // convert from kB to bytes
     }
-    if (bytes < readSize) {
-      break;
-    }
-    memcpy(buffer, end, carryOver);
   }
 
   fclose(f);
-  // Convert from kB to bytes.
-  *aN = amount * 1024;
+  *aN = amount;
   return NS_OK;
 }
 
 #define HAVE_VSIZE_AND_RESIDENT_REPORTERS 1
 static nsresult
 VsizeDistinguishedAmount(int64_t* aN)
 {
   return GetProcSelfStatmField(0, aN);