| Index: base/trace_event/heap_profiler_heap_dump_writer.cc
|
| diff --git a/base/trace_event/heap_profiler_heap_dump_writer.cc b/base/trace_event/heap_profiler_heap_dump_writer.cc
|
| index 1bf06dbd9763e706d2e7da4ae5933d16baf994ee..177e0570b3d0856b11a9830a8bee8508bd0ee8c9 100644
|
| --- a/base/trace_event/heap_profiler_heap_dump_writer.cc
|
| +++ b/base/trace_event/heap_profiler_heap_dump_writer.cc
|
| @@ -308,7 +308,7 @@ std::unique_ptr<TracedValue> Serialize(const std::set<Entry>& entries) {
|
|
|
| } // namespace internal
|
|
|
| -std::unique_ptr<TracedValue> ExportHeapDump(
|
| +std::unique_ptr<TracedValue> ExportHeapDumpOld(
|
| const hash_map<AllocationContext, AllocationMetrics>& metrics_by_context,
|
| const MemoryDumpSessionState& session_state) {
|
| internal::HeapDumpWriter writer(
|
| @@ -319,5 +319,78 @@ std::unique_ptr<TracedValue> ExportHeapDump(
|
| return Serialize(writer.Summarize(metrics_by_context));
|
| }
|
|
|
| +std::unique_ptr<TracedValue> ExportHeapDumpNew(
|
| + const hash_map<AllocationContext, AllocationMetrics>& metrics_by_context,
|
| + const MemoryDumpSessionState& session_state) {
|
| +
|
| + struct Entry {
|
| + hash_map<int, AllocationMetrics> metrics_by_type_id;
|
| + };
|
| + hash_map<int, Entry> entry_by_backtrace_id;
|
| +
|
| + for (const auto& context_and_metrics: metrics_by_context) {
|
| + const AllocationContext& context = context_and_metrics.first;
|
| + const AllocationMetrics& metrics = context_and_metrics.second;
|
| +
|
| + int backtrace_id = session_state.stack_frame_deduplicator()->Insert(
|
| + std::begin(context.backtrace.frames),
|
| + std::begin(context.backtrace.frames) + context.backtrace.frame_count);
|
| + Entry& entry = entry_by_backtrace_id[backtrace_id];
|
| +
|
| + int type_id = session_state.type_name_deduplicator()->Insert(
|
| + context.type_name);
|
| + AllocationMetrics& type_metrics = entry.metrics_by_type_id[type_id];
|
| + type_metrics.size += metrics.size;
|
| + type_metrics.count += metrics.count;
|
| + }
|
| +
|
| + std::string buffer;
|
| + std::unique_ptr<TracedValue> traced_value(new TracedValue);
|
| +
|
| + traced_value->BeginArray("entries");
|
| +
|
| + for (const auto& backtrace_id_and_entry: entry_by_backtrace_id) {
|
| + traced_value->BeginDictionary();
|
| +
|
| + SStringPrintf(&buffer, "%i", backtrace_id_and_entry.first);
|
| + traced_value->SetString("bt", buffer);
|
| +
|
| + traced_value->BeginDictionary("types");
|
| +
|
| + const Entry& entry = backtrace_id_and_entry.second;
|
| + for (const auto& type_id_and_metrics: entry.metrics_by_type_id) {
|
| + SStringPrintf(&buffer, "%i", type_id_and_metrics.first);
|
| + traced_value->BeginDictionaryWithCopiedName(buffer);
|
| +
|
| + const AllocationMetrics& metrics = type_id_and_metrics.second;
|
| +
|
| + SStringPrintf(&buffer, "%" PRIx64, static_cast<uint64_t>(metrics.size));
|
| + traced_value->SetString("size", buffer);
|
| +
|
| + SStringPrintf(&buffer, "%" PRIx64, static_cast<uint64_t>(metrics.count));
|
| + traced_value->SetString("count", buffer);
|
| +
|
| + traced_value->EndDictionary(); // "<type id>"
|
| + }
|
| +
|
| + traced_value->EndDictionary(); // "types"
|
| +
|
| + traced_value->EndDictionary(); // <entry>
|
| + }
|
| +
|
| + traced_value->EndArray(); // "entries"
|
| + return traced_value;
|
| +}
|
| +
|
| +std::unique_ptr<TracedValue> ExportHeapDump(
|
| + const hash_map<AllocationContext, AllocationMetrics>& metrics_by_context,
|
| + const MemoryDumpSessionState& session_state) {
|
| +#if defined(NEW_TRACE_FORMAT)
|
| + return ExportHeapDumpNew(metrics_by_context, session_state);
|
| +#else
|
| + return ExportHeapDumpOld(metrics_by_context, session_state);
|
| +#endif
|
| +}
|
| +
|
| } // namespace trace_event
|
| } // namespace base
|
|
|