Class: Protobuf::Rpc::Stat

Inherits:
Object
  • Object
show all
Defined in:
lib/protobuf/rpc/stat.rb

Constant Summary collapse

TYPES =
[:SERVER, :CLIENT]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type = :SERVER, do_start = true) ⇒ Stat

Returns a new instance of Stat.



11
12
13
14
# File 'lib/protobuf/rpc/stat.rb', line 11

def initialize type=:SERVER, do_start=true
  @type = type
  start if do_start
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



7
8
9
# File 'lib/protobuf/rpc/stat.rb', line 7

def client
  @client
end

#end_timeObject

Returns the value of attribute end_time.



7
8
9
# File 'lib/protobuf/rpc/stat.rb', line 7

def end_time
  @end_time
end

#methodObject

Returns the value of attribute method.



7
8
9
# File 'lib/protobuf/rpc/stat.rb', line 7

def method
  @method
end

#request_sizeObject

Returns the value of attribute request_size.



7
8
9
# File 'lib/protobuf/rpc/stat.rb', line 7

def request_size
  @request_size
end

#response_sizeObject

Returns the value of attribute response_size.



7
8
9
# File 'lib/protobuf/rpc/stat.rb', line 7

def response_size
  @response_size
end

#serverObject

Returns the value of attribute server.



7
8
9
# File 'lib/protobuf/rpc/stat.rb', line 7

def server
  @server
end

#serviceObject

Returns the value of attribute service.



7
8
9
# File 'lib/protobuf/rpc/stat.rb', line 7

def service
  @service
end

#start_timeObject

Returns the value of attribute start_time.



7
8
9
# File 'lib/protobuf/rpc/stat.rb', line 7

def start_time
  @start_time
end

#typeObject

Returns the value of attribute type.



7
8
9
# File 'lib/protobuf/rpc/stat.rb', line 7

def type
  @type
end

Instance Method Details

#elapsed_timeObject



49
50
51
# File 'lib/protobuf/rpc/stat.rb', line 49

def elapsed_time
  (start_time && end_time ? '%ss' % (end_time - start_time).round(4) : nil)
end

#endObject



40
41
42
43
# File 'lib/protobuf/rpc/stat.rb', line 40

def end
  start if !@start_time
  @end_time ||= Time.now
end

#log_statsObject



53
54
55
# File 'lib/protobuf/rpc/stat.rb', line 53

def log_stats
  Protobuf::Logger.info(self.to_s)
end

#rpcObject



45
46
47
# File 'lib/protobuf/rpc/stat.rb', line 45

def rpc
  service && method ? '%s#%s' % [service, method] : nil
end

#sizesObject



32
33
34
# File 'lib/protobuf/rpc/stat.rb', line 32

def sizes
  '%dB/%dB' % [@request_size || 0, @response_size || 0]
end

#startObject



36
37
38
# File 'lib/protobuf/rpc/stat.rb', line 36

def start
  @start_time ||= Time.now
end

#to_sObject



57
58
59
60
61
62
63
64
65
# File 'lib/protobuf/rpc/stat.rb', line 57

def to_s
  [
    @type == :SERVER ? "[SRV-#{self.class}]" : "[CLT-#{self.class}]",
    rpc,
    elapsed_time,
    sizes,
    @type == :SERVER ? server : client
  ].delete_if{|v| v.nil? }.join(' - ')
end