Sha256: 7096f5e47962ef53749d5edb072ac6ad5927ab780894c14a4ab74c098b0accbc

Contents?: true

Size: 890 Bytes

Versions: 2

Compression:

Stored size: 890 Bytes

Contents

require 'whysoslow/results'

module Whysoslow

  class Runner

    attr_accessor :desc, :verbose, :time_unit, :memory_unit

    def initialize(printer, opts={})
      @printer = printer
      @time_unit = opts[:time_unit]
      @memory_unit = opts[:memory_unit]
      @results = nil
    end

    def run(&block)
      @printer.print :title
      @printer.print(Results.new(@desc, @time_unit, @memory_unit).tap do |results|
        @results = results
        @printer.print :run_start
        self.snapshot('start')
        @results.benchmark(&block)
        self.snapshot('finish')
        @printer.print :run_end
        @results = nil
      end)
    end

    def snapshot(*args)
      raise RuntimeError, "no active results being gathered - be sure and call snapshot during a run session" if @results.nil?
      @results.snapshot(*args)
      @printer.print :snapshot
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
whysoslow-0.0.2 lib/whysoslow/runner.rb
whysoslow-0.0.1 lib/whysoslow/runner.rb