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 ...

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, Printer, RSpecListener, RssPrinter, RssTracker, Tracker

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.configObject



56
57
58
# File 'lib/test_prof/memory_prof.rb', line 56

def config
  @config ||= Configuration.new
end

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

Yields:



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

def configure
  yield config
end

.printer(tracker) ⇒ Object



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

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

.trackerObject



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

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