跳到内容 跳到搜索

仪器存储在线程本地。

方法
B
F
I
N
S

属性

[R] id

类公共方法

new(notifier)

# File activesupport/lib/active_support/notifications/instrumenter.rb, line 12
def initialize(notifier)
  unless notifier.respond_to?(:build_handle)
    notifier = LegacyHandle::Wrapper.new(notifier)
  end

  @id       = unique_id
  @notifier = notifier
end

实例公共方法

build_handle(name, payload)

返回一个具有给定namepayload的事件的“句柄”。

startfinish必须在返回的对象上分别调用一次。

尽可能地,最好使用instrument,它将记录事件的开始和结束,并正确处理任何异常。build_handle是一个低级 API,用于无法使用instrument的情况。

查看ActiveSupport::Notifications::Fanout::Handle

# File activesupport/lib/active_support/notifications/instrumenter.rb, line 78
def build_handle(name, payload)
  @notifier.build_handle(name, @id, payload)
end

finish(name, payload)

使用namepayload发送完成通知。

# File activesupport/lib/active_support/notifications/instrumenter.rb, line 92
def finish(name, payload)
  @notifier.finish name, @id, payload
end

finish_with_state(listeners_state, name, payload)

# File activesupport/lib/active_support/notifications/instrumenter.rb, line 96
def finish_with_state(listeners_state, name, payload)
  @notifier.finish name, @id, payload, listeners_state
end

instrument(name, payload = {})

给定一个代码块,通过测量执行时间和发布时间来对其进行检测。没有代码块,只需通过通知器发送消息。请注意,即使在传入代码块中发生错误,也会发送事件。

# File activesupport/lib/active_support/notifications/instrumenter.rb, line 54
def instrument(name, payload = {})
  handle = build_handle(name, payload)
  handle.start
  begin
    yield payload if block_given?
  rescue Exception => e
    payload[:exception] = [e.class.name, e.message]
    payload[:exception_object] = e
    raise e
  ensure
    handle.finish
  end
end

start(name, payload)

使用namepayload发送开始通知。

# File activesupport/lib/active_support/notifications/instrumenter.rb, line 87
def start(name, payload)
  @notifier.start name, @id, payload
end