Class: Fiber

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

Overview

Copyright © 2009-2011 VMware, Inc.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#trace_idObject

Returns the value of attribute trace_id.



3
4
5
# File 'lib/vcap/fiber_tracing.rb', line 3

def trace_id
  @trace_id
end

Class Method Details

.enable_tracing(io) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
# File 'lib/vcap/fiber_tracing.rb', line 11

def enable_tracing(io)
  raise ArgumentError, "You must pass in IO object, #{io.class} given" unless io.is_a? IO
  @io = io
end

.log_action(action, f = nil) ⇒ Object



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

def log_action(action, f=nil)
  return unless @io
  f ||= Fiber.current
  trace_id = f.trace_id || '-'
  cname = Kernel.caller[1]
  @io.puts("FT %-14s %-20s %-30s %s" % [action, trace_id, f.object_id, cname])
  @io.flush
end

.orig_yieldObject



9
# File 'lib/vcap/fiber_tracing.rb', line 9

alias_method :orig_yield, :yield

.yield(*args) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/vcap/fiber_tracing.rb', line 16

def yield(*args)
  log_action('yield')
  begin
    orig_yield(*args)
  rescue FiberError => fe
    Fiber.log_action('yield_error', self)
    raise fe
  end
end

Instance Method Details

#orig_resumeObject



4
# File 'lib/vcap/fiber_tracing.rb', line 4

alias_method :orig_resume, :resume

#resume(*args) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/vcap/fiber_tracing.rb', line 36

def resume(*args)
  Fiber.log_action('resume', self)
  begin
    orig_resume(*args)
  rescue FiberError => fe
    Fiber.log_action('resume_error', self)
    raise fe
  end
end