Class: ProcessTail::Tracer

Inherits:
Object
  • Object
show all
Defined in:
lib/process_tail.rb,
ext/process_tail/process_tail.c

Constant Summary collapse

TRACE_LOCK =
rb_class_new_instance(0, NULL, rb_path2class("Mutex"))

Instance Method Summary collapse

Instance Method Details

#attachObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/process_tail.rb', line 20

def attach
  case
  when respond_to?(:ptrace_attach, true)
    ptrace_attach
  when respond_to?(:dtrace_attach, true)
    dtrace_attach
  else
    raise NotImplementedError
  end

  self
end

#detachObject



41
42
43
44
45
# File 'lib/process_tail.rb', line 41

def detach
  trace_thread.kill if trace_thread.alive?

  wait
end

#fdObject



64
65
66
67
68
69
70
71
72
# File 'ext/process_tail/process_tail.c', line 64

static VALUE
pt_process_tail_fd_reader(VALUE self)
{
  pt_process_tail_t *ptp;

  Data_Get_Struct(self, pt_process_tail_t, ptp);

  return INT2NUM((int)ptp->fd);
}

#pidObject



54
55
56
57
58
59
60
61
62
# File 'ext/process_tail/process_tail.c', line 54

static VALUE
pt_process_tail_pid_reader(VALUE self)
{
  pt_process_tail_t *ptp;

  Data_Get_Struct(self, pt_process_tail_t, ptp);

  return INT2NUM((int)ptp->pid);
}

#trace_threadObject



74
75
76
77
78
79
80
81
82
# File 'ext/process_tail/process_tail.c', line 74

static VALUE
pt_process_tail_trace_thread_reader(VALUE self)
{
  pt_process_tail_t *ptp;

  Data_Get_Struct(self, pt_process_tail_t, ptp);

  return ptp->trace_thread;
}

#waitObject



33
34
35
36
37
38
39
# File 'lib/process_tail.rb', line 33

def wait
  trace_thread.join

  self
rescue StopTracing
  # NOP
end