Module: TestProf::MemoryProf

Defined in:
lib/test_prof/memory_prof.rb,
lib/test_prof/memory_prof/rspec.rb,
lib/test_prof/memory_prof/printer.rb,
lib/test_prof/memory_prof/tracker.rb,
lib/test_prof/memory_prof/tracker/rss_tool.rb,
lib/test_prof/memory_prof/tracker/linked_list.rb,
lib/test_prof/memory_prof/printer/number_to_human.rb

Overview

MemoryProf can help in detecting test examples causing memory spikes. It supports two metrics: RSS and allocations.

Example:

TEST_MEM_PROF='rss' rspec ...
TEST_MEM_PROF='alloc' rspec ...
TEST_MEM_PROF='gc' rspec ...

By default MemoryProf shows the top 5 examples and groups (for RSpec) but you can set how many items to display with TEST_MEM_PROF_COUNT:

TEST_MEM_PROF='rss' TEST_MEM_PROF_COUNT=10 rspec ...

The examples block shows the amount of memory used by each example, and the groups block displays the memory allocated by other code defined in the groups. For example, RSpec groups may include heavy ‘before(:all)` (or before_all) setup blocks, so it is helpful to see which groups use the most amount of memory outside of their examples.

Defined Under Namespace

Classes: AllocPrinter, AllocTracker, Configuration, GCPrinter, GCTracker, Printer, RSpecListener, RssPrinter, RssTracker, Tracker

Constant Summary collapse

TRACKERS =
{
  alloc: AllocTracker,
  rss: RssTracker,
  gc: GCTracker
}.freeze
PRINTERS =
{
  alloc: AllocPrinter,
  rss: RssPrinter,
  gc: GCPrinter
}.freeze

Class Method Summary collapse

Class Method Details

.configObject



61
62
63
# File 'lib/test_prof/memory_prof.rb', line 61

def config
  @config ||= Configuration.new
end

.configure {|config| ... } ⇒ Object

Yields:



65
66
67
# File 'lib/test_prof/memory_prof.rb', line 65

def configure
  yield config
end

.printer(tracker) ⇒ Object



74
75
76
77
# File 'lib/test_prof/memory_prof.rb', line 74

def printer(tracker)
  printer = PRINTERS[config.mode]
  printer.new(tracker)
end

.trackerObject



69
70
71
72
# File 'lib/test_prof/memory_prof.rb', line 69

def tracker
  tracker = TRACKERS[config.mode]
  tracker.new(config.top_count)
end