Class | PhusionPassenger::AnalyticsLogger::Log
In: | lib/phusion_passenger/analytics_logger.rb
Parent: | Object

### Methods

begin_measure close end_measure measure measured_time_points message new null?

### Attributes

txn_id | [R] |

### Public Class methods

new(shared_data = nil, txn_id = nil)

[Source]

        # File lib/phusion_passenger/analytics_logger.rb, line 41
    41:                 def initialize(shared_data = nil, txn_id = nil)
    42:                         if shared_data
    43:                                 @shared_data = shared_data
    44:                                 @txn_id = txn_id
    45:                                 shared_data.ref
    46:                         end
    47:                 end

### Public Instance methods

begin_measure(name, extra_info = nil)

[Source]

        # File lib/phusion_passenger/analytics_logger.rb, line 61
    61:                 def begin_measure(name, extra_info = nil)
    62:                         if extra_info
    63:                                 extra_info_base64 = [extra_info].pack("m")
    64:                                 extra_info_base64.gsub!("\n", "")
    65:                                 extra_info_base64.strip!
    66:                         else
    67:                                 extra_info_base64 = nil
    68:                         end
    69:                         times = NativeSupport.process_times
    70:                         message "BEGIN: #{name} (#{current_timestamp.to_s(36)},#{times.utime.to_s(36)},#{times.stime.to_s(36)}) #{extra_info_base64}"
    71:                 end

close(flush_to_disk = false)

[Source]

         # File lib/phusion_passenger/analytics_logger.rb, line 108
    108:                 def close(flush_to_disk = false)
    109:                         @shared_data.synchronize do
    110:                                 @shared_data.client.write("closeTransaction", @txn_id,
    111:                                         AnalyticsLogger.timestamp_string)
    112:                                 if flush_to_disk
    113:                                         @shared_data.client.write("flush")
    114:                                         result = @shared_data.client.read
    115:                                         if result != ["ok"]
    116:                                                 raise "Invalid logging server response #{result.inspect} to the 'flush' command"
    117:                                         end
    118:                                 end
    119:                                 @shared_data.unref
    120:                                 @shared_data = nil
    121:                         end if @shared_data
    122:                 end

end_measure(name, error_encountered = false)

[Source]

        # File lib/phusion_passenger/analytics_logger.rb, line 73
    73:                 def end_measure(name, error_encountered = false)
    74:                         times = NativeSupport.process_times
    75:                         if error_encountered
    76:                                 message "FAIL: #{name} (#{current_timestamp.to_s(36)},#{times.utime.to_s(36)},#{times.stime.to_s(36)})"
    77:                         else
    78:                                 message "END: #{name} (#{current_timestamp.to_s(36)},#{times.utime.to_s(36)},#{times.stime.to_s(36)})"
    79:                         end
    80:                 end

measure(name, extra_info = nil) {|| ...}

[Source]

        # File lib/phusion_passenger/analytics_logger.rb, line 82
    82:                 def measure(name, extra_info = nil)
    83:                         begin_measure(name, extra_info)
    84:                         begin
    85:                                 yield
    86:                         rescue Exception
    87:                                 error = true
    88:                                 raise
    89:                         ensure
    90:                                 end_measure(name, error)
    91:                         end
    92:                 end

measured_time_points(name, begin_time, end_time, extra_info = nil)

[Source]

         # File lib/phusion_passenger/analytics_logger.rb, line 94
     94:                 def measured_time_points(name, begin_time, end_time, extra_info = nil)
     95:                         if extra_info
     96:                                 extra_info_base64 = [extra_info].pack("m")
     97:                                 extra_info_base64.gsub!("\n", "")
     98:                                 extra_info_base64.strip!
     99:                         else
    100:                                 extra_info_base64 = nil
    101:                         end
    102:                         begin_timestamp = begin_time.to_i * 1_000_000 + begin_time.usec
    103:                         end_timestamp = end_time.to_i * 1_000_000 + end_time.usec
    104:                         message "BEGIN: #{name} (#{begin_timestamp.to_s(36)}) #{extra_info_base64}"
    105:                         message "END: #{name} (#{end_timestamp.to_s(36)})"
    106:                 end

message(text)

[Source]

        # File lib/phusion_passenger/analytics_logger.rb, line 53
    53:                 def message(text)
    54:                         @shared_data.synchronize do
    55:                                 @shared_data.client.write("log", @txn_id,
    56:                                         AnalyticsLogger.timestamp_string)
    57:                                 @shared_data.client.write_scalar(text)
    58:                         end if @shared_data
    59:                 end

null?()

[Source]

        # File lib/phusion_passenger/analytics_logger.rb, line 49
    49:                 def null?
    50:                         return !@shared_data
    51:                 end

[Validate]