Class: Dtrace::Consumer
- Inherits:
-
Object
- Object
- Dtrace::Consumer
- Defined in:
- lib/dtrace/consumer.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#consume(*types, &block) ⇒ Object
Waits for data from the D program, and yields the records returned to the block given.
-
#consume_once(*types, &block) ⇒ Object
Yields the data waiting from the current program, then returns.
-
#drophandler(&block) ⇒ Object
Provide a proc which will be executed when a drop record is received.
-
#errhandler(&block) ⇒ Object
Provide a proc which will be executed when an error record is received.
-
#finish ⇒ Object
Signals that the client wishes to stop consuming trace data.
-
#initialize(t) ⇒ Consumer
constructor
A new instance of Consumer.
Constructor Details
#initialize(t) ⇒ Consumer
Returns a new instance of Consumer.
43 44 45 46 47 48 49 50 |
# File 'lib/dtrace/consumer.rb', line 43 def initialize(t) @t = t @done = false @types = [] @drophandler = nil @errhandler = nil end |
Instance Method Details
#consume(*types, &block) ⇒ Object
Waits for data from the D program, and yields the records returned to the block given. Returns when the D program exits.
Pass a list of classes to restrict the types of data returned, from:
-
DtraceRecord
-
DtracePrintfRecord
-
DtraceAggregateSet
-
DtraceStackRecord
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/dtrace/consumer.rb', line 139 def consume(*types, &block) filter_types(types) @t.buf_consumer(buf_consumer) begin while(true) do @t.sleep work = @t.work(probe_consumer, rec_consumer(block)) if (@done || work > 0) break end end ensure @t.stop @t.work(probe_consumer) end end |
#consume_once(*types, &block) ⇒ Object
Yields the data waiting from the current program, then returns.
Pass a list of classes to restrict the types of data returned, from:
-
DtraceRecord
-
DtracePrintfRecord
-
DtraceAggregateSet
-
DtraceStackRecord
166 167 168 169 170 171 |
# File 'lib/dtrace/consumer.rb', line 166 def consume_once(*types, &block) filter_types(types) @t.buf_consumer(buf_consumer) @t.stop @t.work(probe_consumer, rec_consumer(block)) end |
#drophandler(&block) ⇒ Object
Provide a proc which will be executed when a drop record is received.
102 103 104 105 106 107 108 109 |
# File 'lib/dtrace/consumer.rb', line 102 def drophandler(&block) @drophandler = block @t.drop_consumer(proc do |drop| if @drophandler @drophandler.call(drop) end end) end |
#errhandler(&block) ⇒ Object
Provide a proc which will be executed when an error record is received.
113 114 115 116 117 118 119 120 |
# File 'lib/dtrace/consumer.rb', line 113 def errhandler(&block) @errhandler = block @t.err_consumer(proc do |err| if @errhandler @errhandler.call(err) end end) end |
#finish ⇒ Object
Signals that the client wishes to stop consuming trace data.
123 124 125 126 |
# File 'lib/dtrace/consumer.rb', line 123 def finish @t.stop @done = true end |