Class: SamplingProf::Threads
- Inherits:
-
Object
- Object
- SamplingProf::Threads
- Defined in:
- lib/sampling_prof/internal.rb
Instance Attribute Summary collapse
-
#max ⇒ Object
Returns the value of attribute max.
Instance Method Summary collapse
- #add(obj, time = Time.now) ⇒ Object
- #delete(obj) ⇒ Object
-
#initialize ⇒ Threads
constructor
A new instance of Threads.
- #sample_threads ⇒ Object
- #sampling_runtime ⇒ Object
Constructor Details
#initialize ⇒ Threads
Returns a new instance of Threads.
69 70 71 72 73 74 |
# File 'lib/sampling_prof/internal.rb', line 69 def initialize @hash = {} @mutex = Mutex.new @remain_sampling_time = 0 @max = 4 end |
Instance Attribute Details
#max ⇒ Object
Returns the value of attribute max.
67 68 69 |
# File 'lib/sampling_prof/internal.rb', line 67 def max @max end |
Instance Method Details
#add(obj, time = Time.now) ⇒ Object
80 81 82 |
# File 'lib/sampling_prof/internal.rb', line 80 def add(obj, time=Time.now) @mutex.synchronize { @hash[obj] = time } end |
#delete(obj) ⇒ Object
96 97 98 99 100 101 |
# File 'lib/sampling_prof/internal.rb', line 96 def delete(obj) @mutex.synchronize do start = @hash.delete(obj) @remain_sampling_time += Time.now - start end end |
#sample_threads ⇒ Object
76 77 78 |
# File 'lib/sampling_prof/internal.rb', line 76 def sample_threads @mutex.synchronize { @hash.keys.dup.shuffle[0..@max] } end |
#sampling_runtime ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/sampling_prof/internal.rb', line 84 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 |