class BenchBloc::Logger
Attributes
results[R]
title[R]
Public Class Methods
new(results, title)
click to toggle source
# File lib/bench_bloc/logger/logger.rb, line 5 def initialize results, title @results, @title = results, title end
Public Instance Methods
log_results()
click to toggle source
TODO: Split into a BenchmarkLogger class
# File lib/bench_bloc/logger/logger.rb, line 10 def log_results results.sort! { |a, b| b.real <=> a.real } formatted_results = BenchBloc::Formatter::Benchmark.new(results, title).format_results write_to_log formatted_results end
write_to_log(results)
click to toggle source
# File lib/bench_bloc/logger/logger.rb, line 17 def write_to_log results if defined?(Rails) # Rails Logger not working, naming conflict I think, # or it needs to be required # log = Rails::Logger.new("#{Rails.root}/log/benchmarks.log") # log.info(results) f = File.new("#{Rails.root}/log/benchmarks.log", "w") f.puts(results) f.close else f = File.new("benchmarks.log", "w") f.puts(results) f.puts(parse_db_logger) f.close end end
Private Instance Methods
parse_db_logger()
click to toggle source
# File lib/bench_bloc/logger/logger.rb, line 36 def parse_db_logger if defined?(Rails) log_data = File.read("#{Rails.root}/log/db-queries.log").split("\n") base_aggregator = { SELECT: 0, INSERT: 0, UPDATE: 0, DELETE: 0 } query_data = log_data.reduce(base_aggregator) do |agg, ld| sql_verb = ld[/SELECT|INSERT|UPDATE|DELETE/] agg[sql_verb.to_sym] += 1 if sql_verb.present? agg end end end