Class: BenchBloc::Logger::RubyProf

Inherits:
BenchBloc::Logger show all
Defined in:
lib/bench_bloc/logger/ruby_prof.rb

Instance Attribute Summary

Attributes inherited from BenchBloc::Logger

#results, #title

Instance Method Summary collapse

Methods inherited from BenchBloc::Logger

#initialize

Constructor Details

This class inherits a constructor from BenchBloc::Logger

Instance Method Details

#log_resultsObject



4
5
6
7
8
9
# File 'lib/bench_bloc/logger/ruby_prof.rb', line 4

def log_results
  formatted_results = BenchBloc::Formatter::RubyProf
                      .new(results, title)
                      .format_results
  write_to_log formatted_results
end

#write_to_log(results) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/bench_bloc/logger/ruby_prof.rb', line 11

def write_to_log results
  if defined?(Rails)
    printer = ::RubyProf::FlatPrinter.new(results)
    File.open("#{Rails.root}/log/bench_bloc_ruby-prof.log", 'w') { |file|
      printer.print(file)
    }
  else
    printer = ::RubyProf::FlatPrinter.new(results)
    File.open("log/bench_bloc_ruby-prof.log", "w") { |file|
      printer.print(file)
    }
  end
end