Class: PLogger

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

Overview

Logs performance during life of the object. Defaults to a trifecta of ‘puts` output as well as logging to CSV (in the root folder) and `log/schwad_performance_logger` for traditional info-level logging. It also gives timing and memory usage info. Options include disabling extra logging, including a ’sleep’ parameter to have the application pause at each output (so your puts info is not drowned). This does not impact the time output

It also puts out delta memory and time so you can see ‘between-log’ spikes.

This is stored in the system as ‘second_delta’

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PLogger

Returns a new instance of PLogger.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 19

def initialize( options = {} )
  system('mkdir log')
  system('mkdir log/schwad_performance_logger')
  filename = "./log/schwad_performance_logger/performance-#{Time.now.strftime("%e-%m_%l:%M%p")}.log"
  File.write(filename, "")
  another_empty_csv_row
  @logger = Logger.new(filename)
  @options = options
  @sleep_amount = options[:pause].to_i
  @initial_memory = GetProcessMem.new.mb.round
  @current_memory = @initial_memory
  @delta_memory = 0
  @delta_time = 0
  @initial_time = Time.now
  @current_time = @initial_time
  @last_time = @initial_time
  @last_memory = @initial_memory
  @sleep_adjuster = -@sleep_amount #This is to remove the sleeps for performance checking.
  log_performance('initialization')
end

Instance Attribute Details

#current_memoryObject

Returns the value of attribute current_memory.



15
16
17
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 15

def current_memory
  @current_memory
end

#current_timeObject

Returns the value of attribute current_time.



15
16
17
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 15

def current_time
  @current_time
end

#delta_memoryObject

Returns the value of attribute delta_memory.



15
16
17
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 15

def delta_memory
  @delta_memory
end

#delta_timeObject

Returns the value of attribute delta_time.



15
16
17
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 15

def delta_time
  @delta_time
end

#initial_memoryObject

Returns the value of attribute initial_memory.



15
16
17
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 15

def initial_memory
  @initial_memory
end

#initial_timeObject

Returns the value of attribute initial_time.



15
16
17
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 15

def initial_time
  @initial_time
end

#last_memoryObject

Returns the value of attribute last_memory.



15
16
17
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 15

def last_memory
  @last_memory
end

#last_timeObject

Returns the value of attribute last_time.



15
16
17
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 15

def last_time
  @last_time
end

#loggerObject

Returns the value of attribute logger.



15
16
17
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 15

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



17
18
19
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 17

def options
  @options
end

#second_delta_memoryObject

Returns the value of attribute second_delta_memory.



15
16
17
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 15

def second_delta_memory
  @second_delta_memory
end

#second_delta_timeObject

Returns the value of attribute second_delta_time.



15
16
17
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 15

def second_delta_time
  @second_delta_time
end

#sleep_adjusterObject

Returns the value of attribute sleep_adjuster.



15
16
17
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 15

def sleep_adjuster
  @sleep_adjuster
end

#sleep_amountObject

Returns the value of attribute sleep_amount.



15
16
17
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 15

def sleep_amount
  @sleep_amount
end

Instance Method Details

#log_performance(memo = nil) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 40

def log_performance(memo=nil)
  update_checks
  puts_performance(memo) unless @options[:puts] == false
  logger_performance(memo) unless @options[:log] == false
  csv_performance(memo) unless @options[:csv] == false
  sleep @sleep_amount
end