Class: PLogger

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PLogger

Returns a new instance of PLogger.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 9

def initialize(options = {})
  system('mkdir -p log/schwad_performance_logger')
  filename = "./log/schwad_performance_logger/performance-#{Time.now.strftime("%e-%m_%l:%M%p")}.log"
  File.write(filename, "")
  initialize_csv
  @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.



6
7
8
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 6

def current_memory
  @current_memory
end

#current_timeObject

Returns the value of attribute current_time.



6
7
8
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 6

def current_time
  @current_time
end

#delta_memoryObject

Returns the value of attribute delta_memory.



6
7
8
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 6

def delta_memory
  @delta_memory
end

#delta_timeObject

Returns the value of attribute delta_time.



6
7
8
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 6

def delta_time
  @delta_time
end

#initial_memoryObject

Returns the value of attribute initial_memory.



6
7
8
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 6

def initial_memory
  @initial_memory
end

#initial_timeObject

Returns the value of attribute initial_time.



6
7
8
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 6

def initial_time
  @initial_time
end

#last_memoryObject

Returns the value of attribute last_memory.



6
7
8
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 6

def last_memory
  @last_memory
end

#last_timeObject

Returns the value of attribute last_time.



6
7
8
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 6

def last_time
  @last_time
end

#loggerObject

Returns the value of attribute logger.



6
7
8
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 6

def logger
  @logger
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 7

def options
  @options
end

#second_delta_memoryObject

Returns the value of attribute second_delta_memory.



6
7
8
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 6

def second_delta_memory
  @second_delta_memory
end

#second_delta_timeObject

Returns the value of attribute second_delta_time.



6
7
8
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 6

def second_delta_time
  @second_delta_time
end

#sleep_adjusterObject

Returns the value of attribute sleep_adjuster.



6
7
8
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 6

def sleep_adjuster
  @sleep_adjuster
end

#sleep_amountObject

Returns the value of attribute sleep_amount.



6
7
8
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 6

def sleep_amount
  @sleep_amount
end

Instance Method Details

#log_performance(memo = nil, minimal: false) ⇒ Object Also known as: log, lp



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/schwad_performance_logger/schwad_performance_logger.rb', line 29

def log_performance(memo = nil, minimal: false)
  if block_given?
    update_checks
    yield
    update_checks
    puts_performance("After: #{memo}", gblock: true, minimal: minimal) unless @options[:puts] == false
    logger_performance("After: #{memo}") unless @options[:log] == false
    csv_performance("After: #{memo}") unless @options[:csv] == false
  else
    update_checks
    puts_performance(memo, minimal: minimal) unless @options[:puts] == false
    logger_performance(memo) unless @options[:log] == false
    csv_performance(memo) unless @options[:csv] == false
  end
  sleep @sleep_amount
end