Chromium Code Reviews| Index: third_party/tcmalloc/chromium/src/deep-heap-profile.h |
| diff --git a/third_party/tcmalloc/chromium/src/deep-heap-profile.h b/third_party/tcmalloc/chromium/src/deep-heap-profile.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ba1d65f92e7c4060c026597c577d9067563f3245 |
| --- /dev/null |
| +++ b/third_party/tcmalloc/chromium/src/deep-heap-profile.h |
| @@ -0,0 +1,142 @@ |
| +// 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. |
| + |
| +// --- |
| +// Author: Sainbayar Sukhbaatar |
| +// Dai Mikurube |
| +// |
| +// This file contains a class DeepHeapProfile and its public function |
| +// DeepHeapProfile::FillOrderedProfile() which works as an alternative of |
| +// HeapProfileTable::FillOrderedProfile(). |
| +// |
| +// DeepHeapProfile::FillOrderedProfile() dumps more detailed information about |
| +// heap usage, which includes OS-level information such as whether the memory |
| +// block is actually on memory, or not. DeepHeapProfile::FillOrderedProfile() |
|
jar (doing other things)
2011/12/28 08:30:17
nit: "on memory" --> "in memory" (??)
Dai Mikurube (NOT FULLTIME)
2012/01/06 01:25:23
Done.
|
| +// uses logged data in HeapProfileTable as one of its data source. |
|
jar (doing other things)
2011/12/28 08:30:17
nit: "...one of its data source" --> "...one of it
Dai Mikurube (NOT FULLTIME)
2012/01/06 01:25:23
Done.
|
| +// DeepHeapProfile works only when its FillOrderedProfile() is called. It has |
| +// overhead when dumping, but no overhead when logging. |
| +// |
| +// It currently works only on Linux. It just delegates to HeapProfileTable in |
| +// non-Linux environments. |
| + |
| + |
| +#ifndef BASE_DEEP_HEAP_PROFILE_H_ |
| +#define BASE_DEEP_HEAP_PROFILE_H_ |
| + |
| +#include "config.h" |
| + |
| +#if defined(__linux__) |
| +#define DEEP_HEAP_PROFILE 1 |
| +#endif |
| + |
| +#include "addressmap-inl.h" |
| +#include "heap-profile-table.h" |
| + |
| +class DeepHeapProfile { |
| + public: |
| + typedef HeapProfileTable::Bucket Bucket; |
| + typedef HeapProfileTable::AllocationMap AllocationMap; |
| + typedef HeapProfileTable::AllocValue AllocValue; |
| + typedef HeapProfileTable::Stats Stats; |
| + |
| + DeepHeapProfile(HeapProfileTable* heap_profile, const char* prefix); |
|
jar (doing other things)
2011/12/28 08:30:17
Please add comments indicating what the function d
Dai Mikurube (NOT FULLTIME)
2012/01/06 01:25:23
Done.
|
| + ~DeepHeapProfile(); |
| + |
| + // This replaces the same function in heap-profile-table.h |
|
jar (doing other things)
2011/12/28 08:30:17
That is a fine secondary comment... but it is bett
Dai Mikurube (NOT FULLTIME)
2012/01/06 01:25:23
Done.
|
| + int FillOrderedProfile(char buf[], int size); |
| + |
| + private: |
| +#ifdef DEEP_HEAP_PROFILE |
| + struct DeepBucket { |
| + Bucket* bucket; |
| + size_t committed_size; |
| + int id; // Unique ID of the bucket |
|
jar (doing other things)
2011/12/28 08:30:17
nit: Comments should end with a period.
Please co
Dai Mikurube (NOT FULLTIME)
2012/01/06 01:25:23
Done.
|
| + bool is_logged; // True if the stracktrace is logged to a file |
| + }; |
| + |
| + typedef AddressMap<DeepBucket> DeepBucketMap; |
| + |
| + struct PageState { |
| + bool is_committed; // Currently, we use only this |
| + bool is_present; |
| + bool is_swapped; |
| + bool is_shared; |
| + bool is_mmap; |
| + }; |
| + |
| + struct RegionStats { |
| + size_t virtual_bytes; |
| + size_t committed_bytes; |
| + }; |
| + |
| + struct GlobalStats { |
| + RegionStats total; |
| + RegionStats file_mapped; |
| + RegionStats anonymous; |
| + RegionStats other; |
| + RegionStats record_mmap; |
| + RegionStats record_tcmalloc; |
| + }; |
| + |
| + struct BufferArgs { |
| + char* buf; |
| + int size; |
| + int len; |
| + }; |
| + |
| + DeepBucket* GetDeepBucket(Bucket* bucket); |
|
jar (doing other things)
2011/12/28 08:30:17
nit: All these functions should have comments.
Dai Mikurube (NOT FULLTIME)
2012/01/06 01:25:23
Done.
|
| + void ResetCommittedSize(Bucket** table); |
| + int FillBucketTable(Bucket** table, char buf[], int size, int bucket_length, |
| + HeapProfileTable::Stats* stats); |
| + |
| + // Functions for opening, seeking, reading /proc/pid/pagemap |
| + void OpenProcPagemap(); |
| + bool SeekProcPagemap(uint64 addr); |
| + bool ReadProcPagemap(PageState* state); |
| + size_t GetCommittedSize(uint64 addr, size_t size); |
| + |
| + void InitRegionStats(RegionStats* stats); |
| + void RecordRegionStats(uint64 start, uint64 end, RegionStats* stats); |
| + void GetGlobalStats(); |
| + |
| + // Record the committed memory size of each allocations |
| + static void RecordAlloc(const void* ptr, AllocValue* v, |
| + DeepHeapProfile* deep_profile); |
| + static void RecordMMap(const void* ptr, AllocValue* v, |
| + DeepHeapProfile* deep_profile); |
| + void RecordAllAllocs(); |
| + |
| + void WriteMapsToFile(char buf[], int size); |
| + |
| + int FillBucketForBucketFile(const DeepBucket* db, char buf[], int bufsize); |
| + void WriteBucketsTableToBucketFile(Bucket** table, RawFD bucket_fd); |
| + void WriteBucketsToBucketFile(); |
| + |
| + static int UnparseBucket(const DeepBucket& 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); |
| + |
| +#endif // DEEP_HEAP_PROFILE |
| + HeapProfileTable* heap_profile_; |
|
jar (doing other things)
2011/12/28 08:30:17
Why isn't this line inside the ifdef?
Dai Mikurube (NOT FULLTIME)
2012/01/06 01:25:23
It is used to delegate calling of FillOrderedProfi
jar (doing other things)
2012/01/06 03:05:10
nit: OK... so if you don't want it in the ifdef, h
Dai Mikurube (NOT FULLTIME)
2012/01/30 12:54:53
Sorry, I overlooked this comment. Done it.
On 20
|
| +#ifdef DEEP_HEAP_PROFILE |
| + |
| + int pagemap_fd_; // File descriptor of /proc/self/pagemap |
| + pid_t most_recent_pid_; // Process ID of the last dump. This could change. |
| + GlobalStats stats_; // Stats about total memory |
| + int dump_count_; // The number of dumps |
| + char* filename_prefix_; // Output file prefix |
| + char* profiler_buffer_; // Buffer we use many times |
| + |
| + int bucket_id_; |
| + DeepBucketMap* deep_bucket_map_; |
| +#endif // DEEP_HEAP_PROFILE |
| +}; |
|
jar (doing other things)
2011/12/28 08:30:17
Why doesn't this class have the unsafe copy and co
Dai Mikurube (NOT FULLTIME)
2012/01/06 01:25:23
Ah, I forgot or deleted it wrongly before. Added.
|
| + |
| +#endif // BASE_DEEP_HEAP_PROFILE_H_ |