Class: SamplingProfiler

Inherits:
Object
  • Object
show all
Defined in:
lib/sampling_prof/internal.rb

Defined Under Namespace

Classes: Sampling

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sampling_interval) ⇒ SamplingProfiler

Returns a new instance of SamplingProfiler.



80
81
82
83
84
85
# File 'lib/sampling_prof/internal.rb', line 80

def initialize(sampling_interval)
  @sampling_interval = sampling_interval
  @samplings = {}
  @running = false
  start_sampling_thread
end

Instance Attribute Details

#sampling_intervalObject

Returns the value of attribute sampling_interval.



78
79
80
# File 'lib/sampling_prof/internal.rb', line 78

def sampling_interval
  @sampling_interval
end

Instance Method Details

#profiling?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/sampling_prof/internal.rb', line 114

def profiling?
  !!@sampling_thread && @samplings.has_key?(Thread.current)
end

#start(output_handler) ⇒ Object



87
88
89
90
91
92
# File 'lib/sampling_prof/internal.rb', line 87

def start(output_handler)
  unless @samplings.has_key?(Thread.current)
    @samplings[Thread.current] = Sampling.new(output_handler)
    true
  end
end

#stopObject



94
95
96
97
98
99
100
101
102
103
# File 'lib/sampling_prof/internal.rb', line 94

def stop
  if @running
    if sampling = @samplings[Thread.current]
      unless sampling.stopped?
        sampling.stop
        true
      end
    end
  end
end

#terminateObject



105
106
107
108
109
110
111
112
# File 'lib/sampling_prof/internal.rb', line 105

def terminate
  return false unless @running
  @running = false
  @sampling_thread.join
  @sampling_thread = nil
  @samplings = {}
  true
end