mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 01:14:12 +08:00
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:

committed by
GitHub

parent
e8f7b62752
commit
773b22e8d0
@ -661,6 +661,7 @@ RSpec.describe Middleware::RequestTracker do
|
||||
lambda do |env|
|
||||
sql_calls.times { User.where(id: -100).pluck(:id) }
|
||||
redis_calls.times { Discourse.redis.get("x") }
|
||||
yield if block_given?
|
||||
result
|
||||
end
|
||||
end
|
||||
@ -749,6 +750,36 @@ RSpec.describe Middleware::RequestTracker do
|
||||
expect(headers["X-Runtime"].to_f).to be > 0
|
||||
end
|
||||
|
||||
it "correctly logs GC stats when `instrument_gc_stat_per_request` site setting has been enabled" do
|
||||
tracker =
|
||||
Middleware::RequestTracker.new(
|
||||
app([200, {}, []]) do
|
||||
GC.start(full_mark: true) # Major GC
|
||||
GC.start(full_mark: false) # Minor GC
|
||||
end,
|
||||
)
|
||||
|
||||
tracker.call(env)
|
||||
|
||||
expect(@data[:timing][:gc]).to eq(nil)
|
||||
|
||||
SiteSetting.instrument_gc_stat_per_request = true
|
||||
|
||||
tracker =
|
||||
Middleware::RequestTracker.new(
|
||||
app([200, {}, []]) do
|
||||
GC.start(full_mark: true) # Major GC
|
||||
GC.start(full_mark: false) # Minor GC
|
||||
end,
|
||||
)
|
||||
|
||||
tracker.call(env)
|
||||
|
||||
expect(@data[:timing][:gc][:time]).to be > 0.0
|
||||
expect(@data[:timing][:gc][:major_count]).to eq(1)
|
||||
expect(@data[:timing][:gc][:minor_count]).to eq(1)
|
||||
end
|
||||
|
||||
it "can correctly log messagebus request types" do
|
||||
tracker = Middleware::RequestTracker.new(app([200, {}, []]))
|
||||
|
||||
|
Reference in New Issue
Block a user