Class: SamplingProf::Sampling
- Inherits:
-
Object
- Object
- SamplingProf::Sampling
- Defined in:
- lib/sampling_prof/internal.rb
Instance Method Summary collapse
- #call_element(loc) ⇒ Object
-
#initialize ⇒ Sampling
constructor
A new instance of Sampling.
- #node_id(loc) ⇒ Object
- #process(locations) ⇒ Object
- #result ⇒ Object
Constructor Details
#initialize ⇒ Sampling
7 8 9 10 11 |
# File 'lib/sampling_prof/internal.rb', line 7 def initialize @samples = Hash.new{|h,k| h[k] = [0, 0] } @call_graph = Hash.new{|h,k| h[k] = 0} @nodes = {} end |
Instance Method Details
#call_element(loc) ⇒ Object
45 46 47 |
# File 'lib/sampling_prof/internal.rb', line 45 def call_element(loc) [loc.path, loc.lineno, loc.label].join(":") end |
#node_id(loc) ⇒ Object
41 42 43 |
# File 'lib/sampling_prof/internal.rb', line 41 def node_id(loc) @nodes[call_element(loc)] ||= @nodes.size end |
#process(locations) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sampling_prof/internal.rb', line 17 def process(locations) from = -1 paths = [] calls = [] top_index = locations.size - 1 locations.reverse.each_with_index do |loc, i| node_id = node_id(loc) if i == top_index @samples[node_id][0] += 1 end path = [from, node_id] if !paths.include?(path) paths << path @call_graph[path] += 1 end if !calls.include?(node_id) calls << node_id @samples[node_id][1] += 1 end from = node_id end end |
#result ⇒ Object
13 14 15 |
# File 'lib/sampling_prof/internal.rb', line 13 def result [@nodes.to_a, @samples.to_a, @call_graph.to_a] end |