Class: Minstrel::Event

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action, file, line, method, binding, klass) ⇒ Event

Returns a new instance of Event.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/minstrel.rb', line 33

def initialize(action, file, line, method, binding, klass)
  @action = action
  @file = file
  @line = line
  @method = method
  @binding = binding
  @class = klass
  @timestamp = Time.now

  if ["c-call", "call"].include?(@action)
    @args_hash = {}
    @args_order = eval('local_variables', binding)

    # In ruby 1.9, local_variables returns an array of symbols, not strings.
    @args_order.collect { |v| @args_hash[v] = eval(v.to_s, binding) }
  end

  @block_given = eval('block_given?', @binding)
end

Instance Attribute Details

#actionObject

Returns the value of attribute action.



16
17
18
# File 'lib/minstrel.rb', line 16

def action
  @action
end

#args_hashObject

Returns the value of attribute args_hash.



22
23
24
# File 'lib/minstrel.rb', line 22

def args_hash
  @args_hash
end

#args_orderObject

Returns the value of attribute args_order.



23
24
25
# File 'lib/minstrel.rb', line 23

def args_order
  @args_order
end

#bindingObject

Returns the value of attribute binding.



20
21
22
# File 'lib/minstrel.rb', line 20

def binding
  @binding
end

#classObject

Returns the value of attribute class.



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

def class
  @class
end

#depthObject

The call stack depth of this event



30
31
32
# File 'lib/minstrel.rb', line 30

def depth
  @depth
end

#durationObject

Duration is only valid for ‘return’ or ‘c-return’ events



27
28
29
# File 'lib/minstrel.rb', line 27

def duration
  @duration
end

#fileObject

Returns the value of attribute file.



17
18
19
# File 'lib/minstrel.rb', line 17

def file
  @file
end

#lineObject

Returns the value of attribute line.



18
19
20
# File 'lib/minstrel.rb', line 18

def line
  @line
end

#methodObject

Returns the value of attribute method.



19
20
21
# File 'lib/minstrel.rb', line 19

def method
  @method
end

#timestampObject

Returns the value of attribute timestamp.



24
25
26
# File 'lib/minstrel.rb', line 24

def timestamp
  @timestamp
end

Instance Method Details

#argsObject



55
56
57
58
# File 'lib/minstrel.rb', line 55

def args
  return nil unless @args_order
  return @args_order.collect { |v| @args_hash[v] }
end

#block_given?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/minstrel.rb', line 82

def block_given?
  @block_given
end

#entry?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/minstrel.rb', line 70

def entry?
  return ["c-call", "call"].include?(action)
end

#exit?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/minstrel.rb', line 76

def exit?
  return ["c-return", "return"].include?(action)
end

#symbolObject



87
88
89
90
91
92
93
94
# File 'lib/minstrel.rb', line 87

def symbol
  case @action
    when "c-call", "call" ; return "=>"
    when "c-return", "return" ; return "<="
    when "raise"; return "<E"
    else return " +"
  end
end

#to_sObject



97
98
99
# File 'lib/minstrel.rb', line 97

def to_s
  return "#{"  " * @depth}#{symbol} #{@class.to_s}##{@method}(#{args.inspect}) #{block_given? ? "{ ... }" : ""} (thread=#{Thread.current}) #{@duration.nil? ? "" : sprintf("(%.5f seconds)", @duration)}"
end


61
62
63
64
65
66
# File 'lib/minstrel.rb', line 61

def use_related_event(event)
  @args_order = event.args_order
  @args_hash = event.args_hash
  @block_given = event.block_given?
  @duration = @timestamp - event.timestamp
end