Module: Contrast::Utils::HeadDumpExtend

Included in:
HeapDumpUtil
Defined in:
lib/contrast/utils/head_dump_utils_extend.rb

Overview

this module extends HeadDumpUtil

Instance Method Summary collapse

Instance Method Details

#capture_heap_dumpObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/contrast/utils/head_dump_utils_extend.rb', line 50

def capture_heap_dump
  control = Contrast::Utils::HeapDumpUtil.control
  dir    = control[:path]
  window = control[:window]
  count  = control[:count]
  clean  = control[:clean]
  logger.info('HEAP DUMP MAIN LOOP')
  ObjectSpace.trace_object_allocations_start
  count.times do |i|
    logger.info('STARTING HEAP DUMP PASS', current_pass: i, max: count)
    snapshot_heap(dir, clean)
    logger.info('FINISHING HEAP DUMP PASS', current_pass: i, max: count)
    sleep(window)
  end
ensure
  ObjectSpace.trace_object_allocations_stop
  logger.info('*****************************************************')
  logger.info('********        HEAP DUMP HAS CONCLUDED      ********')
  logger.info('***     APPLICATION PROCESS WILL EXIT SHORTLY     ***')
  logger.info('*****************************************************')
  exit # rubocop:disable Rails/Exit We weren't kidding!
end

#log_enabled_warningObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/contrast/utils/head_dump_utils_extend.rb', line 8

def log_enabled_warning
  control = Contrast::Utils::HeapDumpUtil.control
  dir    = control[:path]
  window = control[:window]
  count  = control[:count]
  delay  = control[:delay]
  clean  = control[:clean]

  logger.info(<<~WARNING)
    *****************************************************
    ********      HEAP DUMP HAS BEEN ENABLED     ********
    *** APPLICATION PROCESS WILL EXIT UPON COMPLETION ***
    *****************************************************

    Heap dump is a debugging tool that snapshots the entire
    state of the Ruby VM. It is an exceptionally expensive
    process, and should only be used to debug especially
    pernicious errors.

    It will write multiple memory snaphots, which are liable
    to be multiple gigabytes in size.
    They will be named "[unix timestamp]-heap.dump",
    e.g.: 1020304050-heap.dump

    It will then call Ruby `exit()`.

    If this is not your specific intent, you can (and should)
    disable this option in your Contrast config file.

    HEAP DUMP PARAMETERS:
    \t[write files to this directory]             dir:     #{ dir    }
    \t[wait this many seconds in between dumps]   window:  #{ window }
    \t[heap dump this many times]                 count:   #{ count  }
    \t[wait this many seconds into app lifetime]  delay:   #{ delay  }
    \t[perform gc pass before dump]               clean:   #{ clean  }

    *****************************************************
    ********        YOU HAVE BEEN WARNED         ********
    *****************************************************
  WARNING
end