Class: Appsignal::GarbageCollection::Profiler Private
- Defined in:
- lib/appsignal/garbage_collection.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A wrapper around Ruby's GC::Profiler
that tracks garbage collection
time, while clearing GC::Profiler
's total_time to make sure it doesn't
leak memory by keeping garbage collection run samples in memory.
Class Method Summary collapse
- .lock ⇒ Object private
Instance Method Summary collapse
-
#initialize ⇒ Profiler
constructor
private
A new instance of Profiler.
-
#total_time ⇒ Integer
private
Whenever #total_time is called, the current
GC::Profiler#total_time
gets added to@total_time
, after whichGC::Profiler.clear
is called to prevent it from leaking memory.
Constructor Details
#initialize ⇒ Profiler
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Profiler.
46 47 48 |
# File 'lib/appsignal/garbage_collection.rb', line 46 def initialize @total_time = 0 end |
Class Method Details
.lock ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
42 43 44 |
# File 'lib/appsignal/garbage_collection.rb', line 42 def self.lock @lock ||= Mutex.new end |
Instance Method Details
#total_time ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Whenever #total_time is called, the current GC::Profiler#total_time
gets added to @total_time
, after which GC::Profiler.clear
is called
to prevent it from leaking memory. A class-level lock is used to make
sure garbage collection time is never counted more than once.
Whenever @total_time
gets above two billion milliseconds (about 23
days), it's reset to make sure the result fits in a signed 32-bit
integer.
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/appsignal/garbage_collection.rb', line 60 def total_time lock.synchronize do @total_time += (internal_profiler.total_time * 1000).round internal_profiler.clear end @total_time = 0 if @total_time > 2_000_000_000 @total_time end |