Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1086)

Side by Side Diff: third_party/tcmalloc/chromium/src/deep-heap-profile.h

Issue 8632007: A deeper heap profile dumper in third_party/tcmalloc/chromium. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Reflected the comments. Created 8 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 // ---
6 // Author: Sainbayar Sukhbaatar
7 // Dai Mikurube
8 //
9 // This file contains a class DeepHeapProfile and its public function
10 // DeepHeapProfile::FillOrderedProfile() which works as an alternative of
11 // HeapProfileTable::FillOrderedProfile().
12 //
13 // DeepHeapProfile::FillOrderedProfile() dumps more detailed information about
14 // heap usage, which includes OS-level information such as whether the memory
15 // 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.
16 // 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.
17 // DeepHeapProfile works only when its FillOrderedProfile() is called. It has
18 // overhead when dumping, but no overhead when logging.
19 //
20 // It currently works only on Linux. It just delegates to HeapProfileTable in
21 // non-Linux environments.
22
23
24 #ifndef BASE_DEEP_HEAP_PROFILE_H_
25 #define BASE_DEEP_HEAP_PROFILE_H_
26
27 #include "config.h"
28
29 #if defined(__linux__)
30 #define DEEP_HEAP_PROFILE 1
31 #endif
32
33 #include "addressmap-inl.h"
34 #include "heap-profile-table.h"
35
36 class DeepHeapProfile {
37 public:
38 typedef HeapProfileTable::Bucket Bucket;
39 typedef HeapProfileTable::AllocationMap AllocationMap;
40 typedef HeapProfileTable::AllocValue AllocValue;
41 typedef HeapProfileTable::Stats Stats;
42
43 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.
44 ~DeepHeapProfile();
45
46 // 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.
47 int FillOrderedProfile(char buf[], int size);
48
49 private:
50 #ifdef DEEP_HEAP_PROFILE
51 struct DeepBucket {
52 Bucket* bucket;
53 size_t committed_size;
54 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.
55 bool is_logged; // True if the stracktrace is logged to a file
56 };
57
58 typedef AddressMap<DeepBucket> DeepBucketMap;
59
60 struct PageState {
61 bool is_committed; // Currently, we use only this
62 bool is_present;
63 bool is_swapped;
64 bool is_shared;
65 bool is_mmap;
66 };
67
68 struct RegionStats {
69 size_t virtual_bytes;
70 size_t committed_bytes;
71 };
72
73 struct GlobalStats {
74 RegionStats total;
75 RegionStats file_mapped;
76 RegionStats anonymous;
77 RegionStats other;
78 RegionStats record_mmap;
79 RegionStats record_tcmalloc;
80 };
81
82 struct BufferArgs {
83 char* buf;
84 int size;
85 int len;
86 };
87
88 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.
89 void ResetCommittedSize(Bucket** table);
90 int FillBucketTable(Bucket** table, char buf[], int size, int bucket_length,
91 HeapProfileTable::Stats* stats);
92
93 // Functions for opening, seeking, reading /proc/pid/pagemap
94 void OpenProcPagemap();
95 bool SeekProcPagemap(uint64 addr);
96 bool ReadProcPagemap(PageState* state);
97 size_t GetCommittedSize(uint64 addr, size_t size);
98
99 void InitRegionStats(RegionStats* stats);
100 void RecordRegionStats(uint64 start, uint64 end, RegionStats* stats);
101 void GetGlobalStats();
102
103 // Record the committed memory size of each allocations
104 static void RecordAlloc(const void* ptr, AllocValue* v,
105 DeepHeapProfile* deep_profile);
106 static void RecordMMap(const void* ptr, AllocValue* v,
107 DeepHeapProfile* deep_profile);
108 void RecordAllAllocs();
109
110 void WriteMapsToFile(char buf[], int size);
111
112 int FillBucketForBucketFile(const DeepBucket* db, char buf[], int bufsize);
113 void WriteBucketsTableToBucketFile(Bucket** table, RawFD bucket_fd);
114 void WriteBucketsToBucketFile();
115
116 static int UnparseBucket(const DeepBucket& b,
117 char* buf, int buflen, int bufsize,
118 const char* extra,
119 Stats* profile_stats);
120
121 static int UnparseRegionStats(const RegionStats* stats, const char* name,
122 char* buf, int buflen, int bufsize);
123
124 int UnparseGlobalStats(char* buf, int buflen, int bufsize);
125
126 #endif // DEEP_HEAP_PROFILE
127 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
128 #ifdef DEEP_HEAP_PROFILE
129
130 int pagemap_fd_; // File descriptor of /proc/self/pagemap
131 pid_t most_recent_pid_; // Process ID of the last dump. This could change.
132 GlobalStats stats_; // Stats about total memory
133 int dump_count_; // The number of dumps
134 char* filename_prefix_; // Output file prefix
135 char* profiler_buffer_; // Buffer we use many times
136
137 int bucket_id_;
138 DeepBucketMap* deep_bucket_map_;
139 #endif // DEEP_HEAP_PROFILE
140 };
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.
141
142 #endif // BASE_DEEP_HEAP_PROFILE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698