diff options
author | peria@chromium.org <peria@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-11 11:17:48 +0000 |
---|---|---|
committer | peria@chromium.org <peria@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-11 11:17:48 +0000 |
commit | 8e9ead8551868b6c66188f9a852ab4b5c6917789 (patch) | |
tree | a757c1afe18c77764ec2c1b40296ec94cd4c045a /third_party | |
parent | fc4743ad25260e7c4c64ce4060c141a526a4a287 (diff) | |
download | chromium_src-8e9ead8551868b6c66188f9a852ab4b5c6917789.zip chromium_src-8e9ead8551868b6c66188f9a852ab4b5c6917789.tar.gz chromium_src-8e9ead8551868b6c66188f9a852ab4b5c6917789.tar.bz2 |
Enable tcmalloc heap-profiler module on Windows.
This CL only enables heap-profiler in static build
on Windows.
With this CL, heap-profiler does not work fully.
It outputs following information.
- memory mapped files and their address regions
- stack traces of malloc() calls
Reference CL: http://crrev.com/11415113/
BUG=159993
Review URL: https://codereview.chromium.org/96153002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@240072 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party')
4 files changed, 75 insertions, 15 deletions
diff --git a/third_party/tcmalloc/chromium/src/deep-heap-profile.cc b/third_party/tcmalloc/chromium/src/deep-heap-profile.cc index ab21950..b27f1aa 100644 --- a/third_party/tcmalloc/chromium/src/deep-heap-profile.cc +++ b/third_party/tcmalloc/chromium/src/deep-heap-profile.cc @@ -30,6 +30,9 @@ #include <byteswap.h> #endif // defined(__BIG_ENDIAN__) #endif // defined(__linux__) +#if defined(COMPILER_MSVC) +#include <Winsock2.h> // for gethostname +#endif // defined(COMPILER_MSVC) #include "base/cycleclock.h" #include "base/sysinfo.h" @@ -55,8 +58,15 @@ static const char kVirtualLabel[] = "virtual"; static const char kCommittedLabel[] = "committed"; #if defined(__linux__) +#define OS_NAME "linux" +#elif defined(_WIN32) || defined(_WIN64) +#define OS_NAME "windows" +#else +#define OS_NAME "unknown-os" +#endif bool DeepHeapProfile::AppendCommandLine(TextBuffer* buffer) { +#if defined(__linux__) RawFD fd; char filename[100]; char cmdline[4096]; @@ -81,15 +91,31 @@ bool DeepHeapProfile::AppendCommandLine(TextBuffer* buffer) { buffer->AppendChar('\n'); return true; +#else + return false; +#endif } -#else // defined(__linux__) +#if defined(_WIN32) || defined(_WIN64) -bool DeepHeapProfile::AppendCommandLine(TextBuffer* buffer) { +// TODO(peria): Implement this function. +void DeepHeapProfile::MemoryInfoGetterWindows::Initialize() { +} + +// TODO(peria): Implement this function. +size_t DeepHeapProfile::MemoryInfoGetterWindows::CommittedSize( + uint64 first_address, + uint64 last_address, + TextBuffer* buffer) const { + return 0; +} + +// TODO(peria): Implement this function. +bool DeepHeapProfile::MemoryInfoGetterWindows::IsPageCountAvailable() const { return false; } -#endif // defined(__linux__) +#endif // defined(_WIN32) || defined(_WIN64) #if defined(__linux__) @@ -264,7 +290,9 @@ DeepHeapProfile::MemoryResidenceInfoGetterInterface:: DeepHeapProfile::MemoryResidenceInfoGetterInterface* DeepHeapProfile::MemoryResidenceInfoGetterInterface::Create( PageFrameType pageframe_type) { -#if defined(__linux__) +#if defined(_WIN32) || defined(_WIN64) + return new MemoryInfoGetterWindows(pageframe_type); +#elif defined(__linux__) return new MemoryInfoGetterLinux(pageframe_type); #else return NULL; @@ -329,10 +357,11 @@ void DeepHeapProfile::DumpOrderedProfile(const char* reason, most_recent_pid_ = getpid(); - snprintf(run_id_, sizeof(run_id_), "%s-linux-%d-%lu", + snprintf(run_id_, sizeof(run_id_), "%s-" OS_NAME "-%d-%lu", hostname, most_recent_pid_, time(NULL)); - memory_residence_info_getter_->Initialize(); + if (memory_residence_info_getter_) + memory_residence_info_getter_->Initialize(); deep_table_.ResetIsLogged(); // Write maps into "|filename_prefix_|.<pid>.maps". @@ -377,7 +406,7 @@ void DeepHeapProfile::DumpOrderedProfile(const char* reason, buffer.AppendChar('\n'); // Assumes the physical memory <= 64GB (PFN < 2^24). - if (pageframe_type_ == DUMP_PAGECOUNT && + if (pageframe_type_ == DUMP_PAGECOUNT && memory_residence_info_getter_ && memory_residence_info_getter_->IsPageCountAvailable()) { buffer.AppendString("PageFrame: 24,Base64,PageCount", 0); buffer.AppendChar('\n'); @@ -739,11 +768,12 @@ uint64 DeepHeapProfile::RegionStats::Record( uint64 first_address, uint64 last_address, TextBuffer* buffer) { - uint64 committed; + uint64 committed = 0; virtual_bytes_ += static_cast<size_t>(last_address - first_address + 1); - committed = memory_residence_info_getter->CommittedSize(first_address, - last_address, - buffer); + if (memory_residence_info_getter) + committed = memory_residence_info_getter->CommittedSize(first_address, + last_address, + buffer); committed_bytes_ += committed; return committed; } @@ -758,7 +788,7 @@ void DeepHeapProfile::RegionStats::Unparse(const char* name, buffer->AppendString("\n", 0); } -// Snapshots all virtual memory mappging stats by merging mmap(2) records from +// Snapshots all virtual memory mapping stats by merging mmap(2) records from // MemoryRegionMap and /proc/maps, the OS-level memory mapping information. // Memory regions described in /proc/maps, but which are not created by mmap, // are accounted as "unhooked" memory regions. @@ -795,6 +825,7 @@ void DeepHeapProfile::GlobalStats::SnapshotMaps( char* flags; char* filename; enum MapsRegionType type; + for (int i = 0; i < NUMBER_OF_MAPS_REGION_TYPES; ++i) { all_[i].Initialize(); unhooked_[i].Initialize(); @@ -915,8 +946,10 @@ void DeepHeapProfile::GlobalStats::SnapshotMaps( partial_last_address = vma_last_addr; else partial_last_address = mmap_iter->end_addr - 1; - uint64 committed_size = memory_residence_info_getter->CommittedSize( - partial_first_address, partial_last_address, mmap_dump_buffer); + uint64 committed_size = 0; + if (memory_residence_info_getter) + committed_size = memory_residence_info_getter->CommittedSize( + partial_first_address, partial_last_address, mmap_dump_buffer); vma_subtotal += committed_size; mmap_dump_buffer->AppendString(trailing ? " (" : " ", 0); mmap_dump_buffer->AppendPtr(mmap_iter->start_addr, 0); diff --git a/third_party/tcmalloc/chromium/src/deep-heap-profile.h b/third_party/tcmalloc/chromium/src/deep-heap-profile.h index c2ee897..0544b31 100644 --- a/third_party/tcmalloc/chromium/src/deep-heap-profile.h +++ b/third_party/tcmalloc/chromium/src/deep-heap-profile.h @@ -36,7 +36,7 @@ #include <typeinfo> #endif -#if defined(__linux__) +#if defined(__linux__) || defined(_WIN32) || defined(_WIN64) #define USE_DEEP_HEAP_PROFILE 1 #endif @@ -166,6 +166,23 @@ class DeepHeapProfile { MemoryResidenceInfoGetterInterface(); }; +#if defined(_WIN32) || defined(_WIN64) + // TODO(peria): Implement this class. + class MemoryInfoGetterWindows : public MemoryResidenceInfoGetterInterface { + public: + MemoryInfoGetterWindows(PageFrameType) {} + virtual ~MemoryInfoGetterWindows() {} + + virtual void Initialize(); + + virtual size_t CommittedSize(uint64 first_address, + uint64 last_address, + TextBuffer* buffer) const; + + virtual bool IsPageCountAvailable() const; + }; +#endif // defined(_WIN32) || defined(_WIN64) + #if defined(__linux__) // Implements MemoryResidenceInfoGetterInterface for Linux. class MemoryInfoGetterLinux : public MemoryResidenceInfoGetterInterface { diff --git a/third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h b/third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h index c2f1699..49c78fe 100644 --- a/third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h +++ b/third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h @@ -61,6 +61,13 @@ # endif #endif +// Make the linker NOT to strip functions in this file. +#if defined(_WIN64) +#pragma comment(linker, "/INCLUDE:HeapProfilerStart") +#elif defined(_WIN32) +#pragma comment(linker, "/INCLUDE:_HeapProfilerStart") +#endif + /* All this code should be usable from within C apps. */ #ifdef __cplusplus extern "C" { diff --git a/third_party/tcmalloc/chromium/src/heap-profile-table.cc b/third_party/tcmalloc/chromium/src/heap-profile-table.cc index bcf8edd..c5c1db7 100644 --- a/third_party/tcmalloc/chromium/src/heap-profile-table.cc +++ b/third_party/tcmalloc/chromium/src/heap-profile-table.cc @@ -103,7 +103,10 @@ const char HeapProfileTable::kFileExt[] = ".heap"; //---------------------------------------------------------------------- static const int kHashTableSize = 179999; // Size for bucket_table_. +// GCC requires this declaration, but MSVC does not allow it. +#if !defined(COMPILER_MSVC) /*static*/ const int HeapProfileTable::kMaxStackDepth; +#endif //---------------------------------------------------------------------- |