Class: SpeedGun::Profiler::LineProfiler

Inherits:
SpeedGun::Profiler show all
Defined in:
lib/speed_gun/profiler/line_profiler.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SpeedGun::Profiler

ignore?, profile

Class Method Details

.regexpObject



7
8
9
10
11
12
13
# File 'lib/speed_gun/profiler/line_profiler.rb', line 7

def self.regexp
  if SpeedGun.config.lineprof_paths.empty?
    %r{.}
  else
    Regexp.union(*SpeedGun.config.lineprof_paths)
  end
end

Instance Method Details

#profile(*_args) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/speed_gun/profiler/line_profiler.rb', line 15

def profile(*_args)
  return yield if self.class.ignore?

  result = nil
  lineprofiled = lineprof(self.class.regexp) do
    result = yield
  end
  store(lineprofiled) if SpeedGun.current_report
  result
end

#store(lineprofiled) ⇒ Object



26
27
28
29
30
31
# File 'lib/speed_gun/profiler/line_profiler.rb', line 26

def store(lineprofiled)
  lineprofiled.each_pair do |file, linesamples|
    source = SpeedGun::Source.new(file, linesamples)
    SpeedGun.current_report.source(source) unless source.lines.empty?
  end
end