Class: ScoutApm::LayerConverters::SlowJobConverter
Instance Attribute Summary
#request, #root_layer, #walker
Instance Method Summary
collapse
#find_first_layer_of_type, #scope_layer
Constructor Details
Returns a new instance of SlowJobConverter.
4
5
6
7
8
9
10
11
12
13
14
|
# File 'lib/scout_apm/layer_converters/slow_job_converter.rb', line 4
def initialize(*)
@backtraces = []
super
@points = if request.job?
ScoutApm::Agent.instance.slow_job_policy.score(request)
else
-1
end
end
|
Instance Method Details
#attach_backtraces(metric_hash) ⇒ Object
142
143
144
145
146
147
|
# File 'lib/scout_apm/layer_converters/slow_job_converter.rb', line 142
def attach_backtraces(metric_hash)
@backtraces.each do |meta_with_backtrace|
metric_hash.keys.find { |k| k == meta_with_backtrace }.backtrace = meta_with_backtrace.backtrace
end
metric_hash
end
|
#call ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/scout_apm/layer_converters/slow_job_converter.rb', line 24
def call
return nil unless request.job?
return nil unless queue_layer
return nil unless job_layer
ScoutApm::Agent.instance.slow_job_policy.stored!(request)
mem_delta = ScoutApm::Instruments::Process::ProcessMemory.(request.capture_mem_delta!)
timing_metrics, allocation_metrics = create_metrics
unless ScoutApm::Instruments::Allocations::ENABLED
allocation_metrics = {}
end
SlowJobRecord.new(
queue_layer.name,
job_layer.name,
root_layer.stop_time,
job_layer.total_call_time,
job_layer.total_exclusive_time,
request.context,
timing_metrics,
allocation_metrics,
mem_delta,
job_layer.total_allocations,
score)
end
|
#create_metrics ⇒ Object
61
62
63
64
65
66
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/scout_apm/layer_converters/slow_job_converter.rb', line 61
def create_metrics
metric_hash = Hash.new
allocation_metric_hash = Hash.new
subscope_layers = []
walker.before do |layer|
if layer.subscopable?
subscope_layers.push(layer)
end
end
walker.after do |layer|
if layer.subscopable?
subscope_layers.pop
end
end
walker.walk do |layer|
next if layer.annotations[:ignorable]
next if layer == queue_layer
meta_options = if subscope_layers.first && layer != subscope_layers.first subscope_name = subscope_layers.first.legacy_metric_name
{:scope => subscope_name}
elsif layer == job_layer {}
else
{:scope => job_layer.legacy_metric_name}
end
meta_options.merge!(:desc => layer.desc.to_s) if layer.desc
meta = MetricMeta.new(layer.legacy_metric_name, meta_options)
meta..merge!(layer.annotations)
if layer.backtrace
bt = ScoutApm::Utils::BacktraceParser.new(layer.backtrace).call
if bt.any? meta.backtrace = bt
@backtraces << meta
else
ScoutApm::Agent.instance.logger.debug { "Unable to capture an app-specific backtrace for #{meta.inspect}\n#{layer.backtrace}" }
end
end
metric_hash[meta] ||= MetricStats.new( meta_options.has_key?(:scope) )
allocation_metric_hash[meta] ||= MetricStats.new( meta_options.has_key?(:scope) )
stat = metric_hash[meta]
stat.update!(layer.total_call_time, layer.total_exclusive_time)
stat = allocation_metric_hash[meta]
stat.update!(layer.total_allocations, layer.total_exclusive_allocations)
meta = MetricMeta.new("#{layer.type}/all")
metric_hash[meta] ||= MetricStats.new(false)
allocation_metric_hash[meta] ||= MetricStats.new(false)
stat = metric_hash[meta]
stat.update!(layer.total_call_time, layer.total_exclusive_time)
stat = allocation_metric_hash[meta]
stat.update!(layer.total_allocations, layer.total_exclusive_allocations)
end
metric_hash = attach_backtraces(metric_hash)
allocation_metric_hash = attach_backtraces(allocation_metric_hash)
[metric_hash,allocation_metric_hash]
end
|
#job_layer ⇒ Object
57
58
59
|
# File 'lib/scout_apm/layer_converters/slow_job_converter.rb', line 57
def job_layer
@job_layer ||= find_first_layer_of_type("Job")
end
|
#name ⇒ Object
16
17
18
|
# File 'lib/scout_apm/layer_converters/slow_job_converter.rb', line 16
def name
request.unique_name
end
|
#queue_layer ⇒ Object
53
54
55
|
# File 'lib/scout_apm/layer_converters/slow_job_converter.rb', line 53
def queue_layer
@queue_layer ||= find_first_layer_of_type("Queue")
end
|
#score ⇒ Object
20
21
22
|
# File 'lib/scout_apm/layer_converters/slow_job_converter.rb', line 20
def score
@points
end
|