Class: TinyProfiler

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/tiny_profiler.rb,
lib/tiny_profiler/version.rb

Constant Summary collapse

VERSION =
"0.1.1"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#intervalsObject

Returns the value of attribute intervals.



9
10
11
# File 'lib/tiny_profiler.rb', line 9

def intervals
  @intervals
end

#start_timeObject

Returns the value of attribute start_time.



8
9
10
# File 'lib/tiny_profiler.rb', line 8

def start_time
  @start_time
end

#timesObject

Returns the value of attribute times.



10
11
12
# File 'lib/tiny_profiler.rb', line 10

def times
  @times
end

Instance Method Details

#finishedObject



20
21
22
23
24
# File 'lib/tiny_profiler.rb', line 20

def finished
  interval = Time.now - @start_time
  @times["total"] = interval
  return @times
end

#interval(name) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/tiny_profiler.rb', line 12

def interval(name)
  now = Time.now
  interval = now - @intervals.last
  @intervals << now
  @times[name] = interval
  p "#{name}: #{interval}"
end

#resetObject



32
33
34
# File 'lib/tiny_profiler.rb', line 32

def reset
  start
end

#startObject



26
27
28
29
30
# File 'lib/tiny_profiler.rb', line 26

def start
  @start_time = Time.now
  @intervals = [@start_time]
  @times = {}
end