Chromium Code Reviews| Index: base/trace_event/heap_profiler_event_writer.h |
| diff --git a/base/trace_event/heap_profiler_event_writer.h b/base/trace_event/heap_profiler_event_writer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..95cbcc9883159a8b07abb439312454c0379e9edc |
| --- /dev/null |
| +++ b/base/trace_event/heap_profiler_event_writer.h |
| @@ -0,0 +1,104 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
|
Primiano Tucci (use gerrit)
2017/03/09 11:47:44
2017 :)
DmitrySkiba
2017/03/14 22:12:47
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef BASE_TRACE_EVENT_HEAP_PROFILER_EVENT_WRITER_H_ |
| +#define BASE_TRACE_EVENT_HEAP_PROFILER_EVENT_WRITER_H_ |
| + |
| +#include <stddef.h> |
| + |
| +#include <memory> |
| +#include <string> |
| +#include <unordered_map> |
| + |
| +#include "base/base_export.h" |
| + |
| +/* |
| + Heap profile event data format. |
|
Primiano Tucci (use gerrit)
2017/03/09 11:47:44
this comment is really awesome. thanks a lot, real
|
| + |
| + Input is: |
| + 1. Per allocator AllocationRegister |
| + 2. Per process deduplicators (for stack frames, types, strings) |
| + |
| + Formatting event data has two steps: |
| + 1. Call ExportHeapDump() on allocation registers and accumulate results |
|
Primiano Tucci (use gerrit)
2017/03/09 11:47:44
only have one small comment about naming: you have
DmitrySkiba
2017/03/14 22:12:47
Done. Going with Export -> Serialize.
|
| + in ExportedHeapDumpsMap. ExportHeapDump() exports allocation register |
| + as "allocators/<allocator>" dictionary outlined below; deduplicators |
| + contained in MemoryDumpSessionState are used in the process. |
|
Primiano Tucci (use gerrit)
2017/03/09 11:47:44
s/in the process/in this stage/
DmitrySkiba
2017/03/14 22:12:47
Done.
|
| + 2. Call ExportHeapProfileEventData() with ExportedHeapDumpsMap and |
| + MemoryDumpSessionState. This puts everything together: |
| + a. Entries from ExportedHeapDumpsMap are formatted as |
| + "allocators/<allocator>" nodes. |
| + b. Deduplicators from MemoryDumpSessionState are formatted as |
| + "maps/" nodes. Deduplicators are exported incrementally using |
| + their ExportIncrementally() methods. |
| + |
| + ExportHeapDump() aggregates allocation register entries first by backtrace, |
| + then by type (i.e. creates map {(backtrace, type) -> AllocationMetrics}). |
| + During aggregation backtraces and types are deduplicated. |
| + |
| + Resulting event data format: |
| + { |
| + "version": 1, |
| + |
| + "allocators": { |
| + <allocator>: { |
|
Primiano Tucci (use gerrit)
2017/03/09 11:47:44
maybe, just to clarify, I'ld s/<allocator>/[malloc
DmitrySkiba
2017/03/14 22:12:47
Done.
|
| + "nodes": [<stack_frame_id1>, <stack_frame_id2>, ...], |
| + "types": [<type_id1>, <type_id2>, ...], |
| + "counts": [<count1>, <count2>, ...], |
| + "sizes": [<size1>, <size1>, ...] |
|
Primiano Tucci (use gerrit)
2017/03/09 11:47:44
I guess the 2nd one is size2?
DmitrySkiba
2017/03/14 22:12:47
Done.
|
| + } |
| + }, |
| + |
| + "maps": { |
| + "nodes": [ |
| + { |
| + "id": <stack_frame_id>, |
| + "parent": <parent_id>, |
|
Primiano Tucci (use gerrit)
2017/03/09 11:47:44
not sure if this is going to affect too much the p
DmitrySkiba
2017/03/14 22:12:47
Yeah, we need to bikeshed that. We can do a pass a
Primiano Tucci (use gerrit)
2017/03/15 20:41:40
Alright. Agree that's definitely not a blocker for
|
| + "name_sid": <name_string_id> |
| + }, |
| + ... |
| + ], |
| + "types": [ |
| + { |
| + "id": <type_id>, |
| + "name_sid": <name_string_id> |
| + } |
| + ], |
| + "strings": [ |
| + { |
| + "id": <string_id>, |
| + "string": <string> |
| + } |
| + ] |
| + } |
| + } |
| +*/ |
| + |
| +namespace base { |
| +namespace trace_event { |
| + |
| +class AllocationRegister; |
| +class MemoryDumpSessionState; |
| +class TracedValue; |
| + |
| +// Exports heap allocations as "allocators/<allocator>" dictionary described |
| +// above. Return value is supposed to be added to ExportedHeapDumpsMap map |
| +// and later passed to ExportHeapProfileEventData(). |
| +BASE_EXPORT std::unique_ptr<TracedValue> ExportHeapDump( |
| + const AllocationRegister& allocation_register, |
| + const MemoryDumpSessionState& session_state); |
| + |
| +// Maps allocator name to its heap dump. |
| +using ExportedHeapDumpsMap = |
|
Primiano Tucci (use gerrit)
2017/03/09 11:47:44
yeah the more I look at this the more I think that
DmitrySkiba
2017/03/14 22:12:47
Done.
|
| + std::unordered_map<std::string, std::unique_ptr<TracedValue>>; |
| + |
| +// Exports event data according to the format described above. |
| +BASE_EXPORT std::unique_ptr<TracedValue> ExportHeapProfileEventData( |
| + const ExportedHeapDumpsMap& heap_dumps, |
| + const MemoryDumpSessionState& session_state); |
| + |
| +} // namespace trace_event |
| +} // namespace base |
| + |
| +#endif // BASE_TRACE_EVENT_HEAP_PROFILER_EVENT_WRITER_H_ |