Class: RorVsWild::Section
- Inherits:
-
Object
- Object
- RorVsWild::Section
- Defined in:
- lib/rorvswild/section.rb
Constant Summary collapse
- COMMAND_MAX_SIZE =
1000
Instance Attribute Summary collapse
-
#appendable_command ⇒ Object
Returns the value of attribute appendable_command.
-
#calls ⇒ Object
Returns the value of attribute calls.
-
#children_runtime ⇒ Object
Returns the value of attribute children_runtime.
-
#command ⇒ Object
Returns the value of attribute command.
-
#file ⇒ Object
Returns the value of attribute file.
-
#kind ⇒ Object
Returns the value of attribute kind.
-
#line ⇒ Object
Returns the value of attribute line.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
-
#total_runtime ⇒ Object
Returns the value of attribute total_runtime.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Section
constructor
A new instance of Section.
- #merge(section) ⇒ Object
- #self_runtime ⇒ Object
- #sibling?(section) ⇒ Boolean
- #to_h ⇒ Object
- #to_json(options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Section
Returns a new instance of Section.
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rorvswild/section.rb', line 29 def initialize @calls = 1 @total_runtime = 0 @children_runtime = 0 @kind = "code".freeze @started_at = RorVsWild.clock_milliseconds location = RorVsWild.agent.locator.find_most_relevant_location(caller_locations) @file = RorVsWild.agent.locator.relative_path(location.path) @line = location.lineno @appendable_command = false end |
Instance Attribute Details
#appendable_command ⇒ Object
Returns the value of attribute appendable_command.
4 5 6 |
# File 'lib/rorvswild/section.rb', line 4 def appendable_command @appendable_command end |
#calls ⇒ Object
Returns the value of attribute calls.
4 5 6 |
# File 'lib/rorvswild/section.rb', line 4 def calls @calls end |
#children_runtime ⇒ Object
Returns the value of attribute children_runtime.
4 5 6 |
# File 'lib/rorvswild/section.rb', line 4 def children_runtime @children_runtime end |
#command ⇒ Object
Returns the value of attribute command.
4 5 6 |
# File 'lib/rorvswild/section.rb', line 4 def command @command end |
#file ⇒ Object
Returns the value of attribute file.
4 5 6 |
# File 'lib/rorvswild/section.rb', line 4 def file @file end |
#kind ⇒ Object
Returns the value of attribute kind.
4 5 6 |
# File 'lib/rorvswild/section.rb', line 4 def kind @kind end |
#line ⇒ Object
Returns the value of attribute line.
4 5 6 |
# File 'lib/rorvswild/section.rb', line 4 def line @line end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
3 4 5 |
# File 'lib/rorvswild/section.rb', line 3 def started_at @started_at end |
#total_runtime ⇒ Object
Returns the value of attribute total_runtime.
4 5 6 |
# File 'lib/rorvswild/section.rb', line 4 def total_runtime @total_runtime end |
Class Method Details
.current ⇒ Object
25 26 27 |
# File 'lib/rorvswild/section.rb', line 25 def self.current (sections = stack) && sections.last end |
.stack ⇒ Object
21 22 23 |
# File 'lib/rorvswild/section.rb', line 21 def self.stack (data = RorVsWild.agent.current_data) && data[:section_stack] end |
.start(&block) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/rorvswild/section.rb', line 6 def self.start(&block) section = Section.new block.call(section) if block_given? stack && stack.push(section) section end |
.stop(&block) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/rorvswild/section.rb', line 13 def self.stop(&block) return unless stack && section = stack.pop block.call(section) if block_given? section.total_runtime = RorVsWild.clock_milliseconds - section.started_at current.children_runtime += section.total_runtime if current RorVsWild.agent.add_section(section) end |
Instance Method Details
#merge(section) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/rorvswild/section.rb', line 45 def merge(section) self.calls += section.calls self.total_runtime += section.total_runtime self.children_runtime += section.children_runtime if section if appendable_command self.command = self.command.dup if self.command.frozen? self.command << "\n" + section.command end else self.command = section.command end self.appendable_command = appendable_command && section.appendable_command end |
#self_runtime ⇒ Object
60 61 62 |
# File 'lib/rorvswild/section.rb', line 60 def self_runtime total_runtime - children_runtime end |
#sibling?(section) ⇒ Boolean
41 42 43 |
# File 'lib/rorvswild/section.rb', line 41 def sibling?(section) kind == section.kind && line == section.line && file == section.file end |
#to_h ⇒ Object
70 71 72 |
# File 'lib/rorvswild/section.rb', line 70 def to_h {calls: calls, total_runtime: total_runtime, children_runtime: children_runtime, kind: kind, started_at: started_at, file: file, line: line, command: command} end |
#to_json(options = {}) ⇒ Object
74 75 76 |
# File 'lib/rorvswild/section.rb', line 74 def to_json( = {}) to_h.to_json() end |