Class: PhusionPassenger::AnalyticsLogger::Log

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shared_data = nil, txn_id = nil) ⇒ Log

Returns a new instance of Log.



41
42
43
44
45
46
47
# File 'lib/phusion_passenger/analytics_logger.rb', line 41

def initialize(shared_data = nil, txn_id = nil)
	if shared_data
		@shared_data = shared_data
		@txn_id = txn_id
		shared_data.ref
	end
end

Instance Attribute Details

#txn_idObject (readonly)

Returns the value of attribute txn_id.



39
40
41
# File 'lib/phusion_passenger/analytics_logger.rb', line 39

def txn_id
  @txn_id
end

Instance Method Details

#begin_measure(name, extra_info = nil) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/phusion_passenger/analytics_logger.rb', line 61

def begin_measure(name, extra_info = nil)
	if extra_info
		extra_info_base64 = [extra_info].pack("m")
		extra_info_base64.gsub!("\n", "")
		extra_info_base64.strip!
	else
		extra_info_base64 = nil
	end
	times = NativeSupport.process_times
	message "BEGIN: #{name} (#{current_timestamp.to_s(36)},#{times.utime.to_s(36)},#{times.stime.to_s(36)}) #{extra_info_base64}"
end

#close(flush_to_disk = false) ⇒ Object



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/phusion_passenger/analytics_logger.rb', line 108

def close(flush_to_disk = false)
	@shared_data.synchronize do
		@shared_data.client.write("closeTransaction", @txn_id,
			AnalyticsLogger.timestamp_string)
		if flush_to_disk
			@shared_data.client.write("flush")
			result = @shared_data.client.read
			if result != ["ok"]
				raise "Invalid logging server response #{result.inspect} to the 'flush' command"
			end
		end
		@shared_data.unref
		@shared_data = nil
	end if @shared_data
end

#end_measure(name, error_encountered = false) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/phusion_passenger/analytics_logger.rb', line 73

def end_measure(name, error_encountered = false)
	times = NativeSupport.process_times
	if error_encountered
		message "FAIL: #{name} (#{current_timestamp.to_s(36)},#{times.utime.to_s(36)},#{times.stime.to_s(36)})"
	else
		message "END: #{name} (#{current_timestamp.to_s(36)},#{times.utime.to_s(36)},#{times.stime.to_s(36)})"
	end
end

#measure(name, extra_info = nil) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
# File 'lib/phusion_passenger/analytics_logger.rb', line 82

def measure(name, extra_info = nil)
	begin_measure(name, extra_info)
	begin
		yield
	rescue Exception
		error = true
		raise
	ensure
		end_measure(name, error)
	end
end

#measured_time_points(name, begin_time, end_time, extra_info = nil) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/phusion_passenger/analytics_logger.rb', line 94

def measured_time_points(name, begin_time, end_time, extra_info = nil)
	if extra_info
		extra_info_base64 = [extra_info].pack("m")
		extra_info_base64.gsub!("\n", "")
		extra_info_base64.strip!
	else
		extra_info_base64 = nil
	end
	begin_timestamp = begin_time.to_i * 1_000_000 + begin_time.usec
	end_timestamp = end_time.to_i * 1_000_000 + end_time.usec
	message "BEGIN: #{name} (#{begin_timestamp.to_s(36)}) #{extra_info_base64}"
	message "END: #{name} (#{end_timestamp.to_s(36)})"
end

#message(text) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/phusion_passenger/analytics_logger.rb', line 53

def message(text)
	@shared_data.synchronize do
		@shared_data.client.write("log", @txn_id,
			AnalyticsLogger.timestamp_string)
		@shared_data.client.write_scalar(text)
	end if @shared_data
end

#null?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/phusion_passenger/analytics_logger.rb', line 49

def null?
	return !@shared_data
end