Class: Tracebin::Timer

Inherits:
Object
  • Object
show all
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

BackgroundTimer

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#eventsObject (readonly)

Returns the value of attribute events.



13
14
15
# File 'lib/tracebin/timer.rb', line 13

def events
  @events
end

#transaction_nameObject

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

#durationObject



49
50
51
# File 'lib/tracebin/timer.rb', line 49

def duration
  milliseconds_between @stop_time, @start_time
end

#payloadObject



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 = timestamp_string
  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 = timestamp_string
end

#transaction_typeObject



53
54
55
# File 'lib/tracebin/timer.rb', line 53

def transaction_type
  'request_response'
end