DEV: Log number of live slots used by requests

This commit is contained in:
Bianca Nenciu 2024-11-21 23:35:06 +02:00
parent 667a09b159
commit 4dda44e2a9
2 changed files with 15 additions and 10 deletions

View File

@ -109,26 +109,28 @@ 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 start_heap_live_slots = data[:__start_heap_live_slots]
if heap_live_slots = GC.stat[:heap_live_slots] - start_heap_live_slots
output[:heap_live_slots] = heap_live_slots if heap_live_slots > 0
end
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_heap_live_slots: GC.stat[:heap_live_slots],
}
end
def self.clear