Class: HeapScope::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/heapscope/config.rb

Constant Summary collapse

MODES =
%i[lightweight standard deep production_safe development].freeze
SNAPSHOT_MODES =
%i[lightweight standard deep].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/heapscope/config.rb', line 34

def initialize
  @mode = :standard
  @track_allocations = false
  @max_graph_depth = 6
  @max_objects = 100_000
  @max_edges = 500_000
  @max_pause_ms = nil
  @object_sample_rate = 1.0
  @force_gc_default = false
  @include_runtime_objects = false
  @ignore_patterns = [/^HeapScope::/]
  @ignored_classes = []
  @inspect_values = false
  @verbose = false
  @debug = false
  @rails = false
  @redactor = nil
  @logger = nil
  @warmup_done = false
  @min_retention_cycles = 3
  @detect_globals = true
  @detect_closures = false
  @detect_fibers = true
  @detect_thread_locals = true
  @apply_noise_defaults = true
  @quiet = false
end

Instance Attribute Details

#apply_noise_defaultsObject

Returns the value of attribute apply_noise_defaults.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def apply_noise_defaults
  @apply_noise_defaults
end

#debugObject

Returns the value of attribute debug.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def debug
  @debug
end

#detect_closuresObject

Returns the value of attribute detect_closures.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def detect_closures
  @detect_closures
end

#detect_fibersObject

Returns the value of attribute detect_fibers.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def detect_fibers
  @detect_fibers
end

#detect_globalsObject

Returns the value of attribute detect_globals.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def detect_globals
  @detect_globals
end

#detect_thread_localsObject

Returns the value of attribute detect_thread_locals.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def detect_thread_locals
  @detect_thread_locals
end

#force_gc_defaultObject

Returns the value of attribute force_gc_default.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def force_gc_default
  @force_gc_default
end

#ignore_patternsObject

Returns the value of attribute ignore_patterns.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def ignore_patterns
  @ignore_patterns
end

#ignored_classesObject

Returns the value of attribute ignored_classes.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def ignored_classes
  @ignored_classes
end

#include_runtime_objectsObject

Returns the value of attribute include_runtime_objects.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def include_runtime_objects
  @include_runtime_objects
end

#inspect_valuesObject

Returns the value of attribute inspect_values.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def inspect_values
  @inspect_values
end

#loggerObject

Returns the value of attribute logger.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def logger
  @logger
end

#max_edgesObject

Returns the value of attribute max_edges.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def max_edges
  @max_edges
end

#max_graph_depthObject

Returns the value of attribute max_graph_depth.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def max_graph_depth
  @max_graph_depth
end

#max_objectsObject

Returns the value of attribute max_objects.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def max_objects
  @max_objects
end

#max_pause_msObject

Returns the value of attribute max_pause_ms.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def max_pause_ms
  @max_pause_ms
end

#min_retention_cyclesObject

Returns the value of attribute min_retention_cycles.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def min_retention_cycles
  @min_retention_cycles
end

#modeObject

Returns the value of attribute mode.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def mode
  @mode
end

#object_sample_rateObject

Returns the value of attribute object_sample_rate.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def object_sample_rate
  @object_sample_rate
end

#quietObject

Returns the value of attribute quiet.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def quiet
  @quiet
end

#railsObject

Returns the value of attribute rails.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def rails
  @rails
end

#redactorObject

Returns the value of attribute redactor.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def redactor
  @redactor
end

#track_allocationsObject

Returns the value of attribute track_allocations.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def track_allocations
  @track_allocations
end

#verboseObject

Returns the value of attribute verbose.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def verbose
  @verbose
end

#warmup_doneObject

Returns the value of attribute warmup_done.



8
9
10
# File 'lib/heapscope/config.rb', line 8

def warmup_done
  @warmup_done
end

Instance Method Details

#development?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/heapscope/config.rb', line 66

def development?
  mode == :development
end

#effective_snapshot_mode(requested = nil) ⇒ Object



70
71
72
73
74
75
# File 'lib/heapscope/config.rb', line 70

def effective_snapshot_mode(requested = nil)
  requested ||= snapshot_mode_for_config
  return :lightweight if production_safe? && requested == :deep

  requested
end

#ignore_class?(name) ⇒ Boolean

Returns:

  • (Boolean)


85
86
87
88
89
# File 'lib/heapscope/config.rb', line 85

def ignore_class?(name)
  return true if ignored_classes.map(&:to_s).include?(name.to_s)

  ignore_patterns.any? { |pattern| name.to_s.match?(pattern) }
end

#log(level, message) ⇒ Object



98
99
100
101
102
103
# File 'lib/heapscope/config.rb', line 98

def log(level, message)
  return unless logger || verbose || debug
  return if level == :debug && !debug

  (logger || $stderr).puts("[HeapScope] #{message}")
end

#production_safe?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/heapscope/config.rb', line 62

def production_safe?
  mode == :production_safe
end

#redact(object) ⇒ Object



91
92
93
94
95
96
# File 'lib/heapscope/config.rb', line 91

def redact(object)
  return nil unless inspect_values
  return redactor.call(object) if redactor

  :"[redacted]"
end

#snapshot_mode_for_configObject



77
78
79
80
81
82
83
# File 'lib/heapscope/config.rb', line 77

def snapshot_mode_for_config
  case mode
  when :lightweight, :production_safe then :lightweight
  when :deep, :development then :deep
  else :standard
  end
end