Class: PLogger
- Inherits:
-
Object
- Object
- PLogger
- 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
-
#current_memory ⇒ Object
Returns the value of attribute current_memory.
-
#current_time ⇒ Object
Returns the value of attribute current_time.
-
#delta_memory ⇒ Object
Returns the value of attribute delta_memory.
-
#delta_time ⇒ Object
Returns the value of attribute delta_time.
-
#initial_memory ⇒ Object
Returns the value of attribute initial_memory.
-
#initial_time ⇒ Object
Returns the value of attribute initial_time.
-
#last_memory ⇒ Object
Returns the value of attribute last_memory.
-
#last_time ⇒ Object
Returns the value of attribute last_time.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#second_delta_memory ⇒ Object
Returns the value of attribute second_delta_memory.
-
#second_delta_time ⇒ Object
Returns the value of attribute second_delta_time.
-
#sleep_adjuster ⇒ Object
Returns the value of attribute sleep_adjuster.
-
#sleep_amount ⇒ Object
Returns the value of attribute sleep_amount.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ PLogger
constructor
A new instance of PLogger.
- #log_performance(memo = nil) ⇒ Object
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( = {} ) 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 = @sleep_amount = [: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_memory ⇒ Object
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_time ⇒ Object
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_memory ⇒ Object
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_time ⇒ Object
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_memory ⇒ Object
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_time ⇒ Object
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_memory ⇒ Object
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_time ⇒ Object
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 |
#logger ⇒ Object
Returns the value of attribute logger.
15 16 17 |
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 15 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 17 def @options end |
#second_delta_memory ⇒ Object
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_time ⇒ Object
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_adjuster ⇒ Object
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_amount ⇒ Object
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 |