OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef BASE_DEEP_HEAP_PROFILE_H_ |
| 6 #define BASE_DEEP_HEAP_PROFILE_H_ |
| 7 |
| 8 #include <config.h> |
| 9 |
| 10 #if defined(__linux__) |
| 11 #define DEEP_HEAP_PROFILE 1 |
| 12 #endif |
| 13 |
| 14 #include "addressmap-inl.h" |
| 15 #include "heap-profile-table.h" |
| 16 |
| 17 class DeepHeapProfile { |
| 18 public: |
| 19 typedef HeapProfileTable::Bucket Bucket; |
| 20 typedef HeapProfileTable::AllocationMap AllocationMap; |
| 21 typedef HeapProfileTable::AllocValue AllocValue; |
| 22 typedef HeapProfileTable::Stats Stats; |
| 23 |
| 24 DeepHeapProfile(HeapProfileTable* heap_profile, const char* prefix); |
| 25 ~DeepHeapProfile(); |
| 26 |
| 27 // This replaces the same function in heap-profile-table.h |
| 28 int FillOrderedProfile(char buf[], int size); |
| 29 |
| 30 private: |
| 31 #ifdef DEEP_HEAP_PROFILE |
| 32 struct DeepBucket { |
| 33 Bucket* bucket; |
| 34 int64 committed_size; |
| 35 int id; // Unique ID of the bucket |
| 36 bool is_logged; // True if the stracktrace is logged to a file |
| 37 }; |
| 38 |
| 39 typedef AddressMap<DeepBucket> DeepBucketMap; |
| 40 |
| 41 struct PageState { |
| 42 bool is_committed; // Currently, we use only this |
| 43 bool is_present; |
| 44 bool is_swapped; |
| 45 bool is_shared; |
| 46 bool is_mmap; |
| 47 }; |
| 48 |
| 49 typedef AddressMap<PageState> PageStateMap; |
| 50 |
| 51 // This represents a single line of /proc/self/maps |
| 52 struct RegionValue { |
| 53 uint64 start; |
| 54 uint64 end; |
| 55 uint64 size; |
| 56 uint64 committed_size; |
| 57 uint64 recorded_size; |
| 58 uint64 recorded_committed_size; |
| 59 char permissions[5]; |
| 60 char filename[1000]; |
| 61 }; |
| 62 |
| 63 typedef AddressMap<RegionValue> RegionMap; |
| 64 |
| 65 struct RegionStats { |
| 66 int64 virtual_bytes; |
| 67 int64 committed_bytes; |
| 68 }; |
| 69 |
| 70 struct GlobalStats { |
| 71 RegionStats total; |
| 72 RegionStats file_mapped; |
| 73 RegionStats anonymous; |
| 74 RegionStats other; |
| 75 RegionStats record_mmap; |
| 76 RegionStats record_tcmalloc; |
| 77 }; |
| 78 |
| 79 struct BufferArgs { |
| 80 char* buf; |
| 81 int size; |
| 82 int len; |
| 83 }; |
| 84 |
| 85 DeepBucket* GetDeepBucket(Bucket* bucket); |
| 86 void ResetCommittedSize(Bucket** table); |
| 87 int FillBucketTable(Bucket** table, char buf[], int size, int bucket_length, |
| 88 HeapProfileTable::Stats* stats); |
| 89 |
| 90 // Functions for opening, seeking, reading /proc/pid/pagemap |
| 91 void OpenProcPagemap(); |
| 92 bool SeekProcPagemap(uint64 addr); |
| 93 bool ReadProcPagemap(PageState* state); |
| 94 uint64 GetCommittedSize(uint64 addr, uint64 size); |
| 95 |
| 96 void InitRegionStats(RegionStats* stats); |
| 97 void RecordRegionStats(uint64 start, uint64 end, RegionStats* stats); |
| 98 void GetGlobalStats(); |
| 99 static size_t GetRegionSize(const RegionValue& rv) { return rv.size; } |
| 100 |
| 101 // Record the committed memory size of each allocations |
| 102 static void RecordAlloc(const void* ptr, AllocValue* v, |
| 103 DeepHeapProfile* deep_profile); |
| 104 static void RecordMMap(const void* ptr, AllocValue* v, |
| 105 DeepHeapProfile* deep_profile); |
| 106 void RecordAllAllocs(); |
| 107 |
| 108 void WriteMapsToFile(char buf[], int size); |
| 109 |
| 110 int FillBucketForBucketFile(const DeepBucket* db, char buf[], int bufsize); |
| 111 void WriteBucketsTableToBucketFile(Bucket** table, RawFD bucket_fd); |
| 112 void WriteBucketsToBucketFile(); |
| 113 |
| 114 static int UnparseBucket(const DeepBucket& b, |
| 115 char* buf, int buflen, int bufsize, |
| 116 const char* extra, |
| 117 Stats* profile_stats); |
| 118 |
| 119 static int UnparseRegionStats(const RegionStats* stats, const char* name, |
| 120 char* buf, int buflen, int bufsize); |
| 121 |
| 122 int UnparseGlobalStats(char* buf, int buflen, int bufsize); |
| 123 |
| 124 #endif // DEEP_HEAP_PROFILE |
| 125 HeapProfileTable* heap_profile_; |
| 126 #ifdef DEEP_HEAP_PROFILE |
| 127 |
| 128 int pagemap_fd_; // File descriptor of /proc/self/pagemap |
| 129 pid_t most_recent_pid_; // Process ID of the last dump. This could change. |
| 130 GlobalStats stats_; // Stats about total memory |
| 131 PageStateMap* page_map_; // Map for holding status of allocations in page |
| 132 int dump_count_; // The number of dumps |
| 133 char* filename_prefix_; // Output file prefix |
| 134 char* profiler_buffer_; // Buffer we use many times |
| 135 |
| 136 int bucket_id_; |
| 137 DeepBucketMap* deep_bucket_map_; |
| 138 #endif // DEEP_HEAP_PROFILE |
| 139 }; |
| 140 |
| 141 #endif // BASE_DEEP_HEAP_PROFILE_H_ |
OLD | NEW |