OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #include "base/trace_event/heap_profiler_heap_dump_writer.h" | 5 #include "base/trace_event/heap_profiler_heap_dump_writer.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <iterator> | 10 #include <iterator> |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 // Comparison operator to order buckets by their size. | 71 // Comparison operator to order buckets by their size. |
72 bool operator<(const Bucket& lhs, const Bucket& rhs) { | 72 bool operator<(const Bucket& lhs, const Bucket& rhs) { |
73 return lhs.size < rhs.size; | 73 return lhs.size < rhs.size; |
74 } | 74 } |
75 | 75 |
76 // Groups the allocations in the bucket by |break_by|. The buckets in the | 76 // Groups the allocations in the bucket by |break_by|. The buckets in the |
77 // returned list will have |backtrace_cursor| advanced or | 77 // returned list will have |backtrace_cursor| advanced or |
78 // |is_broken_down_by_type_name| set depending on the property to group by. | 78 // |is_broken_down_by_type_name| set depending on the property to group by. |
79 std::vector<Bucket> GetSubbuckets(const Bucket& bucket, | 79 std::vector<Bucket> GetSubbuckets(const Bucket& bucket, |
80 BreakDownMode break_by) { | 80 BreakDownMode break_by) { |
81 base::hash_map<const void*, Bucket> breakdown; | 81 std::unordered_map<const void*, Bucket> breakdown; |
82 | |
83 | 82 |
84 if (break_by == BreakDownMode::kByBacktrace) { | 83 if (break_by == BreakDownMode::kByBacktrace) { |
85 for (const auto& context_and_metrics : bucket.metrics_by_context) { | 84 for (const auto& context_and_metrics : bucket.metrics_by_context) { |
86 const Backtrace& backtrace = context_and_metrics.first->backtrace; | 85 const Backtrace& backtrace = context_and_metrics.first->backtrace; |
87 const StackFrame* begin = std::begin(backtrace.frames); | 86 const StackFrame* begin = std::begin(backtrace.frames); |
88 const StackFrame* end = begin + backtrace.frame_count; | 87 const StackFrame* end = begin + backtrace.frame_count; |
89 const StackFrame* cursor = begin + bucket.backtrace_cursor; | 88 const StackFrame* cursor = begin + bucket.backtrace_cursor; |
90 | 89 |
91 DCHECK_LE(cursor, end); | 90 DCHECK_LE(cursor, end); |
92 | 91 |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 for (const Bucket& subbucket : by_backtrace) | 233 for (const Bucket& subbucket : by_backtrace) |
235 if (AddEntryForBucket(subbucket)) | 234 if (AddEntryForBucket(subbucket)) |
236 BreakDown(subbucket); | 235 BreakDown(subbucket); |
237 | 236 |
238 for (const Bucket& subbucket : by_type_name) | 237 for (const Bucket& subbucket : by_type_name) |
239 if (AddEntryForBucket(subbucket)) | 238 if (AddEntryForBucket(subbucket)) |
240 BreakDown(subbucket); | 239 BreakDown(subbucket); |
241 } | 240 } |
242 | 241 |
243 const std::set<Entry>& HeapDumpWriter::Summarize( | 242 const std::set<Entry>& HeapDumpWriter::Summarize( |
244 const hash_map<AllocationContext, AllocationMetrics>& metrics_by_context) { | 243 const std::unordered_map<AllocationContext, AllocationMetrics>& |
| 244 metrics_by_context) { |
245 // Start with one bucket that represents the entire heap. Iterate by | 245 // Start with one bucket that represents the entire heap. Iterate by |
246 // reference, because the allocation contexts are going to point to allocation | 246 // reference, because the allocation contexts are going to point to allocation |
247 // contexts stored in |metrics_by_context|. | 247 // contexts stored in |metrics_by_context|. |
248 Bucket root_bucket; | 248 Bucket root_bucket; |
249 for (const auto& context_and_metrics : metrics_by_context) { | 249 for (const auto& context_and_metrics : metrics_by_context) { |
250 DCHECK_GT(context_and_metrics.second.size, 0u); | 250 DCHECK_GT(context_and_metrics.second.size, 0u); |
251 DCHECK_GT(context_and_metrics.second.count, 0u); | 251 DCHECK_GT(context_and_metrics.second.count, 0u); |
252 const AllocationContext* context = &context_and_metrics.first; | 252 const AllocationContext* context = &context_and_metrics.first; |
253 root_bucket.metrics_by_context.push_back( | 253 root_bucket.metrics_by_context.push_back( |
254 std::make_pair(context, context_and_metrics.second)); | 254 std::make_pair(context, context_and_metrics.second)); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 traced_value->EndDictionary(); | 302 traced_value->EndDictionary(); |
303 } | 303 } |
304 | 304 |
305 traced_value->EndArray(); // "entries" | 305 traced_value->EndArray(); // "entries" |
306 return traced_value; | 306 return traced_value; |
307 } | 307 } |
308 | 308 |
309 } // namespace internal | 309 } // namespace internal |
310 | 310 |
311 std::unique_ptr<TracedValue> ExportHeapDump( | 311 std::unique_ptr<TracedValue> ExportHeapDump( |
312 const hash_map<AllocationContext, AllocationMetrics>& metrics_by_context, | 312 const std::unordered_map<AllocationContext, AllocationMetrics>& |
| 313 metrics_by_context, |
313 const MemoryDumpSessionState& session_state) { | 314 const MemoryDumpSessionState& session_state) { |
314 internal::HeapDumpWriter writer( | 315 internal::HeapDumpWriter writer( |
315 session_state.stack_frame_deduplicator(), | 316 session_state.stack_frame_deduplicator(), |
316 session_state.type_name_deduplicator(), | 317 session_state.type_name_deduplicator(), |
317 session_state.heap_profiler_breakdown_threshold_bytes()); | 318 session_state.heap_profiler_breakdown_threshold_bytes()); |
318 return Serialize(writer.Summarize(metrics_by_context)); | 319 return Serialize(writer.Summarize(metrics_by_context)); |
319 } | 320 } |
320 | 321 |
321 } // namespace trace_event | 322 } // namespace trace_event |
322 } // namespace base | 323 } // namespace base |
OLD | NEW |