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

Side by Side Diff: base/trace_event/heap_profiler_heap_dump_writer.cc

Issue 2052803002: Alternative heap dumping scheme. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: New stackFrames format Created 4 years, 3 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
OLDNEW
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 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 301
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> ExportHeapDumpOld(
312 const hash_map<AllocationContext, AllocationMetrics>& metrics_by_context, 312 const hash_map<AllocationContext, AllocationMetrics>& metrics_by_context,
313 const MemoryDumpSessionState& session_state) { 313 const MemoryDumpSessionState& session_state) {
314 internal::HeapDumpWriter writer( 314 internal::HeapDumpWriter writer(
315 session_state.stack_frame_deduplicator(), 315 session_state.stack_frame_deduplicator(),
316 session_state.type_name_deduplicator(), 316 session_state.type_name_deduplicator(),
317 session_state.memory_dump_config().heap_profiler_options 317 session_state.memory_dump_config().heap_profiler_options
318 .breakdown_threshold_bytes); 318 .breakdown_threshold_bytes);
319 return Serialize(writer.Summarize(metrics_by_context)); 319 return Serialize(writer.Summarize(metrics_by_context));
320 } 320 }
321 321
322 std::unique_ptr<TracedValue> ExportHeapDumpNew(
323 const hash_map<AllocationContext, AllocationMetrics>& metrics_by_context,
324 const MemoryDumpSessionState& session_state) {
325
326 struct Entry {
327 hash_map<int, AllocationMetrics> metrics_by_type_id;
328 };
329 hash_map<int, Entry> entry_by_backtrace_id;
330
331 for (const auto& context_and_metrics: metrics_by_context) {
332 const AllocationContext& context = context_and_metrics.first;
333 const AllocationMetrics& metrics = context_and_metrics.second;
334
335 int backtrace_id = session_state.stack_frame_deduplicator()->Insert(
336 std::begin(context.backtrace.frames),
337 std::begin(context.backtrace.frames) + context.backtrace.frame_count);
338 Entry& entry = entry_by_backtrace_id[backtrace_id];
339
340 int type_id = session_state.type_name_deduplicator()->Insert(
341 context.type_name);
342 AllocationMetrics& type_metrics = entry.metrics_by_type_id[type_id];
343 type_metrics.size += metrics.size;
344 type_metrics.count += metrics.count;
345 }
346
347 std::string buffer;
348 std::unique_ptr<TracedValue> traced_value(new TracedValue);
349
350 traced_value->BeginArray("entries");
351
352 for (const auto& backtrace_id_and_entry: entry_by_backtrace_id) {
353 traced_value->BeginDictionary();
354
355 SStringPrintf(&buffer, "%i", backtrace_id_and_entry.first);
356 traced_value->SetString("bt", buffer);
357
358 traced_value->BeginDictionary("types");
359
360 const Entry& entry = backtrace_id_and_entry.second;
361 for (const auto& type_id_and_metrics: entry.metrics_by_type_id) {
362 SStringPrintf(&buffer, "%i", type_id_and_metrics.first);
363 traced_value->BeginDictionaryWithCopiedName(buffer);
364
365 const AllocationMetrics& metrics = type_id_and_metrics.second;
366
367 SStringPrintf(&buffer, "%" PRIx64, static_cast<uint64_t>(metrics.size));
368 traced_value->SetString("size", buffer);
369
370 SStringPrintf(&buffer, "%" PRIx64, static_cast<uint64_t>(metrics.count));
371 traced_value->SetString("count", buffer);
372
373 traced_value->EndDictionary(); // "<type id>"
374 }
375
376 traced_value->EndDictionary(); // "types"
377
378 traced_value->EndDictionary(); // <entry>
379 }
380
381 traced_value->EndArray(); // "entries"
382 return traced_value;
383 }
384
385 std::unique_ptr<TracedValue> ExportHeapDump(
386 const hash_map<AllocationContext, AllocationMetrics>& metrics_by_context,
387 const MemoryDumpSessionState& session_state) {
388 #if defined(NEW_TRACE_FORMAT)
389 return ExportHeapDumpNew(metrics_by_context, session_state);
390 #else
391 return ExportHeapDumpOld(metrics_by_context, session_state);
392 #endif
393 }
394
322 } // namespace trace_event 395 } // namespace trace_event
323 } // namespace base 396 } // namespace base
OLDNEW
« no previous file with comments | « base/trace_event/heap_profiler_allocation_context.h ('k') | base/trace_event/heap_profiler_stack_frame_deduplicator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698