Class: Protobuf::Rpc::Stat
- Inherits:
-
Object
- Object
- Protobuf::Rpc::Stat
- Defined in:
- lib/protobuf/rpc/stat.rb
Constant Summary collapse
- TYPES =
[:SERVER, :CLIENT]
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#end_time ⇒ Object
Returns the value of attribute end_time.
-
#method ⇒ Object
Returns the value of attribute method.
-
#request_size ⇒ Object
Returns the value of attribute request_size.
-
#response_size ⇒ Object
Returns the value of attribute response_size.
-
#server ⇒ Object
Returns the value of attribute server.
-
#service ⇒ Object
Returns the value of attribute service.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #elapsed_time ⇒ Object
- #end ⇒ Object
-
#initialize(type = :SERVER, do_start = true) ⇒ Stat
constructor
A new instance of Stat.
- #log_stats ⇒ Object
- #rpc ⇒ Object
- #sizes ⇒ Object
- #start ⇒ Object
- #to_s ⇒ Object
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
#client ⇒ Object
Returns the value of attribute client.
7 8 9 |
# File 'lib/protobuf/rpc/stat.rb', line 7 def client @client end |
#end_time ⇒ Object
Returns the value of attribute end_time.
7 8 9 |
# File 'lib/protobuf/rpc/stat.rb', line 7 def end_time @end_time end |
#method ⇒ Object
Returns the value of attribute method.
7 8 9 |
# File 'lib/protobuf/rpc/stat.rb', line 7 def method @method end |
#request_size ⇒ Object
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_size ⇒ Object
Returns the value of attribute response_size.
7 8 9 |
# File 'lib/protobuf/rpc/stat.rb', line 7 def response_size @response_size end |
#server ⇒ Object
Returns the value of attribute server.
7 8 9 |
# File 'lib/protobuf/rpc/stat.rb', line 7 def server @server end |
#service ⇒ Object
Returns the value of attribute service.
7 8 9 |
# File 'lib/protobuf/rpc/stat.rb', line 7 def service @service end |
#start_time ⇒ Object
Returns the value of attribute start_time.
7 8 9 |
# File 'lib/protobuf/rpc/stat.rb', line 7 def start_time @start_time end |
#type ⇒ Object
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_time ⇒ Object
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 |
#end ⇒ Object
40 41 42 43 |
# File 'lib/protobuf/rpc/stat.rb', line 40 def end start if !@start_time @end_time ||= Time.now end |
#log_stats ⇒ Object
53 54 55 |
# File 'lib/protobuf/rpc/stat.rb', line 53 def log_stats Protobuf::Logger.info(self.to_s) end |
#rpc ⇒ Object
45 46 47 |
# File 'lib/protobuf/rpc/stat.rb', line 45 def rpc service && method ? '%s#%s' % [service, method] : nil end |
#sizes ⇒ Object
32 33 34 |
# File 'lib/protobuf/rpc/stat.rb', line 32 def sizes '%dB/%dB' % [@request_size || 0, @response_size || 0] end |
#start ⇒ Object
36 37 38 |
# File 'lib/protobuf/rpc/stat.rb', line 36 def start @start_time ||= Time.now end |
#to_s ⇒ Object
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 |