trashed 3.1.0 → 3.2.0
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/lib/trashed/instruments/gctools_oobgc.rb +4 -4
- data/lib/trashed/instruments/ruby_gc_profiler.rb +0 -5
- data/lib/trashed/meter.rb +10 -6
- data/lib/trashed/rack.rb +1 -15
- data/lib/trashed/railtie.rb +2 -1
- data/lib/trashed/reporter.rb +10 -17
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd60c1035b68ae01277826155e500c675958f97a
|
4
|
+
data.tar.gz: 264984b670dcceaecaf6054eeba872e78f412ff3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aca33bba6021edcb5e1f363209604884f6f64de06c9b97f87095064562f3bb3faf0e6e9feda39a8980a7fa381f39c0aa5afa7cc5fc5cb578c46a9dd5a8a084d4
|
7
|
+
data.tar.gz: 3a3ec7763247d51dcd5f020ede1abc9fb6d04e77a7e2b841d9a8c3d9e147ac105714b61c3cd904d62f4e9faafb0c08e8e50e8da1a960e9c6a97e01f757cbe4b7
|
@@ -6,10 +6,10 @@ module Trashed
|
|
6
6
|
last = state[:persistent][:oobgc] || Hash.new(0)
|
7
7
|
|
8
8
|
current = {
|
9
|
-
:count => GC::OOB.stat(:count),
|
10
|
-
:major => GC::OOB.stat(:major),
|
11
|
-
:minor => GC::OOB.stat(:minor),
|
12
|
-
:sweep => GC::OOB.stat(:sweep) }
|
9
|
+
:count => GC::OOB.stat(:count).to_i,
|
10
|
+
:major => GC::OOB.stat(:major).to_i,
|
11
|
+
:minor => GC::OOB.stat(:minor).to_i,
|
12
|
+
:sweep => GC::OOB.stat(:sweep).to_i }
|
13
13
|
|
14
14
|
timings.update \
|
15
15
|
:'OOBGC.count' => current[:count] - last[:count],
|
@@ -17,12 +17,7 @@ module Trashed
|
|
17
17
|
|
18
18
|
if @has_raw_data
|
19
19
|
timings[:"#{captured}.count"] ||= GC::Profiler.raw_data.size
|
20
|
-
|
21
20
|
timings[:'GC.interval'] = GC::Profiler.raw_data.map { |data| data[:GC_INVOKE_TIME] }
|
22
|
-
|
23
|
-
GC::Profiler.raw_data.each do |data|
|
24
|
-
gauges.concat data.map { |k, v| [ :"GC.Profiler.#{k}", v ] }
|
25
|
-
end
|
26
21
|
end
|
27
22
|
|
28
23
|
GC::Profiler.clear
|
data/lib/trashed/meter.rb
CHANGED
@@ -3,8 +3,8 @@ module Trashed
|
|
3
3
|
attr_reader :instruments
|
4
4
|
|
5
5
|
def initialize
|
6
|
-
@
|
7
|
-
@
|
6
|
+
@timers = []
|
7
|
+
@gauges = []
|
8
8
|
end
|
9
9
|
|
10
10
|
# Counters increase, so we measure before/after differences.
|
@@ -20,14 +20,18 @@ module Trashed
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def instrument(instrument)
|
23
|
-
|
24
|
-
|
23
|
+
if instrument.respond_to?(:start)
|
24
|
+
@timers << instrument
|
25
|
+
else
|
26
|
+
@gauges << instrument
|
27
|
+
end
|
25
28
|
end
|
26
29
|
|
27
30
|
def instrument!(state, timings, gauges)
|
28
|
-
@
|
31
|
+
@timers.each { |i| i.start state, timings, gauges }
|
29
32
|
yield.tap do
|
30
|
-
@
|
33
|
+
@timers.reverse_each { |i| i.measure state, timings, gauges }
|
34
|
+
@gauges.each { |i| i.measure state, timings, gauges }
|
31
35
|
end
|
32
36
|
end
|
33
37
|
|
data/lib/trashed/rack.rb
CHANGED
@@ -7,7 +7,7 @@ module Trashed
|
|
7
7
|
def initialize(app, reporter, options = {})
|
8
8
|
@reporter = reporter
|
9
9
|
@meters = Array(options.fetch(:meters, [ResourceUsage]))
|
10
|
-
@app =
|
10
|
+
@app = build_instrumented_app(app, @meters)
|
11
11
|
end
|
12
12
|
|
13
13
|
def call(env)
|
@@ -23,20 +23,6 @@ module Trashed
|
|
23
23
|
Thread.current[:trashed_rack_state] ||= {}
|
24
24
|
end
|
25
25
|
|
26
|
-
def build_sampled_instrumented_app(app, meters)
|
27
|
-
build_sampled_app app, build_instrumented_app(app, meters)
|
28
|
-
end
|
29
|
-
|
30
|
-
def build_sampled_app(app, instrumented)
|
31
|
-
lambda do |env|
|
32
|
-
if @reporter.sample? env
|
33
|
-
instrumented.call env
|
34
|
-
else
|
35
|
-
app.call env
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
26
|
def build_instrumented_app(app, meters)
|
41
27
|
meters.inject app do |wrapped, meter|
|
42
28
|
lambda do |env|
|
data/lib/trashed/railtie.rb
CHANGED
@@ -24,7 +24,8 @@ module Trashed
|
|
24
24
|
initializer 'trashed' do |app|
|
25
25
|
require 'statsd'
|
26
26
|
|
27
|
-
app.config.trashed.
|
27
|
+
app.config.trashed.timing_sample_rate ||= 0.1
|
28
|
+
app.config.trashed.gauge_sample_rate ||= 0.05
|
28
29
|
app.config.trashed.logger ||= Rails.logger
|
29
30
|
|
30
31
|
app.middleware.insert_after 'Rack::Runtime', Trashed::Rack, app.config.trashed
|
data/lib/trashed/reporter.rb
CHANGED
@@ -2,7 +2,8 @@ require 'trashed/rack'
|
|
2
2
|
|
3
3
|
module Trashed
|
4
4
|
class Reporter
|
5
|
-
attr_accessor :logger, :statsd
|
5
|
+
attr_accessor :logger, :statsd
|
6
|
+
attr_accessor :timing_sample_rate, :gauge_sample_rate
|
6
7
|
attr_accessor :timing_dimensions, :gauge_dimensions
|
7
8
|
|
8
9
|
DEFAULT_DIMENSIONS = [ :All ]
|
@@ -10,21 +11,12 @@ module Trashed
|
|
10
11
|
def initialize
|
11
12
|
@logger = nil
|
12
13
|
@statsd = nil
|
13
|
-
@
|
14
|
+
@timing_sample_rate = 0.1
|
15
|
+
@gauge_sample_rate = 0.05
|
14
16
|
@timing_dimensions = ->(env) { DEFAULT_DIMENSIONS }
|
15
17
|
@gauge_dimensions = ->(env) { DEFAULT_DIMENSIONS }
|
16
18
|
end
|
17
19
|
|
18
|
-
# Override in subclasses. Be sure to `super && ...` if you want to rely
|
19
|
-
# on the sample_rate.
|
20
|
-
def sample?(env = nil)
|
21
|
-
random_sample?
|
22
|
-
end
|
23
|
-
|
24
|
-
def random_sample?
|
25
|
-
@sample_rate == 1 or rand < @sample_rate
|
26
|
-
end
|
27
|
-
|
28
20
|
def report(env)
|
29
21
|
report_logger env if @logger
|
30
22
|
report_statsd env if @statsd
|
@@ -80,13 +72,14 @@ module Trashed
|
|
80
72
|
end
|
81
73
|
|
82
74
|
def report_statsd(env)
|
83
|
-
@statsd.
|
84
|
-
|
85
|
-
send_to_statsd statsd, :
|
75
|
+
method = @statsd.respond_to?(:easy) ? :easy : :batch
|
76
|
+
@statsd.send(method) do |statsd|
|
77
|
+
send_to_statsd statsd, :timing, @timing_sample_rate, env[Trashed::Rack::TIMINGS], :'Rack.Request', @timing_dimensions.call(env)
|
78
|
+
send_to_statsd statsd, :timing, @gauge_sample_rate, env[Trashed::Rack::GAUGES], :'Rack.Server', @gauge_dimensions.call(env)
|
86
79
|
end
|
87
80
|
end
|
88
81
|
|
89
|
-
def send_to_statsd(statsd, method, measurements, namespace, dimensions)
|
82
|
+
def send_to_statsd(statsd, method, sample_rate, measurements, namespace, dimensions)
|
90
83
|
measurements.each do |metric, value|
|
91
84
|
case value
|
92
85
|
when Array
|
@@ -95,7 +88,7 @@ module Trashed
|
|
95
88
|
end
|
96
89
|
when Numeric
|
97
90
|
Array(dimensions || :All).each do |dimension|
|
98
|
-
statsd.send method, :"#{namespace}.#{dimension}.#{metric}", value,
|
91
|
+
statsd.send method, :"#{namespace}.#{dimension}.#{metric}", value, sample_rate
|
99
92
|
end
|
100
93
|
end
|
101
94
|
end
|