xtrace 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in xtrace.gemspec
4
+ gemspec
data/README ADDED
@@ -0,0 +1,4 @@
1
+ Usage:
2
+ xtrace < /path/to/tracefile.xt
3
+
4
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.expand_path('.')) # Ruby 1.9 doesn't have . in the load path...
3
+ $:.push(File.expand_path('lib/'))
4
+
5
+ require 'xtrace'
6
+
7
+ parser = XTrace::Parser.new(STDIN)
8
+ parser.execute
9
+ parser.output
@@ -0,0 +1,6 @@
1
+ require "xtrace/version"
2
+ require "xtrace/call_tree"
3
+ require "xtrace/parser"
4
+
5
+ module XTrace
6
+ end
@@ -0,0 +1,55 @@
1
+ module XTrace
2
+ class CallTree
3
+ attr_accessor :call_trace, :call_depth, :call_time, :call_total_elapsed, :call_delta_elapsed,
4
+ :elapsed_time, :parent,
5
+ :calls
6
+
7
+ def initialize(call_trace, call_depth, call_time, call_total_elapsed, call_delta_elapsed)
8
+ @call_trace = call_trace.gsub(/\(.*\)/, '(...)')
9
+ @call_depth = call_depth
10
+ @call_time = call_time
11
+ @call_total_elapsed = call_total_elapsed
12
+ @call_delta_elapsed = call_delta_elapsed
13
+ @calls = []
14
+ @elapsed_time = call_delta_elapsed
15
+ end
16
+
17
+ def call_stack
18
+ if parent.nil?
19
+ [@call_trace]
20
+ else
21
+ [parent.call_stack, @call_trace].flatten
22
+ end
23
+ end
24
+
25
+ def call_path(delim = ' --> ')
26
+ call_stack.join(delim)
27
+ end
28
+
29
+ def add_time(elapsed_time)
30
+ @elapsed_time += elapsed_time
31
+ @parent.add_time(elapsed_time) unless @parent.nil?
32
+ end
33
+
34
+ def <<(call_tree)
35
+ add_time(call_tree.elapsed_time)
36
+ call_tree.parent = self
37
+ @calls << call_tree
38
+ end
39
+
40
+ def output
41
+ #if @calls.length > 1
42
+ if @elapsed_time > 1.0
43
+ prefix = ' ' * (@call_depth*2)
44
+ puts "#{prefix}Call: #{@call_trace}"
45
+ #puts "#{prefix}\tPath: \n\t > #{self.call_path("\n\t > ")}"
46
+ puts "#{prefix}\tSubcalls:#{@calls.length}"
47
+ puts "#{prefix}\tTime Elapsed: #{@elapsed_time}"
48
+ end
49
+ @calls.each do |call|
50
+ call.output
51
+ end
52
+ end
53
+ end
54
+ end
55
+
@@ -0,0 +1,69 @@
1
+ require 'iconv'
2
+
3
+ module XTrace
4
+ class Parser
5
+
6
+ attr_accessor :ic, :fh, :total_calls, :call_trees, :call_cache
7
+ #
8
+ # 0.0001 114976 -> {main}() /var/opt/content-8000/live/www/index.php:0
9
+ # 0.0003 115392 -> include_once(/var/opt/content-8000/live/www/LocalConfig.php) /var/opt/content-8000/live/www/index.php:10
10
+ # 0.0004 116112 -> dirname('/var/opt/content-8000/live/www/LocalConfig.php') /var/opt/content-8000/live/www/LocalConfig.php:15
11
+ # >=> '/var/opt/content-8000/live/www'
12
+
13
+ def initialize(fh = STDIN)
14
+ @ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
15
+ @fh = fh
16
+ @total_calls = 0
17
+ @call_trees = []
18
+ @call_tree = nil
19
+ @call_cache = {}
20
+ end
21
+
22
+ def execute
23
+ last_total_elapsed = 0.000
24
+ return_value = nil
25
+ while(line = @fh.gets)
26
+ line = @ic.iconv(line)
27
+ if line =~ /^\s+([\d.]+)\s+(\d+) ( *)-> (.*)$/
28
+ total_elapsed = $1.to_f
29
+ time = $2.to_i
30
+ depth = $3.to_s.length/2
31
+ trace = $4.to_s
32
+
33
+ delta_elapsed = total_elapsed - last_total_elapsed
34
+ @total_calls += 1
35
+ last_total_elapsed = total_elapsed
36
+
37
+ call_tree = CallTree.new(trace, depth, time, total_elapsed, delta_elapsed)
38
+
39
+ if depth == 0
40
+ @call_tree = call_tree
41
+ @call_trees << call_tree
42
+ else
43
+ #puts "depth:#{depth} parent:#{@call_cache[depth-1].call_trace} call:#{trace}"
44
+ @call_cache[depth-1] << call_tree
45
+ end
46
+
47
+ # Always set the last call_tree at a given depth
48
+ @call_cache[depth] = call_tree
49
+
50
+ if delta_elapsed > 0
51
+ #puts "[#{total_calls}] [#{depth}] [#{time}] [#{total_elapsed}] [#{delta_elapsed}] [#{trace}]"
52
+ end
53
+ else
54
+ return_value = line
55
+ end
56
+ end
57
+ end
58
+
59
+ def output
60
+ @call_trees.each do |call_tree|
61
+ call_tree.output
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ parser = XTrace::Parser.new(STDIN)
68
+ parser.execute
69
+ parser.output
@@ -0,0 +1,3 @@
1
+ module XTrace
2
+ VERSION = "1.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "xtrace/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "xtrace"
7
+ s.version = XTrace::VERSION
8
+ s.authors = ["Erik Osterman"]
9
+ s.email = ["e@osterman.com"]
10
+ s.homepage = "https://github.com/osterman/xtrace"
11
+ s.summary = %q{XTrace is a gem to evaluate .xt trace files generated by the XDebug PHP extension}
12
+ s.description = %q{XTrace is a gem to evaluate .xt trace files generated by the XDebug PHP extension}
13
+
14
+ s.rubyforge_project = "xtrace"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ #s.add_runtime_dependency "iconv"
24
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xtrace
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 1
9
+ version: 1.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Erik Osterman
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-07-01 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: XTrace is a gem to evaluate .xt trace files generated by the XDebug PHP extension
22
+ email:
23
+ - e@osterman.com
24
+ executables:
25
+ - xtrace
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - README
34
+ - Rakefile
35
+ - bin/xtrace
36
+ - lib/xtrace.rb
37
+ - lib/xtrace/call_tree.rb
38
+ - lib/xtrace/parser.rb
39
+ - lib/xtrace/version.rb
40
+ - xtrace.gemspec
41
+ has_rdoc: true
42
+ homepage: https://github.com/osterman/xtrace
43
+ licenses: []
44
+
45
+ post_install_message:
46
+ rdoc_options: []
47
+
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ requirements: []
65
+
66
+ rubyforge_project: xtrace
67
+ rubygems_version: 1.3.6
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: XTrace is a gem to evaluate .xt trace files generated by the XDebug PHP extension
71
+ test_files: []
72
+