Chromium Code Reviews| Index: base/trace_event/heap_profiler_string_deduplicator.h |
| diff --git a/base/trace_event/heap_profiler_string_deduplicator.h b/base/trace_event/heap_profiler_string_deduplicator.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..ee95b757d895632f50ae6f88dd79c838cc1848aa |
| --- /dev/null |
| +++ b/base/trace_event/heap_profiler_string_deduplicator.h |
| @@ -0,0 +1,55 @@ |
| +// 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. |
| + |
| +#ifndef BASE_TRACE_EVENT_HEAP_PROFILER_STRING_DEDUPLICATOR_H_ |
| +#define BASE_TRACE_EVENT_HEAP_PROFILER_STRING_DEDUPLICATOR_H_ |
| + |
| +#include <string> |
| +#include <unordered_map> |
| +#include <vector> |
| + |
| +#include "base/base_export.h" |
| +#include "base/macros.h" |
| +#include "base/strings/string_piece.h" |
| + |
| +namespace base { |
| +namespace trace_event { |
| + |
| +class TraceEventMemoryOverhead; |
| +class TracedValue; |
| + |
| +// Data structure that assigns a unique numeric ID to |const char*|s. |
| +class BASE_EXPORT StringDeduplicator { |
| + public: |
| + StringDeduplicator(); |
| + ~StringDeduplicator(); |
| + |
| + using Strings = std::vector<std::string>; |
| + |
| + // Deduplicated strings. IDs are indexes. |
| + const Strings& strings() const { return strings_; } |
|
ssid
2017/03/13 03:38:00
this doesn't seem to be used anywhere
DmitrySkiba
2017/03/14 22:12:48
Done.
|
| + |
| + // Inserts a string and returns its ID. |
| + int Insert(StringPiece string); |
| + |
| + // Append {ID -> string} mappings that were added after the last call |
| + // to this function. |
| + void ExportIncrementally(TracedValue* traced_value); |
| + |
| + // Estimates memory overhead including |sizeof(StringDeduplicator)|. |
| + void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead); |
| + |
| + private: |
| + // StringPieces in the map reference values from |string_|. |
| + std::unordered_map<StringPiece, int, StringPieceHash> string_ids_; |
| + Strings strings_; |
| + size_t last_exported_index_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(StringDeduplicator); |
| +}; |
| + |
| +} // namespace trace_event |
| +} // namespace base |
| + |
| +#endif // BASE_TRACE_EVENT_HEAP_PROFILER_STRING_DEDUPLICATOR_H_ |