Reviewers: Michael Starzinger,
Description:
Introduce a test of how much memory it takes to boot up V8.
Linux only at the moment, since it uses /proc. Shows that
there is room for improvement, espcially on 64 bit.
Please review this at http://codereview.chromium.org/8750001/
SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/
Affected files:
M test/cctest/test-mark-compact.cc
Index: test/cctest/test-mark-compact.cc
===================================================================
--- test/cctest/test-mark-compact.cc (revision 10092)
+++ test/cctest/test-mark-compact.cc (working copy)
@@ -27,6 +27,14 @@
#include <stdlib.h>
+#ifdef __linux__
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <errno.h>
+#endif
+
#include "v8.h"
#include "global-handles.h"
@@ -444,3 +452,84 @@
global_handles->AddImplicitReferences(
Handle<HeapObject>::cast(object).location(), NULL, 0);
}
+
+
+#ifdef __linux__
+
+
+static unsigned long ReadLong(char* buffer, intptr_t* position, int base) {
+ char* end_address = buffer + *position;
+ unsigned long result = strtoul(buffer + *position, &end_address, base);
+ CHECK(result != ULONG_MAX || errno != ERANGE);
+ CHECK(end_address > buffer + *position);
+ *position = end_address - buffer;
+ return result;
+}
+
+
+static intptr_t MemoryInUse() {
+ long memory_use = 0;
+
+ int fd = open("/proc/self/maps", O_RDONLY);
+ if (fd < 0) return -1;
+
+ const int kBufSize = 10000;
+ char buffer[kBufSize];
+ int length = read(fd, buffer, kBufSize);
+ intptr_t line_start = 0;
+ CHECK(length < kBufSize); // Make the buffer bigger.
+ CHECK(length > 0); // We have to find some data in the file.
+ while (line_start < length) {
+ if (buffer[line_start] == '\n') {
+ line_start++;
+ continue;
+ }
+ intptr_t position = line_start;
+ unsigned long start = ReadLong(buffer, &position, 16);
+ CHECK(buffer[position++] == '-');
+ unsigned long end = ReadLong(buffer, &position, 16);
+ CHECK(buffer[position++] == ' ');
+ CHECK(buffer[position] == '-' || buffer[position] == 'r');
+ bool read_permission = (buffer[position++] == 'r');
+ CHECK(buffer[position] == '-' || buffer[position] == 'w');
+ bool write_permission = (buffer[position++] == 'w');
+ CHECK(buffer[position] == '-' || buffer[position] == 'x');
+ bool execute_permission = (buffer[position++] == 'x');
+ CHECK(buffer[position] == '-' || buffer[position] == 'p');
+ bool private_mapping = (buffer[position++] == 'p');
+ CHECK(buffer[position++] == ' ');
+ unsigned long offset = ReadLong(buffer, &position, 16);
+ USE(offset);
+ CHECK(buffer[position++] == ' ');
+ unsigned long major = ReadLong(buffer, &position, 16);
+ USE(major);
+ CHECK(buffer[position++] == ':');
+ unsigned long minor = ReadLong(buffer, &position, 16);
+ USE(minor);
+ CHECK(buffer[position++] == ' ');
+ unsigned long inode = ReadLong(buffer, &position, 10);
+ while(position < length && buffer[position] != '\n') position++;
+ if ((read_permission || write_permission || execute_permission) &&
+ private_mapping && inode == 0) {
+ memory_use += (end - start);
+ }
+
+ line_start = position;
+ }
+ close(fd);
+ return memory_use;
+}
+
+
+TEST(BootUpMemoryUse) {
+ intptr_t initial_memory = MemoryInUse();
+ // Only Linux has the proc filesystem and only if it is mapped. If it's
not
+ // there we just skip the test.
+ if (initial_memory >= 0) {
+ InitializeVM();
+ intptr_t booted_memory = MemoryInUse();
+ CHECK_LE(booted_memory - initial_memory, 20 * 1024 * 1024);
+ }
+}
+
+#endif
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev