Class: DtraceData

Inherits:
Object
  • Object
show all
Defined in:
lib/dtracedata.rb

Overview

Ruby-Dtrace © 2007 Chris Andrews <[email protected]>

The object returned from a consumer when a probe fires. Accumulates records from the callbacks, and is yielded when the data is complete.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDtraceData

Returns a new instance of DtraceData.



12
13
14
15
16
# File 'lib/dtracedata.rb', line 12

def initialize
  @data = []
  @curraggset = nil
  @curragg    = nil
end

Instance Attribute Details

#cpuObject (readonly)

Returns the value of attribute cpu.



10
11
12
# File 'lib/dtracedata.rb', line 10

def cpu
  @cpu
end

#dataObject (readonly)

Returns the value of attribute data.



8
9
10
# File 'lib/dtracedata.rb', line 8

def data
  @data
end

#flowObject (readonly)

Returns the value of attribute flow.



10
11
12
# File 'lib/dtracedata.rb', line 10

def flow
  @flow
end

#indentObject (readonly)

Returns the value of attribute indent.



10
11
12
# File 'lib/dtracedata.rb', line 10

def indent
  @indent
end

#prefixObject (readonly)

Returns the value of attribute prefix.



10
11
12
# File 'lib/dtracedata.rb', line 10

def prefix
  @prefix
end

#probeObject (readonly)

Returns the value of attribute probe.



9
10
11
# File 'lib/dtracedata.rb', line 9

def probe
  @probe
end

Instance Method Details

#add_bufdata(buf) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/dtracedata.rb', line 48

def add_bufdata(buf)
  r = buf.record
  # buf records can be empty (trace();)
  if r
    case r.class.to_s
    when DtraceStackRecord.to_s
      @data << r
    when DtraceRecord.to_s
      @data << r
    when DtracePrintfRecord.to_s
      @data << r
    when DtraceAggData.to_s
      if @curragg == nil
        @curragg = DtraceAggregate.new
      end
      if agg = @curragg.add_record(r)
        if @curraggset
          @curraggset.add_aggregate(@curragg)
        end
        @curragg = nil
      end
    end
  end
end

#add_probedata(probedata) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/dtracedata.rb', line 35

def add_probedata(probedata)
  probedata.each_record do |p|
    @data << p
  end

  # Record the probe that fired, and CPU/indent/prefix/flow
  @probe  = probedata.probe
  @cpu    = probedata.cpu
  @indent = probedata.indent
  @prefix = probedata.prefix
  @flow   = probedata.flow
end

#add_recdata(rec) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/dtracedata.rb', line 25

def add_recdata(rec)
  if @curraggset
    @data << @curraggset
    @curraggset = nil
  end
  if rec.action == "printa"
    @curraggset = DtraceAggregateSet.new
  end
end

#finishObject



18
19
20
21
22
23
# File 'lib/dtracedata.rb', line 18

def finish
  if @curraggset
    @data << @curraggset
    @curraggset = nil
  end
end