• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef BASE_TRACE_EVENT_MEMORY_DUMP_SESSION_STATE_H_
6 #define BASE_TRACE_EVENT_MEMORY_DUMP_SESSION_STATE_H_
7 
8 #include <memory>
9 
10 #include "base/base_export.h"
11 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h"
12 #include "base/trace_event/heap_profiler_type_name_deduplicator.h"
13 #include "base/trace_event/trace_config.h"
14 
15 namespace base {
16 namespace trace_event {
17 
18 // Container for state variables that should be shared across all the memory
19 // dumps in a tracing session.
20 class BASE_EXPORT MemoryDumpSessionState
21     : public RefCountedThreadSafe<MemoryDumpSessionState> {
22  public:
23   MemoryDumpSessionState();
24 
25   // Returns the stack frame deduplicator that should be used by memory dump
26   // providers when doing a heap dump.
stack_frame_deduplicator()27   StackFrameDeduplicator* stack_frame_deduplicator() const {
28     return stack_frame_deduplicator_.get();
29   }
30 
31   void SetStackFrameDeduplicator(
32       std::unique_ptr<StackFrameDeduplicator> stack_frame_deduplicator);
33 
34   // Returns the type name deduplicator that should be used by memory dump
35   // providers when doing a heap dump.
type_name_deduplicator()36   TypeNameDeduplicator* type_name_deduplicator() const {
37     return type_name_deduplicator_.get();
38   }
39 
40   void SetTypeNameDeduplicator(
41       std::unique_ptr<TypeNameDeduplicator> type_name_deduplicator);
42 
memory_dump_config()43   const TraceConfig::MemoryDumpConfig& memory_dump_config() const {
44     return memory_dump_config_;
45   }
46 
47   void SetMemoryDumpConfig(const TraceConfig::MemoryDumpConfig& config);
48 
49  private:
50   friend class RefCountedThreadSafe<MemoryDumpSessionState>;
51   ~MemoryDumpSessionState();
52 
53   // Deduplicates backtraces in heap dumps so they can be written once when the
54   // trace is finalized.
55   std::unique_ptr<StackFrameDeduplicator> stack_frame_deduplicator_;
56 
57   // Deduplicates type names in heap dumps so they can be written once when the
58   // trace is finalized.
59   std::unique_ptr<TypeNameDeduplicator> type_name_deduplicator_;
60 
61   // The memory dump config, copied at the time when the tracing session was
62   // started.
63   TraceConfig::MemoryDumpConfig memory_dump_config_;
64 };
65 
66 }  // namespace trace_event
67 }  // namespace base
68 
69 #endif  // BASE_TRACE_EVENT_MEMORY_DUMP_SESSION_STATE_H_
70