Class: SamplingProf::Threads
- Inherits:
-
Object
- Object
- SamplingProf::Threads
- Defined in:
- lib/sampling_prof/internal.rb
Instance Method Summary collapse
- #add(obj) ⇒ Object
- #delete(obj) ⇒ Object
- #dup ⇒ Object
- #each(&block) ⇒ Object
-
#initialize ⇒ Threads
constructor
A new instance of Threads.
- #sampling_runtime ⇒ Object
Constructor Details
#initialize ⇒ Threads
Returns a new instance of Threads.
67 68 69 70 71 |
# File 'lib/sampling_prof/internal.rb', line 67 def initialize @hash = {} @mutex = Mutex.new @remain_sampling_time = 0 end |
Instance Method Details
#add(obj) ⇒ Object
81 82 83 |
# File 'lib/sampling_prof/internal.rb', line 81 def add(obj) @mutex.synchronize { @hash[obj] = Time.now } end |
#delete(obj) ⇒ Object
97 98 99 100 101 102 |
# File 'lib/sampling_prof/internal.rb', line 97 def delete(obj) @mutex.synchronize do start = @hash.delete(obj) @remain_sampling_time += Time.now - start end end |
#dup ⇒ Object
77 78 79 |
# File 'lib/sampling_prof/internal.rb', line 77 def dup @mutex.synchronize { @hash.keys.dup } end |
#each(&block) ⇒ Object
73 74 75 |
# File 'lib/sampling_prof/internal.rb', line 73 def each(&block) dup.each(&block) end |
#sampling_runtime ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/sampling_prof/internal.rb', line 85 def sampling_runtime now = Time.now @mutex.synchronize do ret, @remain_sampling_time = @remain_sampling_time, 0 @hash.keys.each do |k| ret += now - @hash[k] @hash[k] = now end ret end end |