Module: TemplateStreaming::NewRelic::TransactionSample
- Defined in:
- lib/template_streaming/new_relic.rb
Instance Method Summary collapse
-
#bump_by(delta) ⇒ Object
Return a copy of this sample with the segment timestamps all incremented by the given delta.
-
#incorporate(samples) ⇒ Object
Put the given samples under this one.
-
#subroot_segment ⇒ Object
Return the segment under the root.
Instance Method Details
#bump_by(delta) ⇒ Object
Return a copy of this sample with the segment timestamps all incremented by the given delta.
Note that although the returned object is a different TransactionSample instance, the segments will be the same objects, modified in place. We would modify the TransactionSample in place too, only this method is called on frozen samples.
468 469 470 471 472 473 |
# File 'lib/template_streaming/new_relic.rb', line 468 def bump_by(delta) root_segment.bump_by(delta) sample = dup sample.instance_eval{@start_time += delta} sample end |
#incorporate(samples) ⇒ Object
Put the given samples under this one.
The subroot children of the given samples are moved under this sample’s subroot.
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 |
# File 'lib/template_streaming/new_relic.rb', line 498 def incorporate(samples) incorporated_duration = 0.0 samples.each do |sample| # Bump timestamps by the total length of previous samples. sample = sample.bump_by(root_segment.duration + incorporated_duration) incorporated_duration += sample.root_segment.duration # Merge segments. sample.subroot_segment.called_segments.each do |segment| subroot_segment.add_called_segment(segment) end # Merge params. if (request_params = sample.params.delete(:request_params)) params[:request_params].reverse_merge!(request_params) end if (custom_params = sample.params.delete(:custom_params)) params[:custom_params] ||= {} params[:custom_params].reverse_merge!(custom_params) end params.reverse_merge!(sample.params) end root_segment. += incorporated_duration subroot_segment. += incorporated_duration end |
#subroot_segment ⇒ Object
Return the segment under the root.
If the root segment has more than one child, raise an error. It appears this is never supposed to happen, though–the RPM transaction trace view only ever shows the first segment.
483 484 485 486 487 488 489 490 |
# File 'lib/template_streaming/new_relic.rb', line 483 def subroot_segment @subroot_segment ||= begin (children = @root_segment.called_segments).size == 1 or raise Error, "multiple top segments found" children.first end end |