Class: Vernier::Output::Top
- Inherits:
-
Object
- Object
- Vernier::Output::Top
- Defined in:
- lib/vernier/output/top.rb
Defined Under Namespace
Classes: Table
Instance Method Summary collapse
-
#initialize(profile, row_limit) ⇒ Top
constructor
A new instance of Top.
- #output ⇒ Object
Constructor Details
#initialize(profile, row_limit) ⇒ Top
Returns a new instance of Top.
6 7 8 9 |
# File 'lib/vernier/output/top.rb', line 6 def initialize(profile, row_limit) @profile = profile @row_limit = row_limit end |
Instance Method Details
#output ⇒ Object
51 52 53 54 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 |
# File 'lib/vernier/output/top.rb', line 51 def output thread = @profile.main_thread stack_table = if thread.respond_to?(:stack_table) thread.stack_table else @profile._stack_table end stack_weights = Hash.new(0) thread[:samples].zip(thread[:weights]) do |stack_idx, weight| stack_weights[stack_idx] += weight end 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 |