class LineProf::Report::Source
Attributes
file_name[R]
options[R]
raw_samples[R]
Public Class Methods
new(file_name, raw_samples, options = {})
click to toggle source
# File lib/rblineprof/report/source.rb, line 7 def initialize file_name, raw_samples, options = {} @file_name, @raw_samples, @options = file_name, raw_samples, options end
Public Instance Methods
format(colorize = true)
click to toggle source
# File lib/rblineprof/report/source.rb, line 11 def format colorize = true return nil if samples.empty? formatted = file_name.sub(Dir.pwd + '/', '') + "\n" prev_line = samples.first.line - 1 samples.each do |sample| if sample.line != prev_line + 1 formatted << color.intense_black(' ' * 14 + '.' * 7) + "\n" end prev_line = sample.line formatted << sample.format end formatted end
samples()
click to toggle source
# File lib/rblineprof/report/source.rb, line 29 def samples @samples ||= begin parsed = [] raw_samples.each_with_index do |sample, line| next if line == 0 # drop file info ms = sample[0] / 1000.0 calls = sample[2] abnormal = ms >= thresholds[NOMINAL] near_abnormal = (line-context..line+context).any? do |near| near = [1, near].max next unless raw_samples[near] (raw_samples[near][0] / 1000.0) >= thresholds[NOMINAL] end next unless abnormal or near_abnormal threshold = thresholds.invert.detect { |th, _| ms > th } level = threshold ? threshold.last : CONTEXT next unless code = source_lines[line - 1] parsed << Sample.new(ms, calls, line, code, level) end parsed end end
source_lines()
click to toggle source
# File lib/rblineprof/report/source.rb, line 59 def source_lines if File.exist?(file_name) @source_lines ||= ::File.readlines(file_name) else $stderr.puts "LineProf::Report::Source: #{file_name} is not found" @source_lines ||= [] end end
Private Instance Methods
color()
click to toggle source
# File lib/rblineprof/report/source.rb, line 70 def color Term::ANSIColor end
context()
click to toggle source
# File lib/rblineprof/report/source.rb, line 74 def context options.fetch :context, 2 end
thresholds()
click to toggle source
# File lib/rblineprof/report/source.rb, line 78 def thresholds @thresholds ||= { CRITICAL => 50, WARNING => 5, NOMINAL => 0.2 }.merge(options.fetch :thresholds, {}) end