| 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 5cc4c609549df9b75c3304400a366656fe4d1bf3..0f011653b1ea0d735f2e562e2a324ff599d931eb 100644
|
| --- a/base/trace_event/heap_profiler_type_name_deduplicator.cc
|
| +++ b/base/trace_event/heap_profiler_type_name_deduplicator.cc
|
| @@ -9,11 +9,11 @@
|
| #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/heap_profiler_string_deduplicator.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 {
|
| @@ -62,9 +62,11 @@ StringPiece ExtractCategoryFromTypeName(const char* type_name) {
|
|
|
| } // namespace
|
|
|
| -TypeNameDeduplicator::TypeNameDeduplicator() {
|
| - // A null pointer has type ID 0 ("unknown type");
|
| - type_ids_.insert(std::make_pair(nullptr, 0));
|
| +TypeNameDeduplicator::TypeNameDeduplicator(
|
| + StringDeduplicator* string_deduplicator)
|
| + : string_deduplicator_(string_deduplicator) {
|
| + // Add implicit entry for id 0 (NULL type names).
|
| + Insert(nullptr);
|
| }
|
|
|
| TypeNameDeduplicator::~TypeNameDeduplicator() {}
|
| @@ -78,43 +80,35 @@ 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::SerializeIncrementally(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);
|
| + StringPiece name = name_and_id->first
|
| + ? ExtractCategoryFromTypeName(name_and_id->first)
|
| + : "[unknown]";
|
| + int name_string_id = string_deduplicator_->Insert(name);
|
| + traced_value->SetInteger("name_sid", name_string_id);
|
|
|
| - // |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(
|
| TraceEventMemoryOverhead* overhead) {
|
| - size_t memory_usage = EstimateMemoryUsage(type_ids_);
|
| + size_t memory_usage =
|
| + EstimateMemoryUsage(type_ids_) + EstimateMemoryUsage(new_type_ids_);
|
| overhead->Add(TraceEventMemoryOverhead::kHeapProfilerTypeNameDeduplicator,
|
| sizeof(TypeNameDeduplicator) + memory_usage);
|
| }
|
|
|