Index: third_party/tcmalloc/chromium/src/deep-memory-profiler.h |
diff --git a/third_party/tcmalloc/chromium/src/deep-memory-profiler.h b/third_party/tcmalloc/chromium/src/deep-memory-profiler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b8d6bf99829d0612df1b1f235bc2abca76d5c83d |
--- /dev/null |
+++ b/third_party/tcmalloc/chromium/src/deep-memory-profiler.h |
@@ -0,0 +1,118 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+#ifndef BASE_DEEP_MEMORY_PROFILER_H_ |
+#define BASE_DEEP_MEMORY_PROFILER_H_ |
+ |
+#include "addressmap-inl.h" |
+#include "heap-profile-table.h" |
+ |
+class DeepMemoryProfiler { |
+public: |
+ typedef HeapProfileTable::Bucket Bucket; |
+ typedef HeapProfileTable::AllocationMap AllocationMap; |
+ typedef HeapProfileTable::AllocValue AllocValue; |
+ typedef HeapProfileTable::Stats Stats; |
+ |
+ DeepMemoryProfiler(HeapProfileTable* heap_profile, const char* prefix); |
+ ~DeepMemoryProfiler(); |
+ |
+ // This replaces the same function in heap-profile-table.h |
+ int FillOrderedProfile(char buf[], int size); |
+private: |
+ struct PageState { |
+ bool is_committed; // Currently, we use only this |
+ bool is_present; |
+ bool is_swapped; |
+ bool is_shared; |
+ bool is_mmap; |
+ }; |
+ |
+ typedef AddressMap<PageState> PageStateMap; |
+ |
+ // Functions for opening, seeking, reading /proc/pid/pagemap |
+ void OpenPageMap(); |
+ bool PageMapSeek(uint64 addr); |
+ bool PageMapRead(PageState* state); |
+ uint64 GetCommittedSize(uint64 addr, uint64 size); |
+ |
+ // This represents a single line of /proc/self/maps |
+ struct RegionValue { |
+ uint64 start; |
+ uint64 end; |
+ uint64 size; |
+ uint64 committed_size; |
+ uint64 recorded_size; |
+ uint64 recorded_committed_size; |
+ char permissions[5]; |
+ char filename[1000]; |
+ }; |
+ |
+ typedef AddressMap<RegionValue> RegionMap; |
+ RegionMap* regions_; // Map of all regions |
+ uint64 max_region_size_; // Max size of regions |
+ |
+ struct RegionStats { |
+ int64 virtual_bytes; |
+ int64 committed_bytes; |
+ }; |
+ |
+ struct GlobalStats { |
+ RegionStats total; |
+ RegionStats file_mapped; |
+ RegionStats anonymous; |
+ RegionStats other; |
+ RegionStats record_mmap; |
+ RegionStats record_tcmalloc; |
+ }; |
+ |
+ void InitRegionStats(RegionStats* stats); |
+ void RecordRegionStats(uint64 start, uint64 end, RegionStats* stats); |
+ void GetGlobalStats(); |
+ static size_t GetRegionSize(const RegionValue& rv) { return rv.size; } |
+ void RecordAllocInRegions(uint64 addr, uint64 size); |
+ |
+ // Record the committed memory size of each allocations |
+ static void RecordAlloc(const void* ptr, AllocValue* v, |
+ DeepMemoryProfiler* deep_profiler); |
+ void RecordAllAllocs(); |
+ |
+ struct BufferArgs { |
+ char* buf; |
+ int size; |
+ int len; |
+ }; |
+ |
+ static void WriteLeakyRegion(const void* ptr, |
+ RegionValue* rv, |
+ BufferArgs* buffer); |
+ void WriteAllLeakyRegions(); |
+ |
+ void WriteMapsToFile(char buf[], int size); |
+ int WriteBucket(const Bucket* b, char buf[], int bufsize); |
+ void WriteBucketsToFile(); |
+ |
+ static int UnparseBucket(const Bucket& b, |
+ char* buf, int buflen, int bufsize, |
+ const char* extra, |
+ Stats* profile_stats); |
+ |
+ static int UnparseRegionStats(const RegionStats* stats, const char* name, |
+ char* buf, int buflen, int bufsize); |
+ |
+ int UnparseGlobalStats(char* buf, int buflen, int bufsize); |
+ |
+ HeapProfileTable* heap_profile_; |
+ |
+ int pagemap_fd_; // File descriptor of /proc/self/pagemap |
+ int kpageflags_fd_; // File descriptor of /proc/kpageflags |
+ pid_t most_recent_pid_; // Process ID of the last dump. This could change. |
+ GlobalStats stats_; // Stats about total memory |
+ PageStateMap* page_map_; // Map for holding status of allocations in page |
+ int dump_count_; // The number of dumps |
+ char* filename_prefix_; // Output file prefix |
+ char* profiler_buffer_; // Buffer we use many times |
+ bool recording_mmap_; // True if we are recording mmap, not tcmalloc |
+}; |
+ |
+#endif // BASE_DEEP_MEMORY_PROFILER_H_ |