Class: HeapProfiler::AbstractResults

Inherits:
Object
  • Object
show all
Defined in:
lib/heap_profiler/results.rb

Direct Known Subclasses

DiffResults, HeapResults

Constant Summary collapse

UNIT_PREFIXES =
{
  0 => 'B',
  3 => 'kB',
  6 => 'MB',
  9 => 'GB',
  12 => 'TB',
  15 => 'PB',
  18 => 'EB',
  21 => 'ZB',
  24 => 'YB',
}.freeze
METRICS =
["memory", "objects", "strings", "shape_edges"].freeze
GROUPED_METRICS =
["memory", "objects"]
GROUPINGS =
["gem", "file", "location", "class"].freeze

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAbstractResults

Returns a new instance of AbstractResults.

Raises:

  • (NotImplementedError)


28
29
30
# File 'lib/heap_profiler/results.rb', line 28

def initialize(*, **)
  raise NotImplementedError
end

Class Attribute Details

.top_entries_countObject

Returns the value of attribute top_entries_count.



25
26
27
# File 'lib/heap_profiler/results.rb', line 25

def top_entries_count
  @top_entries_count
end

Instance Attribute Details

#dimensionsObject (readonly)

Returns the value of attribute dimensions.



21
22
23
# File 'lib/heap_profiler/results.rb', line 21

def dimensions
  @dimensions
end

#typesObject (readonly)

Returns the value of attribute types.



21
22
23
# File 'lib/heap_profiler/results.rb', line 21

def types
  @types
end

Instance Method Details

#normalize_path(path) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/heap_profiler/results.rb', line 46

def normalize_path(path)
  @normalize_path ||= {}
  @normalize_path[path] ||= begin
    if %r!(/gems/.*)*/gems/(?<gemname>[^/]+)(?<rest>.*)! =~ path
      "#{gemname}#{rest}"
    elsif %r!ruby/2\.[^/]+/(?<stdlib>[^/.]+)(?<rest>.*)! =~ path
      "ruby/lib/#{stdlib}#{rest}"
    elsif %r!(?<app>[^/]+/(bin|app|lib))(?<rest>.*)! =~ path
      "#{app}#{rest}"
    else
      path
    end
  end
end


38
39
40
# File 'lib/heap_profiler/results.rb', line 38

def print_output(io, topic, detail)
  io.puts "#{@colorize.path(topic.to_s.rjust(10))}  #{detail}"
end


42
43
44
# File 'lib/heap_profiler/results.rb', line 42

def print_output2(io, topic1, topic2, detail)
  io.puts "#{@colorize.path(topic1.to_s.rjust(10))}  #{@colorize.path(topic2.to_s.rjust(6))}  #{detail}"
end


32
33
34
35
36
# File 'lib/heap_profiler/results.rb', line 32

def print_title(io, title)
  io.puts
  io.puts title
  io.puts @colorize.line("-----------------------------------")
end

#scale_bytes(bytes) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/heap_profiler/results.rb', line 61

def scale_bytes(bytes)
  return "0 B" if bytes.zero?

  scale = Math.log10(bytes).div(3) * 3
  scale = 24 if scale > 24
  format("%.2f #{UNIT_PREFIXES[scale]}", (bytes / 10.0**scale))
end