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 #include <set> 10 11 #include "base/base_export.h" 12 #include "base/trace_event/heap_profiler_stack_frame_deduplicator.h" 13 #include "base/trace_event/heap_profiler_type_name_deduplicator.h" 14 #include "base/trace_event/memory_dump_request_args.h" 15 16 namespace base { 17 namespace trace_event { 18 19 // Container for state variables that should be shared across all the memory 20 // dumps in a tracing session. 21 class BASE_EXPORT MemoryDumpSessionState 22 : public RefCountedThreadSafe<MemoryDumpSessionState> { 23 public: 24 MemoryDumpSessionState(); 25 26 // Returns the stack frame deduplicator that should be used by memory dump 27 // providers when doing a heap dump. 28 StackFrameDeduplicator* stack_frame_deduplicator() const { 29 return stack_frame_deduplicator_.get(); 30 } 31 32 void SetStackFrameDeduplicator( 33 std::unique_ptr<StackFrameDeduplicator> stack_frame_deduplicator); 34 35 // Returns the type name deduplicator that should be used by memory dump 36 // providers when doing a heap dump. 37 TypeNameDeduplicator* type_name_deduplicator() const { 38 return type_name_deduplicator_.get(); 39 } 40 41 void SetTypeNameDeduplicator( 42 std::unique_ptr<TypeNameDeduplicator> type_name_deduplicator); 43 44 void SetAllowedDumpModes( 45 std::set<MemoryDumpLevelOfDetail> allowed_dump_modes); 46 47 bool IsDumpModeAllowed(MemoryDumpLevelOfDetail dump_mode) const; 48 49 void set_heap_profiler_breakdown_threshold_bytes(uint32_t value) { 50 heap_profiler_breakdown_threshold_bytes_ = value; 51 } 52 53 uint32_t heap_profiler_breakdown_threshold_bytes() const { 54 return heap_profiler_breakdown_threshold_bytes_; 55 } 56 57 private: 58 friend class RefCountedThreadSafe<MemoryDumpSessionState>; 59 ~MemoryDumpSessionState(); 60 61 // Deduplicates backtraces in heap dumps so they can be written once when the 62 // trace is finalized. 63 std::unique_ptr<StackFrameDeduplicator> stack_frame_deduplicator_; 64 65 // Deduplicates type names in heap dumps so they can be written once when the 66 // trace is finalized. 67 std::unique_ptr<TypeNameDeduplicator> type_name_deduplicator_; 68 69 std::set<MemoryDumpLevelOfDetail> allowed_dump_modes_; 70 71 uint32_t heap_profiler_breakdown_threshold_bytes_; 72 }; 73 74 } // namespace trace_event 75 } // namespace base 76 77 #endif // BASE_TRACE_EVENT_MEMORY_DUMP_SESSION_STATE_H_ 78