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

Unified Diff: base/trace_event/heap_profiler_heap_dump_writer.cc

Issue 1467453003: [Tracing] Make heap profiler type info a string (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
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 dc27823bba060edd381819e87f50fc74ec6a56fe..d69ed7bb0a62437b4819b2625cd496ba04766422 100644
--- a/base/trace_event/heap_profiler_heap_dump_writer.cc
+++ b/base/trace_event/heap_profiler_heap_dump_writer.cc
@@ -12,13 +12,12 @@
#include "base/format_macros.h"
#include "base/strings/stringprintf.h"
#include "base/trace_event/heap_profiler_stack_frame_deduplicator.h"
+#include "base/trace_event/heap_profiler_type_name_deduplicator.h"
#include "base/trace_event/trace_event_argument.h"
namespace base {
namespace trace_event {
-using TypeId = AllocationContext::TypeId;
-
namespace {
template <typename T>
@@ -41,9 +40,11 @@ std::vector<std::pair<T, size_t>> SortBySizeDescending(
} // namespace
-HeapDumpWriter::HeapDumpWriter(StackFrameDeduplicator* stack_frame_deduplicator)
+HeapDumpWriter::HeapDumpWriter(StackFrameDeduplicator* stack_frame_deduplicator,
+ TypeNameDeduplicator* type_name_deduplicator)
: traced_value_(new TracedValue()),
- stack_frame_deduplicator_(stack_frame_deduplicator) {}
+ stack_frame_deduplicator_(stack_frame_deduplicator),
+ type_name_deduplicator_(type_name_deduplicator) {}
HeapDumpWriter::~HeapDumpWriter() {}
@@ -57,12 +58,12 @@ scoped_refptr<TracedValue> HeapDumpWriter::WriteHeapDump() {
// iterating anyway.
size_t total_size = 0;
hash_map<Backtrace, size_t> bytes_by_backtrace;
- hash_map<TypeId, size_t> bytes_by_type;
+ hash_map<const char*, size_t> bytes_by_type;
for (auto context_size : bytes_by_context_) {
total_size += context_size.second;
bytes_by_backtrace[context_size.first.backtrace] += context_size.second;
- bytes_by_type[context_size.first.type_id] += context_size.second;
+ bytes_by_type[context_size.first.type_name] += context_size.second;
}
auto sorted_bytes_by_backtrace = SortBySizeDescending(bytes_by_backtrace);
@@ -90,7 +91,9 @@ scoped_refptr<TracedValue> HeapDumpWriter::WriteHeapDump() {
// Entries with the size per type.
for (const auto& entry : sorted_bytes_by_type) {
traced_value_->BeginDictionary();
- WriteTypeId(entry.first);
+ // Insert a forward reference to the type name that will be written to the
+ // trace when it is flushed.
+ WriteTypeId(type_name_deduplicator_->Insert(entry.first));
WriteSize(entry.second);
traced_value_->EndDictionary();
}
@@ -113,17 +116,10 @@ void HeapDumpWriter::WriteStackFrameIndex(int index) {
}
}
-void HeapDumpWriter::WriteTypeId(TypeId type_id) {
- if (type_id == 0) {
- // Type ID 0 represents "unknown type". Instead of writing it as "0" which
- // could be mistaken for an actual type ID, an unknown type is represented
- // by the empty string.
- traced_value_->SetString("type", "");
- } else {
- // Format the type ID as a string.
- SStringPrintf(&buffer_, "%" PRIu16, type_id);
- traced_value_->SetString("type", buffer_);
- }
+void HeapDumpWriter::WriteTypeId(int type_id) {
+ // Format the type ID as a string.
+ SStringPrintf(&buffer_, "%i", type_id);
+ traced_value_->SetString("type", buffer_);
}
void HeapDumpWriter::WriteSize(size_t size) {
« no previous file with comments | « base/trace_event/heap_profiler_heap_dump_writer.h ('k') | base/trace_event/heap_profiler_heap_dump_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698