Class: ScoutApm::LayerConverters::SlowJobConverter

Inherits:
ConverterBase
  • Object
show all
Defined in:
lib/scout_apm/layer_converters/slow_job_converter.rb

Constant Summary

Constants inherited from ConverterBase

ConverterBase::MAX_METRICS

Instance Attribute Summary

Attributes inherited from ConverterBase

#request, #root_layer, #walker

Instance Method Summary collapse

Methods inherited from ConverterBase

#attach_backtraces, #find_first_layer_of_type, #limited?, #make_meta_options, #make_meta_options_desc_hash, #make_meta_options_scope, #over_metric_limit?, #scope_layer, #setup_subscopable_callbacks, #store_aggregate_metric, #store_backtrace, #store_specific_metric, #subscope_name, #subscoped?

Constructor Details

#initializeSlowJobConverter

Returns a new instance of SlowJobConverter.



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/scout_apm/layer_converters/slow_job_converter.rb', line 4

def initialize(*)
  super

  # After call to super, so @request is populated
  @points = if request.job?
              ScoutApm::Agent.instance.slow_job_policy.score(request)
            else
              -1
            end

  setup_subscopable_callbacks
end

Instance Method Details

#callObject



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
52
53
54
55
# File 'lib/scout_apm/layer_converters/slow_job_converter.rb', line 25

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)

  # record the change in memory usage
  mem_delta = ScoutApm::Instruments::Process::ProcessMemory.rss_to_mb(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,
    limited?
  )
end

#create_metricsObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/scout_apm/layer_converters/slow_job_converter.rb', line 69

def create_metrics
  metric_hash = Hash.new
  allocation_metric_hash = Hash.new

  walker.walk do |layer|
    next if skip_layer?(layer)

    # The queue_layer is useful to capture for other reasons, but doesn't
    # create a MetricMeta/Stat of its own
    next if layer == queue_layer

    store_specific_metric(layer, metric_hash, allocation_metric_hash)
    store_aggregate_metric(layer, metric_hash, allocation_metric_hash)
  end

  metric_hash = attach_backtraces(metric_hash)
  allocation_metric_hash = attach_backtraces(allocation_metric_hash)

  [metric_hash, allocation_metric_hash]
end

#job_layerObject



61
62
63
# File 'lib/scout_apm/layer_converters/slow_job_converter.rb', line 61

def job_layer
  @job_layer ||= find_first_layer_of_type("Job")
end

#nameObject



17
18
19
# File 'lib/scout_apm/layer_converters/slow_job_converter.rb', line 17

def name
  request.unique_name
end

#queue_layerObject



57
58
59
# File 'lib/scout_apm/layer_converters/slow_job_converter.rb', line 57

def queue_layer
  @queue_layer ||= find_first_layer_of_type("Queue")
end

#scoreObject



21
22
23
# File 'lib/scout_apm/layer_converters/slow_job_converter.rb', line 21

def score
  @points
end

#skip_layer?(layer) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/scout_apm/layer_converters/slow_job_converter.rb', line 65

def skip_layer?(layer)
  super(layer) || layer == queue_layer
end