Class: RequireProf::Profile

Inherits:
Object
  • Object
show all
Defined in:
lib/require_prof/profile.rb

Instance Method Summary collapse

Constructor Details

#initializeProfile

Returns a new instance of Profile.



8
9
10
11
12
13
# File 'lib/require_prof/profile.rb', line 8

def initialize
  @running = false
  @paused = false
  @root = RequireTree.new('.')
  @stack = [@root]
end

Instance Method Details

#pauseObject



28
29
30
# File 'lib/require_prof/profile.rb', line 28

def pause
  @paused = true
end

#paused?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/require_prof/profile.rb', line 19

def paused?
  @paused
end

#require(name) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/require_prof/profile.rb', line 43

def require(name)
  node = RequireTree.new(name)
  @stack.last << node
  @stack << node
  begin
    time_before = Time.now.to_f
    if MemorySampler.available?
      memory_before = MemorySampler.memory_usage
      overhead_time_before = Time.now.to_f - time_before
    end
    rp_original_require name
  ensure
    @stack.pop
    if MemorySampler.available?
      tmp_time = Time.now.to_f
      memory_after = MemorySampler.memory_usage
      overhead_time_after = Time.now.to_f - tmp_time
    end
    time_after = Time.now.to_f
  end
  node.total_time = (time_after - time_before) * 1000
  if MemorySampler.available?
    node.total_memory = memory_after - memory_before
    node.overhead_time = (overhead_time_before + overhead_time_after) * 1000
  end
end

#resumeObject



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

def resume
  @paused = false
end

#running?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/require_prof/profile.rb', line 15

def running?
  @running
end

#startObject



23
24
25
26
# File 'lib/require_prof/profile.rb', line 23

def start
  install_hook
  @running = true
end

#stopObject



36
37
38
39
40
41
# File 'lib/require_prof/profile.rb', line 36

def stop
  remove_hook
  @running = false
  post_process
  @root
end