Sha256: 63463f9faa832e984f7c4f29b4e4661a2f1f15f31c476cd0392184010b9f9fbb

Contents?: true

Size: 1018 Bytes

Versions: 1

Compression:

Stored size: 1018 Bytes

Contents

require 'vizsla/recorder'
require 'vizsla/helpers'


module Vizsla
  class Timer
    include ::Vizsla::Helpers

    attr_accessor :transaction_name
    attr_reader :events

    def initialize(transaction_name = nil)
      @transaction_name = transaction_name
      @start_time = nil
      @stop_time = nil
    end

    def start!
      @start_time = Time.now
      Recorder.start_recording
    end

    def stop!
      collect_events
      Recorder.stop_recording
      @stop_time = Time.now
    end

    def payload
      {
        type: :cycle_transaction,

        data: {
          transaction_type: transaction_type,
          name: @transaction_name,

          start: @start_time,
          stop: @stop_time,
          duration: duration,

          events: @events
        }
      }
    end

    def duration
      to_milliseconds @stop_time - @start_time
    end

    def transaction_type
      'request_response'
    end

    private

    def collect_events
      @events = Recorder.events
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tracebin-0.0.7 lib/vizsla/timer.rb