class PigCI::Profiler
Attributes
historical_log_file[RW]
i18n_key[RW]
log_file[RW]
log_value[RW]
Public Class Methods
new(i18n_key: nil, log_file: nil, historical_log_file: nil)
click to toggle source
# File lib/pig_ci/profiler.rb, line 4 def initialize(i18n_key: nil, log_file: nil, historical_log_file: nil) @i18n_key = i18n_key || self.class.name.underscore.split("/").last @log_file = log_file || PigCI.tmp_directory.join("#{@i18n_key}.txt") @historical_log_file = historical_log_file || PigCI.tmp_directory.join("#{@i18n_key}.json") @log_value = 0 end
Public Instance Methods
increment!(*)
click to toggle source
# File lib/pig_ci/profiler.rb, line 34 def increment!(*) raise NotImplementedError end
log_request!(request_key)
click to toggle source
# File lib/pig_ci/profiler.rb, line 19 def log_request!(request_key) File.open(log_file, "a+") do |f| f.puts([request_key, log_value].join("|")) end end
reset!()
click to toggle source
# File lib/pig_ci/profiler.rb, line 15 def reset! @log_value = 0 end
save!()
click to toggle source
# File lib/pig_ci/profiler.rb, line 25 def save! historical_data = PigCI::Metric::Historical.new(historical_log_file: @historical_log_file) historical_data.add_change_percentage_and_append!( timestamp: PigCI.run_timestamp, metric: i18n_key, data: PigCI::Metric::Current.new(log_file: log_file).to_h ) end
setup!()
click to toggle source
# File lib/pig_ci/profiler.rb, line 11 def setup! File.open(log_file, "w") { |file| file.truncate(0) } end