Class: Fluent::ObjectSpaceDumpInput

Inherits:
Plugin::Input
  • Object
show all
Defined in:
lib/fluent/plugin/in_object_space_dump.rb

Overview

Dump out all live objects to json files. Each file is a snapshot of the Ruby heap at that time. See tmm1.net/ruby21-objspace/ for more details.

Instance Method Summary collapse

Constructor Details

#initializeObjectSpaceDumpInput

Returns a new instance of ObjectSpaceDumpInput.



25
26
27
28
29
# File 'lib/fluent/plugin/in_object_space_dump.rb', line 25

def initialize
  super

  ObjectSpace.trace_object_allocations_start
end

Instance Method Details

#multi_workers_ready?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/fluent/plugin/in_object_space_dump.rb', line 35

def multi_workers_ready?
  true
end

#on_timerObject



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/fluent/plugin/in_object_space_dump.rb', line 48

def on_timer
  GC.start
  # Use Tempfile.create to open the file, in order to preserve the file.
  file = Tempfile.create(["heap-#{fluentd_worker_id}-", '.json'])
  begin
    log.info 'dumping object space to',
             filepath: file.path,
             worker: fluentd_worker_id
    ObjectSpace.dump_all(output: file)
  ensure
    file.close
  end
end

#startObject



39
40
41
42
43
44
45
46
# File 'lib/fluent/plugin/in_object_space_dump.rb', line 39

def start
  super

  # Dump during startup. The timer only fires after @emit_interval.
  on_timer
  timer_execute(:object_space_dump_input, @emit_interval,
                &method(:on_timer))
end