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

Side by Side Diff: base/trace_event/heap_profiler_string_deduplicator.cc

Issue 2650863003: [tracing] Switch to new heap dump format. (Closed)
Patch Set: Rebase Created 3 years, 6 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/trace_event/heap_profiler_string_deduplicator.h"
6
7 #include "base/trace_event/memory_usage_estimator.h"
8 #include "base/trace_event/trace_event.h"
9 #include "base/trace_event/trace_event_argument.h"
10 #include "base/trace_event/trace_event_memory_overhead.h"
11
12 namespace base {
13 namespace trace_event {
14
15 StringDeduplicator::StringDeduplicator() : last_serialized_index_(0) {
16 // Add implicit entry for id 0 (NULL strings).
17 strings_.push_back("[null]");
18 }
19
20 StringDeduplicator::~StringDeduplicator() {}
21
22 int StringDeduplicator::Insert(StringPiece string) {
23 if (!string.data()) {
24 // NULL strings are mapped to id 0.
25 return 0;
26 }
27 auto it = string_ids_.find(string);
28 if (it != string_ids_.end())
29 return it->second;
30
31 // Insert new mapping. Note that |string_ids_| keys reference values
32 // from |strings_|.
33 int string_id = static_cast<int>(strings_.size());
34 strings_.push_back(string.as_string());
35 auto iter_and_flag = string_ids_.insert({strings_.back(), string_id});
36 DCHECK(iter_and_flag.second); // insert() must succeed
37 return string_id;
38 }
39
40 void StringDeduplicator::SerializeIncrementally(TracedValue* traced_value) {
41 for (; last_serialized_index_ != strings_.size(); ++last_serialized_index_) {
42 traced_value->BeginDictionary();
43 traced_value->SetInteger("id", last_serialized_index_);
44 traced_value->SetString("string", strings_[last_serialized_index_]);
45 traced_value->EndDictionary();
46 }
47 }
48
49 void StringDeduplicator::EstimateTraceMemoryOverhead(
50 TraceEventMemoryOverhead* overhead) {
51 size_t memory_usage =
52 EstimateMemoryUsage(string_ids_) + EstimateMemoryUsage(strings_);
53 overhead->Add(TraceEventMemoryOverhead::kHeapProfilerStringDeduplicator,
54 sizeof(StringDeduplicator) + memory_usage);
55 }
56
57 } // namespace trace_event
58 } // namespace base
OLDNEW
« 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