|
|
@ -11,11 +11,26 @@ module Semantic |
|
|
|
class << self |
|
|
|
def activate(*event_groups) |
|
|
|
reset |
|
|
|
runtime_registry_subscriber |
|
|
|
event_groups.each { |event_group| enable(event_group) } |
|
|
|
end |
|
|
|
|
|
|
|
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 |
|
|
|
@global_subscribers ||= [] |
|
|
|
end |
|
|
|