OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_TRACE_EVENT_HEAP_PROFILER_TYPE_NAME_DEDUPLICATOR_H_ | 5 #ifndef BASE_TRACE_EVENT_HEAP_PROFILER_TYPE_NAME_DEDUPLICATOR_H_ |
6 #define BASE_TRACE_EVENT_HEAP_PROFILER_TYPE_NAME_DEDUPLICATOR_H_ | 6 #define BASE_TRACE_EVENT_HEAP_PROFILER_TYPE_NAME_DEDUPLICATOR_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
| 10 #include <vector> |
10 | 11 |
11 #include "base/base_export.h" | 12 #include "base/base_export.h" |
12 #include "base/macros.h" | 13 #include "base/macros.h" |
13 #include "base/trace_event/trace_event_impl.h" | |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 namespace trace_event { | 16 namespace trace_event { |
17 | 17 |
| 18 class StringDeduplicator; |
18 class TraceEventMemoryOverhead; | 19 class TraceEventMemoryOverhead; |
| 20 class TracedValue; |
19 | 21 |
20 // Data structure that assigns a unique numeric ID to |const char*|s. | 22 // Data structure that assigns a unique numeric ID to type names. |
21 class BASE_EXPORT TypeNameDeduplicator : public ConvertableToTraceFormat { | 23 class BASE_EXPORT TypeNameDeduplicator { |
22 public: | 24 public: |
23 TypeNameDeduplicator(); | 25 // |string_deduplication| is used during serialization, and is expected |
24 ~TypeNameDeduplicator() override; | 26 // to outlive instances of this class. |
| 27 explicit TypeNameDeduplicator(StringDeduplicator* string_deduplicator); |
| 28 ~TypeNameDeduplicator(); |
25 | 29 |
26 // Inserts a type name and returns its ID. | 30 // Inserts a type name and returns its ID. |
27 int Insert(const char* type_name); | 31 int Insert(const char* type_name); |
28 | 32 |
29 // Writes the type ID -> type name mapping to the trace log. | 33 // Appends {ID -> type name} mappings that were added after the last call |
30 void AppendAsTraceFormat(std::string* out) const override; | 34 // to this function. |traced_value| must be in 'array' mode. |
| 35 void SerializeIncrementally(TracedValue* traced_value); |
31 | 36 |
32 // Estimates memory overhead including |sizeof(TypeNameDeduplicator)|. | 37 // Estimates memory overhead including |sizeof(TypeNameDeduplicator)|. |
33 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead) override; | 38 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead); |
34 | 39 |
35 private: | 40 private: |
36 // Map from type name to type ID. | 41 StringDeduplicator* string_deduplicator_; |
37 std::map<const char*, int> type_ids_; | 42 |
| 43 // Map from type name to type ID. The reason this class has its own map |
| 44 // and does not use string_deduplicator_ in Insert() is that type names |
| 45 // are sometimes file names, and we need post-process them to extract |
| 46 // categories. |
| 47 using TypeMap = std::map<const char*, int>; |
| 48 TypeMap type_ids_; |
| 49 std::vector<const TypeMap::value_type*> new_type_ids_; |
38 | 50 |
39 DISALLOW_COPY_AND_ASSIGN(TypeNameDeduplicator); | 51 DISALLOW_COPY_AND_ASSIGN(TypeNameDeduplicator); |
40 }; | 52 }; |
41 | 53 |
42 } // namespace trace_event | 54 } // namespace trace_event |
43 } // namespace base | 55 } // namespace base |
44 | 56 |
45 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_TYPE_NAME_DEDUPLICATOR_H_ | 57 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_TYPE_NAME_DEDUPLICATOR_H_ |
OLD | NEW |