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

Unified Diff: base/trace_event/heap_profiler_string_deduplicator.cc

Issue 2650863003: [tracing] Switch to new heap dump format. (Closed)
Patch Set: Fix rebase damage Created 3 years, 7 months 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_string_deduplicator.cc
diff --git a/base/trace_event/heap_profiler_string_deduplicator.cc b/base/trace_event/heap_profiler_string_deduplicator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bf035a19c03044b5cf675d77caa85ff65ea292db
--- /dev/null
+++ b/base/trace_event/heap_profiler_string_deduplicator.cc
@@ -0,0 +1,58 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#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 {
+namespace trace_event {
+
+StringDeduplicator::StringDeduplicator() : last_serialized_index_(0) {
+ // Add implicit entry for id 0 (NULL strings).
+ strings_.push_back("[null]");
+}
+
+StringDeduplicator::~StringDeduplicator() {}
+
+int StringDeduplicator::Insert(StringPiece string) {
+ if (!string.data()) {
+ // NULL strings are mapped to id 0.
+ return 0;
+ }
+ auto it = string_ids_.find(string);
+ if (it != string_ids_.end())
+ return it->second;
+
+ // Insert new mapping. Note that |string_ids_| keys reference values
+ // from |strings_|.
+ int string_id = static_cast<int>(strings_.size());
+ strings_.push_back(string.as_string());
+ auto iter_and_flag = string_ids_.insert({strings_.back(), string_id});
+ DCHECK(iter_and_flag.second); // insert() must succeed
+ return string_id;
+}
+
+void StringDeduplicator::SerializeIncrementally(TracedValue* traced_value) {
+ for (; last_serialized_index_ != strings_.size(); ++last_serialized_index_) {
+ traced_value->BeginDictionary();
+ traced_value->SetInteger("id", last_serialized_index_);
+ traced_value->SetString("string", strings_[last_serialized_index_]);
+ traced_value->EndDictionary();
+ }
+}
+
+void StringDeduplicator::EstimateTraceMemoryOverhead(
+ TraceEventMemoryOverhead* overhead) {
+ size_t memory_usage =
+ EstimateMemoryUsage(string_ids_) + EstimateMemoryUsage(strings_);
+ overhead->Add(TraceEventMemoryOverhead::kHeapProfilerStringDeduplicator,
+ sizeof(StringDeduplicator) + memory_usage);
+}
+
+} // namespace trace_event
+} // namespace base
« no previous file with comments | « base/trace_event/heap_profiler_string_deduplicator.h ('k') | base/trace_event/heap_profiler_string_deduplicator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698