Class: NewRelic::Agent::Transaction::TransactionSampleBuffer
- Inherits:
-
Object
- Object
- NewRelic::Agent::Transaction::TransactionSampleBuffer
show all
- Defined in:
- lib/new_relic/agent/transaction/transaction_sample_buffer.rb
Constant Summary
collapse
- NO_SAMPLES =
[].freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of TransactionSampleBuffer.
13
14
15
|
# File 'lib/new_relic/agent/transaction/transaction_sample_buffer.rb', line 13
def initialize
@samples = []
end
|
Instance Attribute Details
#samples ⇒ Object
Returns the value of attribute samples.
9
10
11
|
# File 'lib/new_relic/agent/transaction/transaction_sample_buffer.rb', line 9
def samples
@samples
end
|
Instance Method Details
#allow_sample?(sample) ⇒ Boolean
31
32
33
|
# File 'lib/new_relic/agent/transaction/transaction_sample_buffer.rb', line 31
def allow_sample?(sample)
true
end
|
#enabled? ⇒ Boolean
17
18
19
|
# File 'lib/new_relic/agent/transaction/transaction_sample_buffer.rb', line 17
def enabled?
true
end
|
#full? ⇒ Boolean
55
56
57
|
# File 'lib/new_relic/agent/transaction/transaction_sample_buffer.rb', line 55
def full?
@samples.length >= max_samples
end
|
#harvest_samples ⇒ Object
25
26
27
28
29
|
# File 'lib/new_relic/agent/transaction/transaction_sample_buffer.rb', line 25
def harvest_samples
@samples
ensure
reset!
end
|
#reset! ⇒ Object
21
22
23
|
# File 'lib/new_relic/agent/transaction/transaction_sample_buffer.rb', line 21
def reset!
@samples = []
end
|
#store(sample) ⇒ Object
35
36
37
38
39
40
41
|
# File 'lib/new_relic/agent/transaction/transaction_sample_buffer.rb', line 35
def store(sample)
return unless enabled?
if allow_sample?(sample)
add_sample(sample)
truncate_samples_if_needed
end
end
|
#store_previous(previous_samples) ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/new_relic/agent/transaction/transaction_sample_buffer.rb', line 43
def store_previous(previous_samples)
return unless enabled?
previous_samples.each do |sample|
add_sample(sample) if allow_sample?(sample)
end
truncate_samples_if_needed
end
|
#truncate_samples ⇒ Object
Our default truncation strategy is to keep max_samples worth of the longest samples. Override this method for alternate behavior.
This doesn’t use the more convenient #last and #sort_by to avoid additional array allocations (and abundant alliteration)
64
65
66
67
|
# File 'lib/new_relic/agent/transaction/transaction_sample_buffer.rb', line 64
def truncate_samples
@samples.sort!{|a,b| a.duration <=> b.duration}
@samples.slice!(0..-(max_samples + 1))
end
|
#truncate_samples_if_needed ⇒ Object
51
52
53
|
# File 'lib/new_relic/agent/transaction/transaction_sample_buffer.rb', line 51
def truncate_samples_if_needed
truncate_samples if full?
end
|
#visit_segment ⇒ Object
When pushing a scope different sample buffers potentially want to know about what’s happening to annotate the incoming segments
71
72
73
|
# File 'lib/new_relic/agent/transaction/transaction_sample_buffer.rb', line 71
def visit_segment(*)
end
|