Class: Tracer
Overview
tracer main class
Constant Summary
- EVENT_SYMBOL =
{ "line" => "-", "call" => ">", "return" => "<", "class" => "C", "end" => "E", "raise" => "^", "c-call" => "}", "c-return" => "{", "unknown" => "?" }
- Single =
new
Class Attribute Summary (collapse)
-
+ (Object) display_c_call
(also: display_c_call?)
display builtin method call?.
-
+ (Object) display_process_id
(also: display_process_id?)
display process id?.
-
+ (Object) display_thread_id
(also: display_thread_id?)
display thread id?.
-
+ (Object) stdout
Returns the value of attribute stdout.
-
+ (Object) stdout_mutex
readonly
Returns the value of attribute stdout_mutex.
-
+ (Object) verbose
(also: verbose?)
Returns the value of attribute verbose.
Class Method Summary (collapse)
- + (Object) add_filter(p = proc)
- + (Object) off
- + (Object) on
- + (Object) set_get_line_procs(file_name, p = proc)
- + (Object) trace_func(*vars)
Instance Method Summary (collapse)
- - (Object) add_filter(p = proc)
- - (Object) get_line(file, line)
- - (Object) get_thread_no
-
- (Tracer) initialize
constructor
A new instance of Tracer.
- - (Object) off
- - (Object) on
- - (Object) set_get_line_procs(file, p = proc)
- - (Object) stdout
- - (Object) trace_func(event, file, line, id, binding, klass)
Constructor Details
- (Tracer) initialize
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
+ (Object) display_c_call 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 |
+ (Object) display_process_id 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 |
+ (Object) display_thread_id 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 |
+ (Object) stdout
Returns the value of attribute stdout
20 21 22 |
# File 'lib/tracer.rb', line 20 def stdout @stdout end |
+ (Object) stdout_mutex (readonly)
Returns the value of attribute stdout_mutex
21 22 23 |
# File 'lib/tracer.rb', line 21 def stdout_mutex @stdout_mutex end |
+ (Object) verbose 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
+ (Object) add_filter(p = proc)
179 180 181 |
# File 'lib/tracer.rb', line 179 def Tracer.add_filter(p = proc) Single.add_filter(p) end |
+ (Object) off
171 172 173 |
# File 'lib/tracer.rb', line 171 def Tracer.off Single.off end |
+ (Object) on
163 164 165 166 167 168 169 |
# File 'lib/tracer.rb', line 163 def Tracer.on if block_given? Single.on{yield} else Single.on end end |
+ (Object) set_get_line_procs(file_name, p = proc)
175 176 177 |
# File 'lib/tracer.rb', line 175 def Tracer.set_get_line_procs(file_name, p = proc) Single.set_get_line_procs(file_name, p) end |
+ (Object) trace_func(*vars)
16 17 18 |
# File 'lib/debug.rb', line 16 def Tracer.trace_func(*vars) Single.trace_func(*vars) end |
Instance Method Details
- (Object) add_filter(p = proc)
91 92 93 |
# File 'lib/tracer.rb', line 91 def add_filter(p = proc) @filters.push p end |
- (Object) get_line(file, line)
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 |
- (Object) get_thread_no
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 |
- (Object) off
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 |
- (Object) on
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 |
- (Object) set_get_line_procs(file, p = proc)
95 96 97 |
# File 'lib/tracer.rb', line 95 def set_get_line_procs(file, p = proc) @get_line_procs[file] = p end |
- (Object) stdout
68 69 70 |
# File 'lib/tracer.rb', line 68 def stdout Tracer.stdout end |
- (Object) trace_func(event, file, line, id, binding, klass)
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 |