Chromium Code Reviews| OLD | NEW |
|---|---|
| (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_exported_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()) { | |
|
Primiano Tucci (use gerrit)
2017/03/09 11:47:45
should this also be + || string.empty() to reuse t
DmitrySkiba
2017/03/14 22:12:47
NULL is the only value that means "no type name",
| |
| 24 // NULL strings are mapped to id 0. | |
| 25 return 0; | |
| 26 } | |
| 27 int next_id = static_cast<int>(strings_.size()); | |
| 28 auto iter_and_flag = string_ids_.insert({string, next_id}); | |
| 29 if (iter_and_flag.second) { | |
| 30 // Inserted a new mapping | |
| 31 strings_.push_back(string.as_string()); | |
|
Primiano Tucci (use gerrit)
2017/03/09 11:47:45
I think that if you do
strings_.emplace_back(strin
DmitrySkiba
2017/03/14 22:12:47
push_back() has && variant, which is used in this
| |
| 32 } | |
| 33 return iter_and_flag.first->second; | |
| 34 } | |
| 35 | |
| 36 void StringDeduplicator::ExportIncrementally(TracedValue* traced_value) { | |
| 37 for (; last_exported_index_ != strings_.size(); ++last_exported_index_) { | |
| 38 traced_value->BeginDictionary(); | |
| 39 traced_value->SetInteger("id", last_exported_index_); | |
| 40 traced_value->SetString("string", strings_[last_exported_index_]); | |
| 41 traced_value->EndDictionary(); | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 void StringDeduplicator::EstimateTraceMemoryOverhead( | |
| 46 TraceEventMemoryOverhead* overhead) { | |
| 47 size_t memory_usage = | |
| 48 EstimateMemoryUsage(string_ids_) + EstimateMemoryUsage(strings_); | |
| 49 overhead->Add("StringDeduplicator", | |
| 50 sizeof(StringDeduplicator) + memory_usage); | |
| 51 } | |
| 52 | |
| 53 } // namespace trace_event | |
| 54 } // namespace base | |
| OLD | NEW |