|
@ -11,11 +11,26 @@ module Semantic |
|
|
class << self |
|
|
class << self |
|
|
def activate(*event_groups) |
|
|
def activate(*event_groups) |
|
|
reset |
|
|
reset |
|
|
|
|
|
runtime_registry_subscriber |
|
|
event_groups.each { |event_group| enable(event_group) } |
|
|
event_groups.each { |event_group| enable(event_group) } |
|
|
end |
|
|
end |
|
|
|
|
|
|
|
|
private |
|
|
private |
|
|
|
|
|
|
|
|
|
|
|
def runtime_registry_subscriber |
|
|
|
|
|
global_subscribers << ActiveSupport::Notifications.monotonic_subscribe('sql.active_record') do |name, start, finish, id, payload| |
|
|
|
|
|
unless %w[SCHEMA TRANSACTION].include?(payload[:name]) |
|
|
|
|
|
ActiveRecord::RuntimeRegistry.queries_count += 1 |
|
|
|
|
|
ActiveRecord::RuntimeRegistry.cached_queries_count += 1 if payload[:cached] |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
runtime = (finish - start) * 1_000.0 |
|
|
|
|
|
|
|
|
|
|
|
ActiveRecord::RuntimeRegistry.async_sql_runtime += (runtime - payload[:lock_wait]) if payload[:async] |
|
|
|
|
|
ActiveRecord::RuntimeRegistry.sql_runtime += runtime |
|
|
|
|
|
end |
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
def global_subscribers |
|
|
def global_subscribers |
|
|
@global_subscribers ||= [] |
|
|
@global_subscribers ||= [] |
|
|
end |
|
|
end |
|
|