DEV: Seperate concerns of tracking GC stat from MethodProfiler (#22921)

Why this change?

This is a follow up to e8f7b62752a65e33aa1cee748fc966c4ad14b1ee.
Tracking of GC stats didn't really belong in the `MethodProfiler` class
so we want to extract that concern into its own class.

As part of this PR, the `track_gc_stat_per_request` site setting has
also been renamed to `instrument_gc_stat_per_request`.
This commit is contained in:
Alan Guo Xiang Tan
2023-08-02 10:46:37 +08:00
committed by GitHub
parent e8f7b62752
commit 773b22e8d0
8 changed files with 83 additions and 39 deletions

View File

@ -201,6 +201,7 @@ class Middleware::RequestTracker
def call(env)
result = nil
info = nil
gc_stat_timing = nil
# doing this as early as possible so we have an
# accurate counter
@ -225,7 +226,13 @@ class Middleware::RequestTracker
env["discourse.request_tracker"] = self
MethodProfiler.start
result = @app.call(env)
if SiteSetting.instrument_gc_stat_per_request
gc_stat_timing = GCStatInstrumenter.instrument { result = @app.call(env) }
else
result = @app.call(env)
end
info = MethodProfiler.stop
# possibly transferred?
@ -263,7 +270,11 @@ class Middleware::RequestTracker
end
end
end
log_request_info(env, result, info, request) if !env["discourse.request_tracker.skip"]
if !env["discourse.request_tracker.skip"]
info.merge!(gc_stat_timing) if gc_stat_timing
log_request_info(env, result, info, request)
end
end
def log_later(data)