Class: RbBCC::USDT

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pid: nil, path: nil) ⇒ USDT

Returns a new instance of USDT.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rbbcc/usdt.rb', line 7

def initialize(pid: nil, path: nil)
  @pid = pid
  @path = path
  if pid
    @context = Clib.bcc_usdt_new_frompid(pid, path)
  elsif path
    @context = Clib.bcc_usdt_new_frompath(path)
  else
    raise "Either a pid or a binary path must be specified"
  end
  if !@context || @context.null?
    raise SystemCallError.new(Fiddle.last_error)
  end
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



21
22
23
# File 'lib/rbbcc/usdt.rb', line 21

def context
  @context
end

#pathObject (readonly)

Returns the value of attribute path.



21
22
23
# File 'lib/rbbcc/usdt.rb', line 21

def path
  @path
end

#pidObject (readonly)

Returns the value of attribute pid.



21
22
23
# File 'lib/rbbcc/usdt.rb', line 21

def pid
  @pid
end

Instance Method Details

#enable_probe(probe:, fn_name:) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/rbbcc/usdt.rb', line 23

def enable_probe(probe:, fn_name:)
  ret = Clib.bcc_usdt_enable_probe(@context, probe, fn_name)
  if(ret < 0)
    raise SystemCallError.new(Fiddle.last_error)
  end
  ret
end

#enumerate_active_probesObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rbbcc/usdt.rb', line 31

def enumerate_active_probes
  probes = []
  callback = Clib.bind('void _usdt_cb(char *, char *, unsigned long long, int)') do |binpath, fn_name, addr, pid|
    probe = USDTProbe.new(Clib.__extract_char(binpath), Clib.__extract_char(fn_name), addr, pid)
    probes << probe
  end

  Clib.bcc_usdt_foreach_uprobe(@context, callback)

  return probes
end