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 TypeNameDeduplicator(StringDeduplicator* string_deduplicator); |
Primiano Tucci (use gerrit)
2017/03/09 11:47:45
+explicit
DmitrySkiba
2017/03/14 22:12:47
Done.
| |
24 ~TypeNameDeduplicator() override; | 26 ~TypeNameDeduplicator(); |
25 | 27 |
26 // Inserts a type name and returns its ID. | 28 // Inserts a type name and returns its ID. |
27 int Insert(const char* type_name); | 29 int Insert(const char* type_name); |
28 | 30 |
29 // Writes the type ID -> type name mapping to the trace log. | 31 // Appends {ID -> type name} mappings that were added after the last call |
30 void AppendAsTraceFormat(std::string* out) const override; | 32 // to this function. |traced_value| must be in 'array' mode. |
33 void ExportIncrementally(TracedValue* traced_value); | |
31 | 34 |
32 // Estimates memory overhead including |sizeof(TypeNameDeduplicator)|. | 35 // Estimates memory overhead including |sizeof(TypeNameDeduplicator)|. |
33 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead) override; | 36 void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead); |
34 | 37 |
35 private: | 38 private: |
36 // Map from type name to type ID. | 39 StringDeduplicator* string_deduplicator_; |
37 std::map<const char*, int> type_ids_; | 40 |
41 // Map from type name to type ID. The reason this class has its own map | |
42 // and does not use string_deduplicator_ in Insert() is that type names | |
43 // are sometimes file names, and we need post-process them to extract | |
44 // categories. | |
45 using TypeMap = std::map<const char*, int>; | |
46 TypeMap type_ids_; | |
47 std::vector<const TypeMap::value_type*> new_type_ids_; | |
38 | 48 |
39 DISALLOW_COPY_AND_ASSIGN(TypeNameDeduplicator); | 49 DISALLOW_COPY_AND_ASSIGN(TypeNameDeduplicator); |
40 }; | 50 }; |
41 | 51 |
42 } // namespace trace_event | 52 } // namespace trace_event |
43 } // namespace base | 53 } // namespace base |
44 | 54 |
45 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_TYPE_NAME_DEDUPLICATOR_H_ | 55 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_TYPE_NAME_DEDUPLICATOR_H_ |
OLD | NEW |