Class: SassProf::Profiler

Inherits:
Object
  • Object
show all
Defined in:
lib/sass-prof/profiler.rb

Constant Summary collapse

PERFORMABLE_ACTIONS =
[:fun, :mix, :ext]

Instance Method Summary collapse

Constructor Details

#initialize(subject, action, args = nil, env = nil) ⇒ Profiler

Returns a new instance of Profiler.



6
7
8
9
10
11
12
13
14
# File 'lib/sass-prof/profiler.rb', line 6

def initialize(subject, action, args = nil, env = nil)
  @subject = subject
  @action  = action
  @args    = args
  @env     = env
  @t_total = 0
  @t_then  = 0
  @t_now   = 0
end

Instance Method Details

#startObject



16
17
18
# File 'lib/sass-prof/profiler.rb', line 16

def start
  @t_then = Time.now
end

#stopObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sass-prof/profiler.rb', line 20

def stop
  @t_now = Time.now
  t_delta = (@t_now.to_f - @t_then.to_f) * 1000.0
  @t_then, @t_total = @t_now, t_delta

  # Add to total execution time
  Timer.add_t_total t_delta

  # Add to action's execution time and count
  Timer.send "add_t_#{@action}_total",   t_delta
  Timer.send "add_cnt_#{@action}_total", 1

  create_report
end