Class: AppPerfRpm::Span
- Inherits:
-
Object
- Object
- AppPerfRpm::Span
- Defined in:
- lib/app_perf_rpm/span.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#backtrace ⇒ Object
Returns the value of attribute backtrace.
-
#children ⇒ Object
Returns the value of attribute children.
-
#controller ⇒ Object
Returns the value of attribute controller.
-
#domain ⇒ Object
Returns the value of attribute domain.
-
#ended_at ⇒ Object
Returns the value of attribute ended_at.
-
#layer ⇒ Object
Returns the value of attribute layer.
-
#options ⇒ Object
Returns the value of attribute options.
-
#source ⇒ Object
Returns the value of attribute source.
-
#started_at ⇒ Object
Returns the value of attribute started_at.
-
#trace_id ⇒ Object
Returns the value of attribute trace_id.
-
#type ⇒ Object
Returns the value of attribute type.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #base_options ⇒ Object
- #child_of?(span) ⇒ Boolean
- #duration ⇒ Object
- #exclusive_duration ⇒ Object
-
#initialize ⇒ Span
constructor
A new instance of Span.
- #parent_of?(span) ⇒ Boolean
- #to_a ⇒ Object
- #to_s ⇒ Object
- #to_spans ⇒ Object
Constructor Details
#initialize ⇒ Span
Returns a new instance of Span.
42 43 44 45 46 |
# File 'lib/app_perf_rpm/span.rb', line 42 def initialize self.children = [] self.type = "web" self. = {} end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
3 4 5 |
# File 'lib/app_perf_rpm/span.rb', line 3 def action @action end |
#backtrace ⇒ Object
Returns the value of attribute backtrace.
3 4 5 |
# File 'lib/app_perf_rpm/span.rb', line 3 def backtrace @backtrace end |
#children ⇒ Object
Returns the value of attribute children.
3 4 5 |
# File 'lib/app_perf_rpm/span.rb', line 3 def children @children end |
#controller ⇒ Object
Returns the value of attribute controller.
3 4 5 |
# File 'lib/app_perf_rpm/span.rb', line 3 def controller @controller end |
#domain ⇒ Object
Returns the value of attribute domain.
3 4 5 |
# File 'lib/app_perf_rpm/span.rb', line 3 def domain @domain end |
#ended_at ⇒ Object
Returns the value of attribute ended_at.
3 4 5 |
# File 'lib/app_perf_rpm/span.rb', line 3 def ended_at @ended_at end |
#layer ⇒ Object
Returns the value of attribute layer.
3 4 5 |
# File 'lib/app_perf_rpm/span.rb', line 3 def layer @layer end |
#options ⇒ Object
Returns the value of attribute options.
3 4 5 |
# File 'lib/app_perf_rpm/span.rb', line 3 def @options end |
#source ⇒ Object
Returns the value of attribute source.
3 4 5 |
# File 'lib/app_perf_rpm/span.rb', line 3 def source @source end |
#started_at ⇒ Object
Returns the value of attribute started_at.
3 4 5 |
# File 'lib/app_perf_rpm/span.rb', line 3 def started_at @started_at end |
#trace_id ⇒ Object
Returns the value of attribute trace_id.
3 4 5 |
# File 'lib/app_perf_rpm/span.rb', line 3 def trace_id @trace_id end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'lib/app_perf_rpm/span.rb', line 3 def type @type end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/app_perf_rpm/span.rb', line 3 def url @url end |
Class Method Details
.arrange(spans) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/app_perf_rpm/span.rb', line 17 def self.arrange(spans) spans.sort! { |a, b| (a.ended_at <=> b.ended_at) } null_span = Span.new controller = (spans.find {|s| s.controller } || null_span).controller action = (spans.find {|s| s.action } || null_span).action domain = (spans.find {|s| s.domain } || null_span).domain url = (spans.find {|s| s.url } || null_span).url while span = spans.shift span.controller ||= controller span.action ||= action span.domain ||= domain span.url ||= url if parent = spans.find { |n| n.parent_of?(span) } parent.children << span elsif spans.empty? root = span end end root end |
Instance Method Details
#base_options ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/app_perf_rpm/span.rb', line 77 def opts = {} opts["domain"] = domain opts["controller"] = controller opts["action"] = action opts["url"] = url opts["type"] = type #opts["backtrace"] = ::AppPerfRpm::Backtrace.backtrace opts["source"] = ::AppPerfRpm::Backtrace.source_extract opts.delete_if { |k, v| v.nil? } end |
#child_of?(span) ⇒ Boolean
61 62 63 |
# File 'lib/app_perf_rpm/span.rb', line 61 def child_of?(span) span.parent_of?(self) end |
#duration ⇒ Object
48 49 50 |
# File 'lib/app_perf_rpm/span.rb', line 48 def duration @duration ||= (ended_at - started_at) * 1000.0 end |
#exclusive_duration ⇒ Object
52 53 54 |
# File 'lib/app_perf_rpm/span.rb', line 52 def exclusive_duration @exclusive_duration ||= duration - children.inject(0.0) { |sum, child| sum + child.duration } end |
#parent_of?(span) ⇒ Boolean
56 57 58 59 |
# File 'lib/app_perf_rpm/span.rb', line 56 def parent_of?(span) start = (started_at - span.started_at) * 1000.0 start <= 0 && (start + duration >= span.duration) end |
#to_a ⇒ Object
93 94 95 96 97 98 99 100 101 |
# File 'lib/app_perf_rpm/span.rb', line 93 def to_a [ layer, trace_id, started_at, duration, .merge() ] end |
#to_s ⇒ Object
89 90 91 |
# File 'lib/app_perf_rpm/span.rb', line 89 def to_s "#{layer}:#{trace_id}:#{started_at}:#{exclusive_duration}" end |
#to_spans ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/app_perf_rpm/span.rb', line 65 def to_spans span = self.dup span.exclusive_duration span.children = [] if children.size > 0 return [span] + children.map(&:to_spans) else return [span] end end |