Class: HeapInfo::Chunk
- Inherits:
-
Object
- Object
- HeapInfo::Chunk
- Defined in:
- lib/heapinfo/chunk.rb
Overview
The object of a heap chunk
Direct Known Subclasses
Instance Attribute Summary collapse
-
#base ⇒ Integer
readonly
Base address of this chunk.
-
#data ⇒ String
readonly
Chunk data.
-
#prev_size ⇒ Integer
readonly
Previous chunk size.
-
#size_t ⇒ Integer
readonly
4 or 8 according to 32bit or 64bit, respectively.
Instance Method Summary collapse
-
#bintype ⇒ Symbol
Bin type of this chunk.
-
#flags ⇒ Array<Symbol>
The chunk flags record in low three bits of size.
-
#initialize(size_t, base, dumper, head: false) ⇒ Chunk
constructor
Instantiate a Chunk object.
-
#mmapped? ⇒ Boolean
Ask if chunk is mmapped.
-
#non_main_arena? ⇒ Boolean
Ask if chunk not belongs to main arena.
-
#prev_inuse? ⇒ Boolean
Ask if chunk has set the prev-inuse bit.
-
#size ⇒ Integer
Size of chunk.
-
#to_s ⇒ String
Hook
#to_sfor pretty printing.
Constructor Details
#initialize(size_t, base, dumper, head: false) ⇒ Chunk
Instantiate a HeapInfo::Chunk object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/heapinfo/chunk.rb', line 26 def initialize(size_t, base, dumper, head: false) raise ArgumentError, 'size_t can be either 4 or 8' unless [4, 8].include?(size_t) self.class.__send__(:define_method, :dump) { |*args| dumper.call(*args) } @size_t = size_t @base = base sz = dump(@base, size_t * 2) if head # no need to read size if is bin @data = dump(@base + size_t * 2, size_t * 4) return end @prev_size = Helper.unpack(size_t, sz[0, size_t]) @size = Helper.unpack(size_t, sz[size_t..-1]) r_size = [size - size_t * 2, size_t * 4].min # don't read too much data r_size = [r_size, 0].max # prevent negative size @data = dump(@base + size_t * 2, r_size) end |
Instance Attribute Details
#base ⇒ Integer (readonly)
Returns Base address of this chunk.
13 14 15 |
# File 'lib/heapinfo/chunk.rb', line 13 def base @base end |
#data ⇒ String (readonly)
Returns chunk data.
11 12 13 |
# File 'lib/heapinfo/chunk.rb', line 11 def data @data end |
#prev_size ⇒ Integer (readonly)
Returns previous chunk size.
9 10 11 |
# File 'lib/heapinfo/chunk.rb', line 9 def prev_size @prev_size end |
#size_t ⇒ Integer (readonly)
Returns 4 or 8 according to 32bit or 64bit, respectively.
7 8 9 |
# File 'lib/heapinfo/chunk.rb', line 7 def size_t @size_t end |
Instance Method Details
#bintype ⇒ Symbol
Bin type of this chunk
113 114 115 116 117 118 119 120 |
# File 'lib/heapinfo/chunk.rb', line 113 def bintype sz = size return :unknown if sz < @size_t * 4 return :fast if sz <= @size_t * 16 return :small if sz <= @size_t * 0x7e return :large if sz <= @size_t * 0x3ffe # is this correct? :mmap end |
#flags ⇒ Array<Symbol>
The chunk flags record in low three bits of size
60 61 62 63 64 65 66 67 |
# File 'lib/heapinfo/chunk.rb', line 60 def flags mask = @size - size flag = [] flag << :non_main_arena unless (mask & 4).zero? flag << :mmapped unless (mask & 2).zero? flag << :prev_inuse unless (mask & 1).zero? flag end |
#mmapped? ⇒ Boolean
Ask if chunk is mmapped.
79 80 81 |
# File 'lib/heapinfo/chunk.rb', line 79 def mmapped? flags.include? :mmapped end |
#non_main_arena? ⇒ Boolean
Ask if chunk not belongs to main arena.
72 73 74 |
# File 'lib/heapinfo/chunk.rb', line 72 def non_main_arena? flags.include? :non_main_arena end |
#prev_inuse? ⇒ Boolean
Ask if chunk has set the prev-inuse bit.
86 87 88 |
# File 'lib/heapinfo/chunk.rb', line 86 def prev_inuse? flags.include? :prev_inuse end |
#size ⇒ Integer
Size of chunk
92 93 94 |
# File 'lib/heapinfo/chunk.rb', line 92 def size @size & -8 end |
#to_s ⇒ String
Hook #to_s for pretty printing
45 46 47 48 49 50 51 52 |
# File 'lib/heapinfo/chunk.rb', line 45 def to_s ret = Helper.color(format("#<%s:%#x>\n", self.class.to_s, @base), sev: :klass) ret += "flags = [#{flags.map { |f| Helper.color(":#{f}", sev: :sym) }.join(',')}]\n" ret += "size = #{Helper.color(format('%#x', size))} (#{bintype})\n" ret += "prev_size = #{Helper.color(format('%#x', @prev_size))}\n" unless flags.include? :prev_inuse ret += "data = #{Helper.color(@data.inspect)}#{'...' if @data.length < size - size_t * 2}\n" ret end |