Backed out changeset d89a7ed61c19 (bug 1035396) for asan failures

This commit is contained in:
Ed Morley 2014-07-11 15:58:21 +01:00
Родитель 8e26939459
Коммит 15de8c4224
1 изменённых файлов: 13 добавлений и 34 удалений

Просмотреть файл

@ -45,9 +45,6 @@ using namespace mozilla;
#if defined(XP_LINUX)
#include <string.h>
#include <stdlib.h>
static nsresult
GetProcSelfStatmField(int aField, int64_t* aN)
{
@ -71,48 +68,30 @@ GetProcSelfStatmField(int aField, int64_t* aN)
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;
}