From 52dfeca5f2228b4df5b0d0013de5b332695419e9 Mon Sep 17 00:00:00 2001 From: "erik.corry@gmail.com" Date: Tue, 16 Jun 2009 12:52:02 +0000 Subject: [PATCH] Fix profiling for shared libraries on Linux loaded at negative addresses (Android does this). Fix logging for executable mappings that have no file associated. Be more consistent with use of uintptr_t. Review URL: http://codereview.chromium.org/125183 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2187 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/log.cc | 20 ++++++++++++-------- src/log.h | 8 ++++---- src/platform-linux.cc | 27 +++++++++++++++++++-------- 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/log.cc b/src/log.cc index af49128ea..1777234d5 100644 --- a/src/log.cc +++ b/src/log.cc @@ -426,26 +426,30 @@ void Logger::ApiNamedSecurityCheck(Object* key) { void Logger::SharedLibraryEvent(const char* library_path, - unsigned start, - unsigned end) { + uintptr_t start, + uintptr_t end) { #ifdef ENABLE_LOGGING_AND_PROFILING if (!Log::IsEnabled() || !FLAG_prof) return; LogMessageBuilder msg; - msg.Append("shared-library,\"%s\",0x%08x,0x%08x\n", library_path, - start, end); + msg.Append("shared-library,\"%s\",0x%08" V8PRIxPTR ",0x%08" V8PRIxPTR "\n", + library_path, + start, + end); msg.WriteToLogFile(); #endif } void Logger::SharedLibraryEvent(const wchar_t* library_path, - unsigned start, - unsigned end) { + uintptr_t start, + uintptr_t end) { #ifdef ENABLE_LOGGING_AND_PROFILING if (!Log::IsEnabled() || !FLAG_prof) return; LogMessageBuilder msg; - msg.Append("shared-library,\"%ls\",0x%08x,0x%08x\n", library_path, - start, end); + msg.Append("shared-library,\"%ls\",0x%08" V8PRIxPTR ",0x%08" V8PRIxPTR "\n", + library_path, + start, + end); msg.WriteToLogFile(); #endif } diff --git a/src/log.h b/src/log.h index 08e957a12..89939cbb3 100644 --- a/src/log.h +++ b/src/log.h @@ -217,11 +217,11 @@ class Logger { static void HeapSampleItemEvent(const char* type, int number, int bytes); static void SharedLibraryEvent(const char* library_path, - unsigned start, - unsigned end); + uintptr_t start, + uintptr_t end); static void SharedLibraryEvent(const wchar_t* library_path, - unsigned start, - unsigned end); + uintptr_t start, + uintptr_t end); // ==== Events logged by --log-regexp ==== // Regexp compilation and execution events. diff --git a/src/platform-linux.cc b/src/platform-linux.cc index 79ffe8149..39495ab96 100644 --- a/src/platform-linux.cc +++ b/src/platform-linux.cc @@ -224,8 +224,8 @@ PosixMemoryMappedFile::~PosixMemoryMappedFile() { #ifdef ENABLE_LOGGING_AND_PROFILING -static unsigned StringToLong(char* buffer) { - return static_cast(strtol(buffer, NULL, 16)); // NOLINT +static uintptr_t StringToULong(char* buffer) { + return strtoul(buffer, NULL, 16); // NOLINT } #endif @@ -242,13 +242,13 @@ void OS::LogSharedLibraryAddresses() { addr_buffer[10] = 0; int result = read(fd, addr_buffer + 2, 8); if (result < 8) break; - unsigned start = StringToLong(addr_buffer); + uintptr_t start = StringToULong(addr_buffer); result = read(fd, addr_buffer + 2, 1); if (result < 1) break; if (addr_buffer[2] != '-') break; result = read(fd, addr_buffer + 2, 8); if (result < 8) break; - unsigned end = StringToLong(addr_buffer); + uintptr_t end = StringToULong(addr_buffer); char buffer[MAP_LENGTH]; int bytes_read = -1; do { @@ -262,10 +262,21 @@ void OS::LogSharedLibraryAddresses() { // Ignore mappings that are not executable. if (buffer[3] != 'x') continue; char* start_of_path = index(buffer, '/'); - // There may be no filename in this line. Skip to next. - if (start_of_path == NULL) continue; - buffer[bytes_read] = 0; - LOG(SharedLibraryEvent(start_of_path, start, end)); + // 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)); + } } close(fd); #endif -- 2.34.1