Class: Trace::EventBuffer
- Inherits:
-
Object
- Object
- Trace::EventBuffer
- Defined in:
- lib/eventbuffer.rb
Defined Under Namespace
Classes: EventStruct
Instance Attribute Summary collapse
-
#buf ⇒ Object
readonly
Returns the value of attribute buf.
-
#marks ⇒ Object
User position mark into buffer.
-
#maxsize ⇒ Object
readonly
Maximum size of buffer or nil if unlimited.
-
#size ⇒ Object
readonly
size of buffer.
Instance Method Summary collapse
-
#add_mark ⇒ Object
Add mark for the current event buffer position.
-
#add_mark_nodup ⇒ Object
Like add mark, but do only if the last marked position has changed.
-
#append(event, frame, arg) ⇒ Object
Add a new event dropping off old events if that was declared marks are also dropped if buffer has a limit.
- #each(from = nil, to = nil) ⇒ Object
- #each_with_index(from = nil, to = nil) ⇒ Object
- #format_entry(item, long_format = true) ⇒ Object
-
#initialize(maxsize = nil) ⇒ EventBuffer
constructor
then marks will drop out as they disappear from the buffer.
-
#pred_pos(dec = 1) ⇒ Object
Return the next event buffer position taking into account that we may have a fixed-sized buffer ring.
- #reset ⇒ Object
-
#succ_pos(inc = 1) ⇒ Object
Return the next event buffer position taking into account that we may have a fixed-sized buffer ring.
-
#zero_pos ⇒ Object
Return the adjusted zeroth position in @buf.
Constructor Details
#initialize(maxsize = nil) ⇒ EventBuffer
then marks will drop out as they disappear from the buffer
12 13 14 15 |
# File 'lib/eventbuffer.rb', line 12 def initialize(maxsize=nil) @maxsize = maxsize reset end |
Instance Attribute Details
#buf ⇒ Object (readonly)
Returns the value of attribute buf.
7 8 9 |
# File 'lib/eventbuffer.rb', line 7 def buf @buf end |
#marks ⇒ Object
User position mark into buffer. If buffer is limited,
8 9 10 |
# File 'lib/eventbuffer.rb', line 8 def marks @marks end |
#maxsize ⇒ Object (readonly)
Maximum size of buffer or nil if unlimited.
9 10 11 |
# File 'lib/eventbuffer.rb', line 9 def maxsize @maxsize end |
#size ⇒ Object (readonly)
size of buffer
10 11 12 |
# File 'lib/eventbuffer.rb', line 10 def size @size end |
Instance Method Details
#add_mark ⇒ Object
Add mark for the current event buffer position.
44 45 46 |
# File 'lib/eventbuffer.rb', line 44 def add_mark @marks << @pos end |
#add_mark_nodup ⇒ Object
Like add mark, but do only if the last marked position has changed
50 51 52 |
# File 'lib/eventbuffer.rb', line 50 def add_mark_nodup @marks << @pos unless @marks[-1] == @pos end |
#append(event, frame, arg) ⇒ Object
Add a new event dropping off old events if that was declared marks are also dropped if buffer has a limit.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/eventbuffer.rb', line 26 def append(event, frame, arg) if 'c-return' == event arg = frame.sp(2) elsif 'return' == event arg = frame.sp(1) end iseq = frame.iseq item = EventStruct.new(event, arg, frame.type, frame.thread, frame.method, frame.source_container, frame.source_location, iseq, iseq ? frame.pc_offset : nil) @pos = self.succ_pos @marks.shift if @marks[0] == @pos @buf[@pos] = item @size += 1 unless @maxsize && @size == @maxsize end |
#each(from = nil, to = nil) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/eventbuffer.rb', line 54 def each(from=nil, to=nil) from = self.succ_pos unless from to = @pos unless to if from <= to from.upto(to).each do |pos| yield @buf[pos] end else from.upto(@size-1).each do |pos| yield @buf[pos] end 0.upto(@pos).each do |pos| yield @buf[pos] end end end |
#each_with_index(from = nil, to = nil) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/eventbuffer.rb', line 71 def each_with_index(from=nil, to=nil) from = succ_pos unless from to = @pos unless to if from <= to from.upto(to).each do |pos| yield [@buf[pos], pos] end else from.upto(@size-1).each do |pos| yield [@buf[pos], pos] end 0.upto(@pos).each do |pos| yield [@buf[pos], pos] end end end |
#format_entry(item, long_format = true) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/eventbuffer.rb', line 88 def format_entry(item, long_format=true) # require 'rbdbgr'; Debugger.debug container = if item.source_container[0] == 'file' item.source_container[1].inspect else item.source_container.inspect end location = if 1 == item.source_location.size item.source_location[0].inspect else item.source_location.inspect end mess = "#{item.event} #{item.type} #{item.method} " + "#{container} #{location}" if long_format && item.iseq mess += "\n\t" + "VM offset #{item.pc_offset} of #{item.iseq.name}" end mess end |
#pred_pos(dec = 1) ⇒ Object
Return the next event buffer position taking into account that we may have a fixed-sized buffer ring.
121 122 123 124 |
# File 'lib/eventbuffer.rb', line 121 def pred_pos(dec=1) pos = @pos - dec @maxsize ? pos % @maxsize : pos end |
#reset ⇒ Object
17 18 19 20 21 22 |
# File 'lib/eventbuffer.rb', line 17 def reset @buf = [] @marks = [] @pos = -1 @size = 0 end |
#succ_pos(inc = 1) ⇒ Object
Return the next event buffer position taking into account that we may have a fixed-sized buffer ring.
114 115 116 117 |
# File 'lib/eventbuffer.rb', line 114 def succ_pos(inc=1) pos = @pos + inc @maxsize ? pos % @maxsize : pos end |
#zero_pos ⇒ Object
Return the adjusted zeroth position in @buf.
127 128 129 130 131 132 133 |
# File 'lib/eventbuffer.rb', line 127 def zero_pos if !@maxsize || @buf.size < @maxsize 0 else self.succ_pos end end |