Class: XTrace::Parser
- Inherits:
-
Object
- Object
- XTrace::Parser
- Defined in:
- lib/xtrace/parser.rb
Instance Attribute Summary collapse
-
#call_cache ⇒ Object
Returns the value of attribute call_cache.
-
#call_trees ⇒ Object
Returns the value of attribute call_trees.
-
#fh ⇒ Object
Returns the value of attribute fh.
-
#ic ⇒ Object
Returns the value of attribute ic.
-
#total_calls ⇒ Object
Returns the value of attribute total_calls.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(fh = STDIN) ⇒ Parser
constructor
0.0001 114976 -> main() /var/opt/content-8000/live/www/index.php:0 0.0003 115392 -> include_once(/var/opt/content-8000/live/www/LocalConfig.php) /var/opt/content-8000/live/www/index.php:10 0.0004 116112 -> dirname(‘/var/opt/content-8000/live/www/LocalConfig.php’) /var/opt/content-8000/live/www/LocalConfig.php:15 >=> ‘/var/opt/content-8000/live/www’.
- #output ⇒ Object
Constructor Details
#initialize(fh = STDIN) ⇒ Parser
0.0001 114976 -> main() /var/opt/content-8000/live/www/index.php:0
0.0003 115392 -> include_once(/var/opt/content-8000/live/www/LocalConfig.php) /var/opt/content-8000/live/www/index.php:10
0.0004 116112 -> dirname('/var/opt/content-8000/live/www/LocalConfig.php') /var/opt/content-8000/live/www/LocalConfig.php:15
>=> '/var/opt/content-8000/live/www'
13 14 15 16 17 18 19 20 |
# File 'lib/xtrace/parser.rb', line 13 def initialize(fh = STDIN) @ic = Iconv.new('UTF-8//IGNORE', 'UTF-8') @fh = fh @total_calls = 0 @call_trees = [] @call_tree = nil @call_cache = {} end |
Instance Attribute Details
#call_cache ⇒ Object
Returns the value of attribute call_cache.
6 7 8 |
# File 'lib/xtrace/parser.rb', line 6 def call_cache @call_cache end |
#call_trees ⇒ Object
Returns the value of attribute call_trees.
6 7 8 |
# File 'lib/xtrace/parser.rb', line 6 def call_trees @call_trees end |
#fh ⇒ Object
Returns the value of attribute fh.
6 7 8 |
# File 'lib/xtrace/parser.rb', line 6 def fh @fh end |
#ic ⇒ Object
Returns the value of attribute ic.
6 7 8 |
# File 'lib/xtrace/parser.rb', line 6 def ic @ic end |
#total_calls ⇒ Object
Returns the value of attribute total_calls.
6 7 8 |
# File 'lib/xtrace/parser.rb', line 6 def total_calls @total_calls end |
Instance Method Details
#execute ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/xtrace/parser.rb', line 22 def execute last_total_elapsed = 0.000 return_value = nil while(line = @fh.gets) line = @ic.iconv(line) if line =~ /^\s+([\d.]+)\s+(\d+) ( *)-> (.*)$/ total_elapsed = $1.to_f time = $2.to_i depth = $3.to_s.length/2 trace = $4.to_s delta_elapsed = total_elapsed - last_total_elapsed @total_calls += 1 last_total_elapsed = total_elapsed call_tree = CallTree.new(trace, depth, time, total_elapsed, delta_elapsed) if depth == 0 @call_tree = call_tree @call_trees << call_tree else #puts "depth:#{depth} parent:#{@call_cache[depth-1].call_trace} call:#{trace}" @call_cache[depth-1] << call_tree end # Always set the last call_tree at a given depth @call_cache[depth] = call_tree if delta_elapsed > 0 #puts "[#{total_calls}] [#{depth}] [#{time}] [#{total_elapsed}] [#{delta_elapsed}] [#{trace}]" end else return_value = line end end end |
#output ⇒ Object
59 60 61 62 63 |
# File 'lib/xtrace/parser.rb', line 59 def output @call_trees.each do |call_tree| call_tree.output end end |