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 #ifndef BASE_TRACE_EVENT_HEAP_PROFILER_STRING_DEDUPLICATOR_H_ | |
6 #define BASE_TRACE_EVENT_HEAP_PROFILER_STRING_DEDUPLICATOR_H_ | |
7 | |
8 #include <string> | |
9 #include <unordered_map> | |
10 #include <vector> | |
11 | |
12 #include "base/base_export.h" | |
13 #include "base/macros.h" | |
14 #include "base/strings/string_piece.h" | |
15 | |
16 namespace base { | |
17 namespace trace_event { | |
18 | |
19 class TraceEventMemoryOverhead; | |
20 class TracedValue; | |
21 | |
22 // Data structure that assigns a unique numeric ID to |const char*|s. | |
23 class BASE_EXPORT StringDeduplicator { | |
24 public: | |
25 StringDeduplicator(); | |
26 ~StringDeduplicator(); | |
27 | |
28 using Strings = std::vector<std::string>; | |
29 | |
30 // Deduplicated strings. IDs are indexes. | |
31 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.
| |
32 | |
33 // Inserts a string and returns its ID. | |
34 int Insert(StringPiece string); | |
35 | |
36 // Append {ID -> string} mappings that were added after the last call | |
37 // to this function. | |
38 void ExportIncrementally(TracedValue* traced_value); | |
39 | |
40 // Estimates memory overhead including |sizeof(StringDeduplicator)|. | |
41 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead); | |
42 | |
43 private: | |
44 // StringPieces in the map reference values from |string_|. | |
45 std::unordered_map<StringPiece, int, StringPieceHash> string_ids_; | |
46 Strings strings_; | |
47 size_t last_exported_index_; | |
48 | |
49 DISALLOW_COPY_AND_ASSIGN(StringDeduplicator); | |
50 }; | |
51 | |
52 } // namespace trace_event | |
53 } // namespace base | |
54 | |
55 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_STRING_DEDUPLICATOR_H_ | |
OLD | NEW |