class Vernier::Collector
def self.new(mode, options = {})
def self.new(mode, options = {}) _new(mode, options) end
def add_marker(name:, start:, finish:, thread: Thread.current.object_id, phase: Marker::Phase::INTERVAL, data: nil)
def add_marker(name:, start:, finish:, thread: Thread.current.object_id, phase: Marker::Phase::INTERVAL, data: nil) @markers << [thread, name, start, finish, phase, data] end
def current_time
integer nanoseconds. It's the same time used by Vernier internals and
This method returns the current time from Process.clock_gettime in
Get the current time.
#
def current_time Process.clock_gettime(Process::CLOCK_MONOTONIC, :nanosecond) end
def initialize(mode)
def initialize(mode) @mode = mode @markers = [] end
def record_interval(category, name = category)
Record an interval with a category and name. Yields to a block and
#
def record_interval(category, name = category) start = current_time yield add_marker( name: category, start:, finish: current_time, phase: Marker::Phase::INTERVAL, thread: Thread.current.object_id, data: { :type => 'UserTiming', :entryType => 'measure', :name => name } ) end
def stop
def stop result = finish end_time = Process.clock_gettime(Process::CLOCK_REALTIME, :nanosecond) result.pid = Process.pid result.end_time = end_time marker_strings = Marker.name_table markers = self.markers.map do |(tid, type, phase, ts, te, stack)| name = marker_strings[type] sym = Marker::MARKER_SYMBOLS[type] data = { type: sym } data[:cause] = { stack: stack } if stack [tid, name, ts, te, phase, data] end markers.concat @markers result.instance_variable_set(:@markers, markers) result end