Method: OneApm::TransactionAnalysis#breakdown_data

Defined in:
lib/one_apm/transaction/transaction_analysis.rb

#breakdown_data(limit = nil) ⇒ Object

return the data that breaks down the performance of the transaction as an array of SegmentSummary objects. If a limit is specified, then limit the data set to the top n



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/one_apm/transaction/transaction_analysis.rb', line 18

def breakdown_data(limit = nil)
  metric_hash = {}
  each_segment_with_nest_tracking do |segment|
    unless segment == root_segment
      metric_name = segment.metric_name
      metric_hash[metric_name] ||= SegmentSummary.new(metric_name, self)
      metric_hash[metric_name] << segment
      metric_hash[metric_name]
    end
  end

  data = metric_hash.values

  data.sort! do |x,y|
    y.exclusive_time <=> x.exclusive_time
  end

  if limit && data.length > limit
    data = data[0..limit - 1]
  end

  # add one last segment for the remaining time if any
  remainder = duration
  data.each do |segment|
    remainder -= segment.exclusive_time
  end

  if (remainder*1000).round > 0
    remainder_summary = SegmentSummary.new('Remainder', self)
    remainder_summary.total_time = remainder_summary.exclusive_time = remainder
    remainder_summary.call_count = 1
    data << remainder_summary
  end

  data
end