Class: Instana::Backend::GCSnapshot

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/instana/backend/gc_snapshot.rb

Overview

Keeps track of garbage collector related metrics

Since:

  • 1.197.0

Instance Method Summary collapse

Constructor Details

#initializeGCSnapshot

Returns a new instance of GCSnapshot.

Since:

  • 1.197.0



13
14
15
16
17
18
# File 'lib/instana/backend/gc_snapshot.rb', line 13

def initialize
  ::GC::Profiler.enable

  @last_major_count = 0
  @last_minor_count = 0
end

Instance Method Details

#reportObject

Since:

  • 1.197.0



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/instana/backend/gc_snapshot.rb', line 20

def report
  stats = ::GC.stat
  total_time = ::GC::Profiler.total_time * 1000

  ::GC::Profiler.clear

  payload = {
    totalTime: total_time,
    heap_live: stats[:heap_live_slots] || stats[:heap_live_num],
    heap_free: stats[:heap_free_slots] || stats[:heap_free_num],
    minorGcs: stats[:minor_gc_count] - @last_minor_count,
    majorGcs: stats[:major_gc_count] - @last_major_count
  }

  @last_major_count = stats[:major_gc_count]
  @last_minor_count = stats[:minor_gc_count]

  payload
end