Index: base/trace_event/heap_profiler_type_name_deduplicator.cc |
diff --git a/base/trace_event/heap_profiler_type_name_deduplicator.cc b/base/trace_event/heap_profiler_type_name_deduplicator.cc |
index a6dab51ad2abf24195a76c7f47b4dc0151fc99f7..a804033dc239d613123053aedb562676730b8a77 100644 |
--- a/base/trace_event/heap_profiler_type_name_deduplicator.cc |
+++ b/base/trace_event/heap_profiler_type_name_deduplicator.cc |
@@ -9,11 +9,10 @@ |
#include <string> |
#include <utility> |
-#include "base/json/string_escape.h" |
#include "base/strings/string_split.h" |
-#include "base/strings/stringprintf.h" |
#include "base/trace_event/memory_usage_estimator.h" |
#include "base/trace_event/trace_event.h" |
+#include "base/trace_event/trace_event_argument.h" |
#include "base/trace_event/trace_event_memory_overhead.h" |
namespace base { |
@@ -56,7 +55,7 @@ StringPiece ExtractCategoryFromTypeName(const char* type_name) { |
TypeNameDeduplicator::TypeNameDeduplicator() { |
// A null pointer has type ID 0 ("unknown type"); |
- type_ids_.insert(std::make_pair(nullptr, 0)); |
+ Insert(nullptr); |
} |
TypeNameDeduplicator::~TypeNameDeduplicator() {} |
@@ -70,38 +69,26 @@ int TypeNameDeduplicator::Insert(const char* type_name) { |
// The type IDs are assigned sequentially and they are zero-based, so |
// |size() - 1| is the ID of the new element. |
elem->second = static_cast<int>(type_ids_.size() - 1); |
+ new_type_ids_.push_back(result.first); |
} |
return elem->second; |
} |
-void TypeNameDeduplicator::AppendAsTraceFormat(std::string* out) const { |
- out->append("{"); // Begin the type names dictionary. |
+void TypeNameDeduplicator::AppendIncrementally(TracedValue* traced_value) { |
+ for (const auto& name_and_id : new_type_ids_) { |
+ traced_value->BeginDictionary(); |
- auto it = type_ids_.begin(); |
- std::string buffer; |
- |
- // Write the first entry manually; the null pointer must not be dereferenced. |
- // (The first entry is the null pointer because a |std::map| is ordered.) |
- it++; |
- out->append("\"0\":\"[unknown]\""); |
- |
- for (; it != type_ids_.end(); it++) { |
- // Type IDs in the trace are strings, write them as stringified keys of |
- // a dictionary. |
- SStringPrintf(&buffer, ",\"%d\":", it->second); |
+ traced_value->SetInteger("id", name_and_id->second); |
// TODO(ssid): crbug.com/594803 the type name is misused for file name in |
// some cases. |
- StringPiece type_info = ExtractCategoryFromTypeName(it->first); |
+ traced_value->SetString("type", |
+ ExtractCategoryFromTypeName(name_and_id->first)); |
- // |EscapeJSONString| appends, it does not overwrite |buffer|. |
- bool put_in_quotes = true; |
- EscapeJSONString(type_info, put_in_quotes, &buffer); |
- out->append(buffer); |
+ traced_value->EndDictionary(); |
} |
- |
- out->append("}"); // End the type names dictionary. |
+ new_type_ids_.clear(); |
} |
void TypeNameDeduplicator::EstimateTraceMemoryOverhead( |