OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // --- | 5 // --- |
6 // Author: Sainbayar Sukhbaatar | 6 // Author: Sainbayar Sukhbaatar |
7 // Dai Mikurube | 7 // Dai Mikurube |
8 // | 8 // |
9 | 9 |
10 #include "deep-heap-profile.h" | 10 #include "deep-heap-profile.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 pagemap_fd_ = OpenProcPagemap(); | 83 pagemap_fd_ = OpenProcPagemap(); |
84 | 84 |
85 for (int i = 0; i < kHashTableSize; i++) { | 85 for (int i = 0; i < kHashTableSize; i++) { |
86 for (DeepBucket* deep_bucket = deep_table_[i]; | 86 for (DeepBucket* deep_bucket = deep_table_[i]; |
87 deep_bucket != NULL; | 87 deep_bucket != NULL; |
88 deep_bucket = deep_bucket->next) { | 88 deep_bucket = deep_bucket->next) { |
89 deep_bucket->is_logged = false; | 89 deep_bucket->is_logged = false; |
90 } | 90 } |
91 } | 91 } |
92 | 92 |
93 // Write maps into a .maps file with using the global buffer. | 93 // Write maps into "|filename_prefix|.<pid>.maps" using global buffer. |
94 WriteMapsToFile(filename_prefix_, kProfilerBufferSize, profiler_buffer_); | 94 WriteMapsToFile(filename_prefix_, 0, |
| 95 kProfilerBufferSize, profiler_buffer_); |
95 } | 96 } |
| 97 // Write maps into "|filename_prefix|.<pid>.|count|.maps" using global buffer. |
| 98 WriteMapsToFile(filename_prefix_, dump_count_, |
| 99 kProfilerBufferSize, profiler_buffer_); |
96 | 100 |
97 // Reset committed sizes of buckets. | 101 // Reset committed sizes of buckets. |
98 ResetCommittedSize(deep_table_); | 102 ResetCommittedSize(deep_table_); |
99 | 103 |
100 // Allocate a list for mmap'ed regions. | 104 // Allocate a list for mmap'ed regions. |
101 num_mmap_allocations_ = 0; | 105 num_mmap_allocations_ = 0; |
102 heap_profile_->mmap_address_map_->Iterate(CountMMap, this); | 106 heap_profile_->mmap_address_map_->Iterate(CountMMap, this); |
103 mmap_list_length_ = 0; | 107 mmap_list_length_ = 0; |
104 mmap_list_ = reinterpret_cast<MMapListEntry*>(heap_profile_->alloc_( | 108 mmap_list_ = reinterpret_cast<MMapListEntry*>(heap_profile_->alloc_( |
105 sizeof(MMapListEntry) * num_mmap_allocations_)); | 109 sizeof(MMapListEntry) * num_mmap_allocations_)); |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 break; | 320 break; |
317 } | 321 } |
318 page_address += page_size; | 322 page_address += page_size; |
319 } | 323 } |
320 | 324 |
321 return committed_size; | 325 return committed_size; |
322 } | 326 } |
323 | 327 |
324 // static | 328 // static |
325 void DeepHeapProfile::WriteMapsToFile(const char* filename_prefix, | 329 void DeepHeapProfile::WriteMapsToFile(const char* filename_prefix, |
| 330 unsigned count, |
326 int buffer_size, | 331 int buffer_size, |
327 char buffer[]) { | 332 char buffer[]) { |
328 char filename[100]; | 333 char filename[100]; |
329 snprintf(filename, sizeof(filename), | 334 if (count > 0) { |
330 "%s.%05d.maps", filename_prefix, static_cast<int>(getpid())); | 335 snprintf(filename, sizeof(filename), |
| 336 "%s.%05d.%04d.maps", filename_prefix, static_cast<int>(getpid()), |
| 337 count); |
| 338 } else { |
| 339 snprintf(filename, sizeof(filename), |
| 340 "%s.%05d.maps", filename_prefix, static_cast<int>(getpid())); |
| 341 } |
331 | 342 |
332 RawFD maps_fd = RawOpenForWriting(filename); | 343 RawFD maps_fd = RawOpenForWriting(filename); |
333 RAW_DCHECK(maps_fd != kIllegalRawFD, ""); | 344 RAW_DCHECK(maps_fd != kIllegalRawFD, ""); |
334 | 345 |
335 int map_length; | 346 int map_length; |
336 bool wrote_all; | 347 bool wrote_all; |
337 map_length = tcmalloc::FillProcSelfMaps(buffer, buffer_size, &wrote_all); | 348 map_length = tcmalloc::FillProcSelfMaps(buffer, buffer_size, &wrote_all); |
338 RAW_DCHECK(wrote_all, ""); | 349 RAW_DCHECK(wrote_all, ""); |
339 RAW_DCHECK(map_length <= buffer_size, ""); | 350 RAW_DCHECK(map_length <= buffer_size, ""); |
340 RawWrite(maps_fd, buffer, map_length); | 351 RawWrite(maps_fd, buffer, map_length); |
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 } | 818 } |
808 | 819 |
809 DeepHeapProfile::~DeepHeapProfile() { | 820 DeepHeapProfile::~DeepHeapProfile() { |
810 } | 821 } |
811 | 822 |
812 int DeepHeapProfile::FillOrderedProfile(char buffer[], int buffer_size) { | 823 int DeepHeapProfile::FillOrderedProfile(char buffer[], int buffer_size) { |
813 return heap_profile_->FillOrderedProfile(buffer, buffer_size); | 824 return heap_profile_->FillOrderedProfile(buffer, buffer_size); |
814 } | 825 } |
815 | 826 |
816 #endif // DEEP_HEAP_PROFILE | 827 #endif // DEEP_HEAP_PROFILE |
OLD | NEW |