Class: Tracebin::Timer
- Inherits:
-
Object
- Object
- Tracebin::Timer
- Includes:
- Helpers
- Defined in:
- lib/tracebin/timer.rb
Overview
This is the timer for a top-level transaction. Transactions include request/response cycles, as well as background jobs. Background jobs subclass this class and overwrite the #transaction_type
method.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#transaction_name ⇒ Object
Returns the value of attribute transaction_name.
Instance Method Summary collapse
- #duration ⇒ Object
-
#initialize(transaction_name = nil) ⇒ Timer
constructor
A new instance of Timer.
- #payload ⇒ Object
- #start! ⇒ Object
- #stop! ⇒ Object
- #transaction_type ⇒ Object
Methods included from Helpers
#deserialize_time_string, #milliseconds_between, #time_to_string, #timestamp_string, #to_milliseconds
Constructor Details
#initialize(transaction_name = nil) ⇒ Timer
Returns a new instance of Timer.
15 16 17 18 19 |
# File 'lib/tracebin/timer.rb', line 15 def initialize(transaction_name = nil) @transaction_name = transaction_name @start_time = nil @stop_time = nil end |
Instance Attribute Details
#events ⇒ Object (readonly)
Returns the value of attribute events.
13 14 15 |
# File 'lib/tracebin/timer.rb', line 13 def events @events end |
#transaction_name ⇒ Object
Returns the value of attribute transaction_name.
12 13 14 |
# File 'lib/tracebin/timer.rb', line 12 def transaction_name @transaction_name end |
Instance Method Details
#duration ⇒ Object
49 50 51 |
# File 'lib/tracebin/timer.rb', line 49 def duration milliseconds_between @stop_time, @start_time end |
#payload ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/tracebin/timer.rb', line 32 def payload { type: :cycle_transaction, data: { transaction_type: transaction_type, name: @transaction_name, start: @start_time, stop: @stop_time, duration: duration, events: @events } } end |
#start! ⇒ Object
21 22 23 24 |
# File 'lib/tracebin/timer.rb', line 21 def start! @start_time = Recorder.start_recording end |
#stop! ⇒ Object
26 27 28 29 30 |
# File 'lib/tracebin/timer.rb', line 26 def stop! collect_events Recorder.stop_recording @stop_time = end |
#transaction_type ⇒ Object
53 54 55 |
# File 'lib/tracebin/timer.rb', line 53 def transaction_type 'request_response' end |