mirror of
https://github.com/discourse/discourse.git
synced 2024-12-27 08:53:56 +08:00
773b22e8d0
Why this change?
This is a follow up to e8f7b62752
.
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`.
41 lines
837 B
Ruby
41 lines
837 B
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe MethodProfiler do
|
|
class Sneetch
|
|
def beach
|
|
end
|
|
|
|
def recurse(count = 5)
|
|
recurse(count - 1) if count > 0
|
|
end
|
|
end
|
|
|
|
it "can bypass recursion on demand" do
|
|
MethodProfiler.patch(Sneetch, [:recurse], :recurse, no_recurse: true)
|
|
|
|
MethodProfiler.start
|
|
Sneetch.new.recurse
|
|
result = MethodProfiler.stop
|
|
|
|
expect(result[:recurse][:calls]).to eq(1)
|
|
end
|
|
|
|
it "can transfer data between threads" do
|
|
MethodProfiler.patch(Sneetch, [:beach], :at_beach)
|
|
|
|
MethodProfiler.start
|
|
Sneetch.new.beach
|
|
data = MethodProfiler.transfer
|
|
result = nil
|
|
Thread
|
|
.new do
|
|
MethodProfiler.start(data)
|
|
Sneetch.new.beach
|
|
result = MethodProfiler.stop
|
|
end
|
|
.join
|
|
|
|
expect(result[:at_beach][:calls]).to eq(2)
|
|
end
|
|
end
|