Class: SamplingProf::Threads

Inherits:
Object
  • Object
show all
Defined in:
lib/sampling_prof/internal.rb

Instance Method Summary collapse

Constructor Details

#initializeThreads

Returns a new instance of Threads.



63
64
65
66
67
# File 'lib/sampling_prof/internal.rb', line 63

def initialize
  @hash = {}
  @mutex = Mutex.new
  @remain_sampling_time = 0
end

Instance Method Details

#add(obj) ⇒ Object



77
78
79
# File 'lib/sampling_prof/internal.rb', line 77

def add(obj)
  @mutex.synchronize { @hash[obj] = Time.now }
end

#delete(obj) ⇒ Object



93
94
95
96
97
98
# File 'lib/sampling_prof/internal.rb', line 93

def delete(obj)
  @mutex.synchronize do
    start = @hash.delete(obj)
    @remain_sampling_time += Time.now - start
  end
end

#dupObject



73
74
75
# File 'lib/sampling_prof/internal.rb', line 73

def dup
  @mutex.synchronize { @hash.keys.dup }
end

#each(&block) ⇒ Object



69
70
71
# File 'lib/sampling_prof/internal.rb', line 69

def each(&block)
  dup.each(&block)
end

#sampling_runtimeObject



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/sampling_prof/internal.rb', line 81

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