Class: Vernier::Output::Top

Inherits:
Object
  • Object
show all
Includes:
Vernier::OutputHelpers
Defined in:
lib/vernier/output/top.rb

Defined Under Namespace

Classes: Table

Instance Method Summary collapse

Methods included from Vernier::OutputHelpers

#collapse_stack_weights, #sanitize_string

Constructor Details

#initialize(profile, row_limit) ⇒ Top

Returns a new instance of Top.



10
11
12
13
# File 'lib/vernier/output/top.rb', line 10

def initialize(profile, row_limit)
  @profile = profile
  @row_limit = row_limit
end

Instance Method Details

#outputObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/vernier/output/top.rb', line 55

def output
  thread = @profile.main_thread
  stack_table =
    if thread.respond_to?(:stack_table)
      thread.stack_table
    else
      @profile._stack_table
    end

  samples = thread[:samples]
  weights = thread[:weights]

  stack_weights = collapse_stack_weights(samples, weights)

  total = stack_weights.values.sum

  top_by_self = Hash.new(0)
  stack_weights.each do |stack_idx, weight|
    frame_idx = stack_table.stack_frame_idx(stack_idx)
    func_idx = stack_table.frame_func_idx(frame_idx)
    name = stack_table.func_name(func_idx)
    top_by_self[name] += weight
  end

  Table.new %w[Samples % name], @row_limit do |t|
    top_by_self.sort_by(&:last).reverse.each do |frame, samples|
      pct = 100.0 * samples / total
      t << [samples.to_s, pct.round(1).to_s, frame]
    end
  end.to_s
end