Class: TuneMyGc::Interposer
- Inherits:
-
Object
- Object
- TuneMyGc::Interposer
- Defined in:
- lib/tunemygc/interposer.rb
Instance Attribute Summary collapse
-
#installed ⇒ Object
Returns the value of attribute installed.
-
#spies ⇒ Object
readonly
Returns the value of attribute spies.
Instance Method Summary collapse
- #check_uninstall ⇒ Object
-
#initialize(spies = TuneMyGc.spies) ⇒ Interposer
constructor
A new instance of Interposer.
- #install ⇒ Object
- #kamikaze ⇒ Object
- #on_initialized ⇒ Object
- #spy ⇒ Object
- #uninstall ⇒ Object
Constructor Details
#initialize(spies = TuneMyGc.spies) ⇒ Interposer
Returns a new instance of Interposer.
10 11 12 13 |
# File 'lib/tunemygc/interposer.rb', line 10 def initialize(spies = TuneMyGc.spies) reset @spies = spies.map{|s| TuneMyGc::Spies.const_get(s).new } end |
Instance Attribute Details
#installed ⇒ Object
Returns the value of attribute installed.
8 9 10 |
# File 'lib/tunemygc/interposer.rb', line 8 def installed @installed end |
#spies ⇒ Object (readonly)
Returns the value of attribute spies.
7 8 9 |
# File 'lib/tunemygc/interposer.rb', line 7 def spies @spies end |
Instance Method Details
#check_uninstall ⇒ Object
53 54 55 |
# File 'lib/tunemygc/interposer.rb', line 53 def check_uninstall @spies.each{|s| s.check_uninstall } end |
#install ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/tunemygc/interposer.rb', line 27 def install return if @installed TuneMyGc.log "interposing" if TuneMyGc.rails? require 'active_support' ActiveSupport.on_load(:after_initialize) do TuneMyGc.interposer.on_initialized end else TuneMyGc.interposer.on_initialized end TuneMyGc.log "hooked: after_initialize" at_exit do if @installed TuneMyGc.log "at_exit" @spies.each{|s| s.uninstall } TuneMyGc.terminated TuneMyGc.recommendations end end TuneMyGc.log "hooked: at_exit" @installed = true TuneMyGc.log "interposed" end |
#kamikaze ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/tunemygc/interposer.rb', line 64 def kamikaze Thread.new do TuneMyGc.terminated TuneMyGc.log "kamikaze: synching #{TuneMyGc.snapshotter.size} GC sample snapshots ahead of time (usually only on process exit)" Timeout.timeout(TuneMyGc::KAMIZE_SYNC_TIMEOUT) do begin uninstall TuneMyGc.recommendations rescue Timeout::Error # Discard the TERMINATED snapshot, retry in the at_exit block TuneMyGc.snapshotter.deq TuneMyGc.log "kamikaze: timeout syncing #{TuneMyGc.snapshotter.size} GC samples ahead of time" end end end end |
#on_initialized ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/tunemygc/interposer.rb', line 19 def on_initialized GC.start(full_mark: true, :immediate_sweep => true) TuneMyGc.install_gc_tracepoint TuneMyGc.log "hooked: GC tracepoints" TuneMyGc.snapshot(:BOOTED, TuneMyGc.count_objects) TuneMyGc.interposer.spies.each{|s| s.install } end |
#spy ⇒ Object
15 16 17 |
# File 'lib/tunemygc/interposer.rb', line 15 def spy @spies.first end |
#uninstall ⇒ Object
57 58 59 60 61 62 |
# File 'lib/tunemygc/interposer.rb', line 57 def uninstall TuneMyGc.uninstall_gc_tracepoint TuneMyGc.log "uninstalled GC tracepoint" @spies.each{|s| s.uninstall } reset end |