rails-profiler 0.44.20 → 0.44.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/app/assets/builds/profiler.js +6 -6
- data/lib/profiler/collectors/flamegraph_collector.rb +12 -1
- data/lib/profiler/collectors/http_collector.rb +15 -1
- data/lib/profiler/instrumentation/net_http_instrumentation.rb +32 -29
- data/lib/profiler/test_runner/runner.rb +3 -3
- data/lib/profiler/version.rb +1 -1
- metadata +1 -1
|
@@ -11,6 +11,7 @@ module Profiler
|
|
|
11
11
|
@events = []
|
|
12
12
|
@subscriptions = []
|
|
13
13
|
@mutex = Mutex.new
|
|
14
|
+
@released_at = nil
|
|
14
15
|
end
|
|
15
16
|
|
|
16
17
|
def icon
|
|
@@ -152,6 +153,7 @@ module Profiler
|
|
|
152
153
|
def unsubscribe
|
|
153
154
|
unsubscribe_notifications(@subscriptions)
|
|
154
155
|
restore_thread_slots
|
|
156
|
+
@released_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
155
157
|
end
|
|
156
158
|
|
|
157
159
|
def toolbar_summary
|
|
@@ -163,6 +165,13 @@ module Profiler
|
|
|
163
165
|
|
|
164
166
|
private
|
|
165
167
|
|
|
168
|
+
def add_event_allowed?
|
|
169
|
+
return true unless @released_at
|
|
170
|
+
|
|
171
|
+
grace_period = 0.5
|
|
172
|
+
(Process.clock_gettime(Process::CLOCK_MONOTONIC) - @released_at) <= grace_period && @events.size < 100
|
|
173
|
+
end
|
|
174
|
+
|
|
166
175
|
def build_hierarchy(events)
|
|
167
176
|
return [] if events.empty?
|
|
168
177
|
|
|
@@ -193,7 +202,9 @@ module Profiler
|
|
|
193
202
|
end
|
|
194
203
|
|
|
195
204
|
def add_event(event)
|
|
196
|
-
@mutex.synchronize
|
|
205
|
+
@mutex.synchronize do
|
|
206
|
+
@events << event if add_event_allowed?
|
|
207
|
+
end
|
|
197
208
|
end
|
|
198
209
|
|
|
199
210
|
def short_identifier(identifier)
|
|
@@ -11,6 +11,7 @@ module Profiler
|
|
|
11
11
|
@requests = []
|
|
12
12
|
@mutex = Mutex.new
|
|
13
13
|
@collected = false
|
|
14
|
+
@released_at = nil
|
|
14
15
|
end
|
|
15
16
|
|
|
16
17
|
def icon
|
|
@@ -48,6 +49,7 @@ module Profiler
|
|
|
48
49
|
# records nothing when no collector holds the thread-local slot.
|
|
49
50
|
def unsubscribe
|
|
50
51
|
restore_thread_slots
|
|
52
|
+
@released_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
51
53
|
end
|
|
52
54
|
|
|
53
55
|
def collect
|
|
@@ -62,11 +64,23 @@ module Profiler
|
|
|
62
64
|
|
|
63
65
|
# Called from NetHttpInstrumentation before the actual HTTP call.
|
|
64
66
|
# Returns the mutable entry so the caller can update it on completion.
|
|
67
|
+
# Returns nil if the collector has been released and the grace period or entry cap is exceeded,
|
|
68
|
+
# to prevent fire-and-forget threads from indefinitely polluting the profile after the request ends.
|
|
65
69
|
def register_pending(payload)
|
|
66
70
|
entry = payload.merge(in_flight: true, status: 0, duration: nil,
|
|
67
71
|
response_headers: {}, response_body: nil,
|
|
68
72
|
response_body_encoding: "text", response_size: 0)
|
|
69
|
-
|
|
73
|
+
|
|
74
|
+
@mutex.synchronize do
|
|
75
|
+
# Refuse new entries if released and (grace period expired OR cap exceeded). Checked
|
|
76
|
+
# and appended under the same lock, so concurrent fire-and-forget threads cannot all
|
|
77
|
+
# pass the cap together.
|
|
78
|
+
if @released_at
|
|
79
|
+
grace_period = 0.5
|
|
80
|
+
return nil if (Process.clock_gettime(Process::CLOCK_MONOTONIC) - @released_at) > grace_period || @requests.size >= 100
|
|
81
|
+
end
|
|
82
|
+
@requests << entry
|
|
83
|
+
end
|
|
70
84
|
save_if_collected
|
|
71
85
|
entry
|
|
72
86
|
end
|
|
@@ -65,39 +65,42 @@ module Profiler
|
|
|
65
65
|
|
|
66
66
|
response = super
|
|
67
67
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
68
|
+
# Only record response details if the collector accepted the request
|
|
69
|
+
if entry
|
|
70
|
+
duration = ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - t0) * 1000).round(2)
|
|
71
|
+
# read_body with a block hands each chunk to the block and keeps none: the response then
|
|
72
|
+
# holds a Net::ReadAdapter, whose to_s is an inspect and whose bytes are gone.
|
|
73
|
+
streamed = NetHttpInstrumentation.streamed_body?(response)
|
|
74
|
+
resp_body_raw = streamed ? "" : response.body.to_s
|
|
75
|
+
resp_content_encoding = response["content-encoding"].to_s.strip.downcase
|
|
76
|
+
resp_body = NetHttpInstrumentation.decompress_body(resp_body_raw, resp_content_encoding, limit)
|
|
77
|
+
resp_truncated = limit ? resp_body.bytesize > limit : false
|
|
78
|
+
resp_body = Redaction.cut_bytes(resp_body, limit) if resp_truncated
|
|
79
|
+
resp_content_type = response["content-type"].to_s
|
|
80
|
+
processed_resp = NetHttpInstrumentation.process_body(resp_body, resp_content_type)
|
|
81
|
+
|
|
82
|
+
t1 = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
83
|
+
|
|
84
|
+
collector.complete_request(
|
|
85
|
+
entry,
|
|
86
|
+
status: response.code.to_i,
|
|
87
|
+
duration: duration,
|
|
88
|
+
response_headers: Redaction.filter_headers(response.to_hash.transform_values { |v| v.join(", ") }),
|
|
89
|
+
response_body: processed_resp[:body],
|
|
90
|
+
response_body_encoding: processed_resp[:encoding],
|
|
91
|
+
response_size: streamed ? (declared_length(response) || 0) : resp_body_raw.bytesize,
|
|
92
|
+
response_body_truncated: resp_truncated,
|
|
93
|
+
response_body_not_captured: streamed
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
fg = Thread.current[:profiler_flamegraph_collector]
|
|
97
|
+
fg&.record_http_event(started_at: t0, finished_at: t1, url: url, method: req.method, status: response.code.to_i)
|
|
98
|
+
end
|
|
96
99
|
|
|
97
100
|
response
|
|
98
101
|
rescue => e
|
|
99
102
|
duration = defined?(t0) && t0 ? ((Process.clock_gettime(Process::CLOCK_MONOTONIC) - t0) * 1000).round(2) : 0.0
|
|
100
|
-
if defined?(entry) && entry
|
|
103
|
+
if defined?(entry) && entry && defined?(collector) && collector
|
|
101
104
|
collector.fail_request(entry, error: e.message, duration: duration)
|
|
102
105
|
end
|
|
103
106
|
raise
|
|
@@ -165,11 +165,11 @@ module Profiler
|
|
|
165
165
|
Profiler::TestRunner.run_store.update(run.id, pid: io.pid)
|
|
166
166
|
|
|
167
167
|
begin
|
|
168
|
-
while (chunk = io.
|
|
169
|
-
break if chunk.empty?
|
|
170
|
-
|
|
168
|
+
while (chunk = io.readpartial(4096))
|
|
171
169
|
Profiler::TestRunner.run_store.append_output(run.id, chunk)
|
|
172
170
|
end
|
|
171
|
+
rescue EOFError
|
|
172
|
+
# End of stream reached
|
|
173
173
|
ensure
|
|
174
174
|
# The process printed everything, killed or not: what was held back can be shown.
|
|
175
175
|
Profiler::TestRunner.run_store.finish_output(run.id)
|
data/lib/profiler/version.rb
CHANGED