DEV: Log number of live slots used by requests (#29884)

This commit is contained in:
Bianca Nenciu 2024-11-28 18:25:48 +02:00 committed by GitHub
parent 5b19e2ca0f
commit 5abee8ac6b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 10 deletions

View File

@ -109,26 +109,27 @@ if ENV["ENABLE_LOGSTASH_LOGGER"] == "1"
}
if data = (Thread.current[:_method_profiler] || event.payload[:timings])
sql = data[:sql]
if sql
if sql = data[:sql]
output[:db] = sql[:duration] * 1000
output[:db_calls] = sql[:calls]
end
redis = data[:redis]
if redis
if redis = data[:redis]
output[:redis] = redis[:duration] * 1000
output[:redis_calls] = redis[:calls]
end
net = data[:net]
if net
if net = data[:net]
output[:net] = net[:duration] * 1000
output[:net_calls] = net[:calls]
end
# MethodProfiler.stop is called after this lambda, so the delta
# must be computed here.
if data[:__start_gc_heap_live_slots]
output[:heap_live_slots] = GC.stat[:heap_live_slots] -
data[:__start_gc_heap_live_slots]
end
end
output

View File

@ -90,7 +90,10 @@ class MethodProfiler
def self.start(transfer = nil)
Thread.current[:_method_profiler] = transfer ||
{ __start: Process.clock_gettime(Process::CLOCK_MONOTONIC) }
{
__start: Process.clock_gettime(Process::CLOCK_MONOTONIC),
__start_gc_heap_live_slots: GC.stat[:heap_live_slots],
}
end
def self.clear