Class: Tracer
- Inherits:
-
Object
- Object
- Tracer
- Defined in:
- lib/tracer.rb
Overview
tracer main class
Constant Summary collapse
- EVENT_SYMBOL =
{ "line" => "-", "call" => ">", "return" => "<", "class" => "C", "end" => "E", "raise" => "^", "c-call" => "}", "c-return" => "{", "unknown" => "?" }
- Single =
new
Class Attribute Summary collapse
-
.display_c_call ⇒ Object
(also: display_c_call?)
display builtin method call?.
-
.display_process_id ⇒ Object
(also: display_process_id?)
display process id?.
-
.display_thread_id ⇒ Object
(also: display_thread_id?)
display thread id?.
-
.stdout ⇒ Object
Returns the value of attribute stdout.
-
.stdout_mutex ⇒ Object
readonly
Returns the value of attribute stdout_mutex.
-
.verbose ⇒ Object
(also: verbose?)
Returns the value of attribute verbose.
Class Method Summary collapse
- .add_filter(p = proc) ⇒ Object
- .off ⇒ Object
- .on ⇒ Object
- .set_get_line_procs(file_name, p = proc) ⇒ Object
Instance Method Summary collapse
- #add_filter(p = proc) ⇒ Object
- #get_line(file, line) ⇒ Object
- #get_thread_no ⇒ Object
-
#initialize ⇒ Tracer
constructor
A new instance of Tracer.
- #off ⇒ Object
- #on ⇒ Object
- #set_get_line_procs(file, p = proc) ⇒ Object
- #stdout ⇒ Object
- #trace_func(event, file, line, id, binding, klass) ⇒ Object
Constructor Details
#initialize ⇒ Tracer
Returns a new instance of Tracer.
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/tracer.rb', line 55 def initialize @threads = Hash.new if defined? Thread.main @threads[Thread.main.object_id] = 0 else @threads[Thread.current.object_id] = 0 end @get_line_procs = {} @filters = [] end |
Class Attribute Details
.display_c_call ⇒ Object Also known as: display_c_call?
display builtin method call?
32 33 34 |
# File 'lib/tracer.rb', line 32 def display_c_call @display_c_call end |
.display_process_id ⇒ Object Also known as: display_process_id?
display process id?
24 25 26 |
# File 'lib/tracer.rb', line 24 def display_process_id @display_process_id end |
.display_thread_id ⇒ Object Also known as: display_thread_id?
display thread id?
28 29 30 |
# File 'lib/tracer.rb', line 28 def display_thread_id @display_thread_id end |
.stdout ⇒ Object
Returns the value of attribute stdout
20 21 22 |
# File 'lib/tracer.rb', line 20 def stdout @stdout end |
.stdout_mutex ⇒ Object (readonly)
Returns the value of attribute stdout_mutex
21 22 23 |
# File 'lib/tracer.rb', line 21 def stdout_mutex @stdout_mutex end |
.verbose ⇒ Object Also known as: verbose?
Returns the value of attribute verbose
17 18 19 |
# File 'lib/tracer.rb', line 17 def verbose @verbose end |
Class Method Details
.add_filter(p = proc) ⇒ Object
179 180 181 |
# File 'lib/tracer.rb', line 179 def Tracer.add_filter(p = proc) Single.add_filter(p) end |
Instance Method Details
#add_filter(p = proc) ⇒ Object
91 92 93 |
# File 'lib/tracer.rb', line 91 def add_filter(p = proc) @filters.push p end |
#get_line(file, line) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/tracer.rb', line 99 def get_line(file, line) if p = @get_line_procs[file] return p.call(line) end unless list = SCRIPT_LINES__[file] begin f = File::open(file) begin SCRIPT_LINES__[file] = list = f.readlines ensure f.close end rescue SCRIPT_LINES__[file] = list = [] end end if l = list[line - 1] l else "-\n" end end |
#get_thread_no ⇒ Object
124 125 126 127 128 129 130 |
# File 'lib/tracer.rb', line 124 def get_thread_no if no = @threads[Thread.current.object_id] no else @threads[Thread.current.object_id] = @threads.size end end |
#off ⇒ Object
86 87 88 89 |
# File 'lib/tracer.rb', line 86 def off set_trace_func nil stdout.print "Trace off\n" if Tracer.verbose? end |
#on ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/tracer.rb', line 72 def on if block_given? on begin yield ensure off end else set_trace_func method(:trace_func).to_proc stdout.print "Trace on\n" if Tracer.verbose? end end |
#set_get_line_procs(file, p = proc) ⇒ Object
95 96 97 |
# File 'lib/tracer.rb', line 95 def set_get_line_procs(file, p = proc) @get_line_procs[file] = p end |
#trace_func(event, file, line, id, binding, klass) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/tracer.rb', line 132 def trace_func(event, file, line, id, binding, klass, *) return if file == __FILE__ for p in @filters return unless p.call event, file, line, id, binding, klass end return unless Tracer::display_c_call? or event != "c-call" && event != "c-return" Tracer::stdout_mutex.synchronize do if EVENT_SYMBOL[event] stdout.printf("<%d>", $$) if Tracer::display_process_id? stdout.printf("#%d:", get_thread_no) if Tracer::display_thread_id? if line == 0 source = "?\n" else source = get_line(file, line) end printf("%s:%d:%s:%s: %s", file, line, klass || '', EVENT_SYMBOL[event], source) end end end |