summaryrefslogtreecommitdiff
path: root/base/trace_event/heap_profiler_type_name_deduplicator.h
blob: 2d26c73488ef59b7e7ce8502914a54984d4666f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Copyright 2015 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_TYPE_NAME_DEDUPLICATOR_H_
#define BASE_TRACE_EVENT_HEAP_PROFILER_TYPE_NAME_DEDUPLICATOR_H_

#include <map>
#include <string>

#include "base/base_export.h"
#include "base/macros.h"
#include "base/trace_event/trace_event_impl.h"

namespace base {
namespace trace_event {

class TraceEventMemoryOverhead;

// Data structure that assigns a unique numeric ID to |const char*|s.
class BASE_EXPORT TypeNameDeduplicator : public ConvertableToTraceFormat {
 public:
  TypeNameDeduplicator();
  ~TypeNameDeduplicator() override;

  // Inserts a type name and returns its ID.
  int Insert(const char* type_name);

  // Writes the type ID -> type name mapping to the trace log.
  void AppendAsTraceFormat(std::string* out) const override;

  // Estimates memory overhead including |sizeof(TypeNameDeduplicator)|.
  void EstimateTraceMemoryOverhead(TraceEventMemoryOverhead* overhead) override;

 private:
  // Map from type name to type ID.
  std::map<const char*, int> type_ids_;

  DISALLOW_COPY_AND_ASSIGN(TypeNameDeduplicator);
};

}  // namespace trace_event
}  // namespace base

#endif  // BASE_TRACE_EVENT_HEAP_PROFILER_TYPE_NAME_DEDUPLICATOR_H_