X64: Fixes to enable C/C++ functions processing in profiler.

- rewrote Linux version of LogSharedLibraryAddresses to work correctly with 64-bit libs;
 - fixed address length restriction in JS tickprofiler script.

Review URL: http://codereview.chromium.org/160273


git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2563 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
mikhail.naganov@gmail.com 2009-07-28 15:37:05 +00:00
parent 4354661a49
commit ee340a52ff
2 changed files with 26 additions and 52 deletions

View File

@ -223,62 +223,36 @@ PosixMemoryMappedFile::~PosixMemoryMappedFile() {
} }
#ifdef ENABLE_LOGGING_AND_PROFILING
static uintptr_t StringToULong(char* buffer) {
return strtoul(buffer, NULL, 16); // NOLINT
}
#endif
void OS::LogSharedLibraryAddresses() { void OS::LogSharedLibraryAddresses() {
#ifdef ENABLE_LOGGING_AND_PROFILING #ifdef ENABLE_LOGGING_AND_PROFILING
static const int MAP_LENGTH = 1024; FILE *fp;
int fd = open("/proc/self/maps", O_RDONLY); fp = fopen("/proc/self/maps", "r");
if (fd < 0) return; if (fp == NULL) return;
while (true) { while (true) {
char addr_buffer[11]; uintptr_t start, end;
addr_buffer[0] = '0'; char attr_r, attr_w, attr_x, attr_p;
addr_buffer[1] = 'x'; if (fscanf(fp, "%" V8PRIxPTR "-%" V8PRIxPTR, &start, &end) != 2) break;
addr_buffer[10] = 0; if (fscanf(fp, " %c%c%c%c", &attr_r, &attr_w, &attr_x, &attr_p) != 4) break;
int result = read(fd, addr_buffer + 2, 8); char c;
if (result < 8) break; if (attr_r == 'r' && attr_x == 'x') {
uintptr_t start = StringToULong(addr_buffer); while (c = getc(fp), c != EOF && c != '\n' && c != '/');
result = read(fd, addr_buffer + 2, 1); char lib_name[1024];
if (result < 1) break; bool lib_has_name = false;
if (addr_buffer[2] != '-') break; if (c == '/') {
result = read(fd, addr_buffer + 2, 8); ungetc(c, fp);
if (result < 8) break; lib_has_name = fgets(lib_name, sizeof(lib_name), fp) != NULL;
uintptr_t end = StringToULong(addr_buffer); }
char buffer[MAP_LENGTH]; if (lib_has_name && strlen(lib_name) > 0) {
int bytes_read = -1; lib_name[strlen(lib_name) - 1] = '\0';
do { } else {
bytes_read++; snprintf(lib_name, sizeof(lib_name),
if (bytes_read >= MAP_LENGTH - 1) "%08" V8PRIxPTR "-%08" V8PRIxPTR, start, end);
break; }
result = read(fd, buffer + bytes_read, 1); LOG(SharedLibraryEvent(lib_name, start, end));
if (result < 1) break;
} while (buffer[bytes_read] != '\n');
buffer[bytes_read] = 0;
// Ignore mappings that are not executable.
if (buffer[3] != 'x') continue;
char* start_of_path = index(buffer, '/');
// If there is no filename for this line then log it as an anonymous
// mapping and use the address as its name.
if (start_of_path == NULL) {
// 40 is enough to print a 64 bit address range.
ASSERT(sizeof(buffer) > 40);
snprintf(buffer,
sizeof(buffer),
"%08" V8PRIxPTR "-%08" V8PRIxPTR,
start,
end);
LOG(SharedLibraryEvent(buffer, start, end));
} else {
buffer[bytes_read] = 0;
LOG(SharedLibraryEvent(start_of_path, start, end));
} }
while (c = getc(fp), c != EOF && c != '\n');
} }
close(fd); fclose(fp);
#endif #endif
} }

View File

@ -429,7 +429,7 @@ function UnixCppEntriesProvider(nmExec) {
this.symbols = []; this.symbols = [];
this.parsePos = 0; this.parsePos = 0;
this.nmExec = nmExec; this.nmExec = nmExec;
this.FUNC_RE = /^([0-9a-fA-F]{8}) ([0-9a-fA-F]{8} )?[tTwW] (.*)$/; this.FUNC_RE = /^([0-9a-fA-F]{8,16}) ([0-9a-fA-F]{8,16} )?[tTwW] (.*)$/;
}; };
inherits(UnixCppEntriesProvider, CppEntriesProvider); inherits(UnixCppEntriesProvider, CppEntriesProvider);