Class: Hone::HarnessRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/hone/harness_runner.rb

Constant Summary collapse

PROFILE_DIR =
"tmp/hone"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(harness_path, options = {}) ⇒ HarnessRunner

Returns a new instance of HarnessRunner.



12
13
14
15
16
17
18
# File 'lib/hone/harness_runner.rb', line 12

def initialize(harness_path, options = {})
  @harness_path = harness_path
  @profiler = options[:profiler] || detect_profiler
  @include_memory = options.fetch(:memory, false)
  @warmup = options.fetch(:warmup, 10)
  @output_dir = options.fetch(:output_dir, PROFILE_DIR)
end

Instance Attribute Details

#harness_pathObject (readonly)

Returns the value of attribute harness_path.



10
11
12
# File 'lib/hone/harness_runner.rb', line 10

def harness_path
  @harness_path
end

#include_memoryObject (readonly)

Returns the value of attribute include_memory.



10
11
12
# File 'lib/hone/harness_runner.rb', line 10

def include_memory
  @include_memory
end

#output_dirObject (readonly)

Returns the value of attribute output_dir.



10
11
12
# File 'lib/hone/harness_runner.rb', line 10

def output_dir
  @output_dir
end

#profilerObject (readonly)

Returns the value of attribute profiler.



10
11
12
# File 'lib/hone/harness_runner.rb', line 10

def profiler
  @profiler
end

#warmupObject (readonly)

Returns the value of attribute warmup.



10
11
12
# File 'lib/hone/harness_runner.rb', line 10

def warmup
  @warmup
end

Instance Method Details

#runObject



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/hone/harness_runner.rb', line 20

def run
  harness = Harness.load(@harness_path)

  unless harness.valid?
    raise Hone::Error, "Harness must define an exercise block"
  end

  FileUtils.mkdir_p(@output_dir)

  # Setup phase (not profiled)
  harness.run_setup

  # Warmup phase (not profiled, lets JIT optimize)
  @warmup.times { harness.run_exercise }

  # Profile CPU
  cpu_path = profile_cpu(harness)

  # Profile memory (if requested)
  memory_path = @include_memory ? profile_memory(harness) : nil

  # Teardown phase
  harness.run_teardown

  # Write metadata
  (cpu_path, memory_path, harness.iterations)

  {cpu: cpu_path, memory: memory_path}
end