pline 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. data/README +134 -0
  2. data/ext/pline/depend +55 -0
  3. data/ext/pline/extconf.rb +14 -0
  4. data/ext/pline/iseq.c +124 -0
  5. data/ext/pline/minfo.c +167 -0
  6. data/ext/pline/pline.c.rb +68 -0
  7. data/ext/pline/profiler.c +125 -0
  8. data/ext/pline/ruby_source/1.9.2/debug.h +36 -0
  9. data/ext/pline/ruby_source/1.9.2/eval_intern.h +232 -0
  10. data/ext/pline/ruby_source/1.9.2/gc.h +77 -0
  11. data/ext/pline/ruby_source/1.9.2/id.h +170 -0
  12. data/ext/pline/ruby_source/1.9.2/insns.inc +179 -0
  13. data/ext/pline/ruby_source/1.9.2/insns_info.inc +695 -0
  14. data/ext/pline/ruby_source/1.9.2/iseq.h +104 -0
  15. data/ext/pline/ruby_source/1.9.2/manual_update.h +19 -0
  16. data/ext/pline/ruby_source/1.9.2/method.h +103 -0
  17. data/ext/pline/ruby_source/1.9.2/node.h +483 -0
  18. data/ext/pline/ruby_source/1.9.2/thread_pthread.h +27 -0
  19. data/ext/pline/ruby_source/1.9.2/thread_win32.h +33 -0
  20. data/ext/pline/ruby_source/1.9.2/vm_core.h +706 -0
  21. data/ext/pline/ruby_source/1.9.2/vm_exec.h +184 -0
  22. data/ext/pline/ruby_source/1.9.2/vm_insnhelper.c +1734 -0
  23. data/ext/pline/ruby_source/1.9.2/vm_insnhelper.h +208 -0
  24. data/ext/pline/ruby_source/1.9.2/vm_opts.h +51 -0
  25. data/ext/pline/ruby_source/1.9.3/atomic.h +56 -0
  26. data/ext/pline/ruby_source/1.9.3/constant.h +34 -0
  27. data/ext/pline/ruby_source/1.9.3/debug.h +41 -0
  28. data/ext/pline/ruby_source/1.9.3/eval_intern.h +234 -0
  29. data/ext/pline/ruby_source/1.9.3/gc.h +98 -0
  30. data/ext/pline/ruby_source/1.9.3/id.h +175 -0
  31. data/ext/pline/ruby_source/1.9.3/insns.inc +179 -0
  32. data/ext/pline/ruby_source/1.9.3/insns_info.inc +695 -0
  33. data/ext/pline/ruby_source/1.9.3/internal.h +227 -0
  34. data/ext/pline/ruby_source/1.9.3/iseq.h +125 -0
  35. data/ext/pline/ruby_source/1.9.3/manual_update.h +19 -0
  36. data/ext/pline/ruby_source/1.9.3/method.h +105 -0
  37. data/ext/pline/ruby_source/1.9.3/node.h +503 -0
  38. data/ext/pline/ruby_source/1.9.3/thread_pthread.h +51 -0
  39. data/ext/pline/ruby_source/1.9.3/thread_win32.h +40 -0
  40. data/ext/pline/ruby_source/1.9.3/vm_core.h +756 -0
  41. data/ext/pline/ruby_source/1.9.3/vm_exec.h +184 -0
  42. data/ext/pline/ruby_source/1.9.3/vm_insnhelper.c +1749 -0
  43. data/ext/pline/ruby_source/1.9.3/vm_insnhelper.h +220 -0
  44. data/ext/pline/ruby_source/1.9.3/vm_opts.h +51 -0
  45. data/ext/pline/sinfo.c +311 -0
  46. data/lib/pline.rb +11 -0
  47. data/lib/pline/minfo.rb +22 -0
  48. data/lib/pline/summarize.rb +127 -0
  49. data/lib/pline/util.rb +54 -0
  50. data/pline.gemspec +28 -0
  51. metadata +102 -0
@@ -0,0 +1,11 @@
1
+ require 'pline.so'
2
+ require 'pline/util'
3
+ require 'pline/minfo'
4
+ require 'pline/summarize'
5
+
6
+ module PLine
7
+ extend PLine::Util
8
+ extend PLine::Summarize
9
+ at_exit{summarize}
10
+ end
11
+
@@ -0,0 +1,22 @@
1
+ module PLine
2
+ class MethodInfo
3
+ ALL = []
4
+
5
+ def description()
6
+ "#{obj}#{singleton? ? '.' : '#'}#{mid}: #{spath}(#{sline} - #{eline})"
7
+ end
8
+
9
+ def self.register(m)
10
+ bug() unless m.is_a?(MethodInfo)
11
+ ALL << m
12
+ end
13
+
14
+ def self.each()
15
+ ALL.each do |m|
16
+ bug() unless m.is_a?(MethodInfo)
17
+ yield(m)
18
+ end
19
+ end
20
+ end
21
+ end
22
+
@@ -0,0 +1,127 @@
1
+ module PLine
2
+ module Summarize
3
+ DEFAULT_OUTPUT = STDERR
4
+ @@output = DEFAULT_OUTPUT
5
+ def output=(io)
6
+ @@output = io
7
+ end
8
+
9
+ DIVISOR_NSEC = 1
10
+ DIVISOR_USEC = DIVISOR_NSEC * 1000
11
+ DIVISOR_MSEC = DIVISOR_USEC * 1000
12
+ DIVISOR_SEC = DIVISOR_MSEC * 1000
13
+ @@divisor = DIVISOR_USEC
14
+ @@time_label = :usec
15
+
16
+ def show_nsec()
17
+ @@divisor = DIVISOR_NSEC
18
+ @@time_label = :nsec
19
+ end
20
+
21
+ def show_usec()
22
+ @@divisor = DIVISOR_USEC
23
+ @@time_label = :usec
24
+ end
25
+
26
+ def show_msec()
27
+ @@divisor = DIVISOR_MSEC
28
+ @@time_label = :msec
29
+ end
30
+
31
+ def show_sec()
32
+ @@divisor = DIVISOR_SEC
33
+ @@time_label = :sec
34
+ end
35
+
36
+ private
37
+
38
+ def build_message(desc, labels, contents, align, pretty = true)
39
+ results = []
40
+ l_desc = desc.length
41
+ column_size = labels.size
42
+ contents = contents.inject([]) do |ary, c|
43
+ bug() unless c.size == column_size
44
+ c.map! do |v|
45
+ v.split("\n")
46
+ end
47
+ max = c.inject(0) do |m, v|
48
+ l = v.size
49
+ m > l ? m : l
50
+ end
51
+ max.times do |i|
52
+ ary << c.map{|v| v[i] || ''}
53
+ end
54
+ ary
55
+ end
56
+ l_labels = contents.inject(labels.map{|t| t.length}) do |a0, a1|
57
+ bug() unless a0.size == a1.size
58
+ a0.zip(a1).map do |(v0, v1)|
59
+ length = v1.length
60
+ v0 > length ? v0 : length
61
+ end
62
+ end
63
+ title = labels.zip(l_labels).map{|(t, l)| t.center(l)}.join(" | ")
64
+ l_title = title.length
65
+ width = l_desc > l_title ? l_desc : l_title
66
+ if width != l_title
67
+ bonus = width - l_title
68
+ adjust = column_size - bonus % column_size
69
+ width += adjust
70
+ bonus += adjust
71
+ bonus /= column_size
72
+ l_labels.map!{|l| l + bonus}
73
+ title = labels.zip(l_labels).map{|(t, l)| t.center(l)}.join(" | ")
74
+ end
75
+ width += 2
76
+ sep = "-" * width
77
+ results << " #{sep} "
78
+ results << "|#{desc.center(width)}|"
79
+ results << "|#{sep}|"
80
+ results << "|#{title.center(width)}|"
81
+ results << "|#{sep}|"
82
+ if pretty
83
+ side = "|"
84
+ else
85
+ side = ""
86
+ end
87
+ contents.each do |line|
88
+ center = line.zip(l_labels).zip(align).map{|(c, l), m|
89
+ pretty ? c.__send__(m, l) : c
90
+ }.join(" | ")
91
+ results << "#{side} #{center} #{side}"
92
+ end
93
+ results << " #{sep} "
94
+ results.map{|s| s.force_encoding('ASCII-8BIT')}.join("\n")
95
+ end
96
+
97
+ def summarize()
98
+ files = {}
99
+ MethodInfo.each do |m|
100
+ bug() unless m.is_a?(MethodInfo)
101
+ minfos = files[m.spath] ||= []
102
+ minfos << m
103
+ end
104
+ labels = ["Line", "Time(#{@@time_label})", "Source"]
105
+ align = [:rjust, :rjust, :ljust]
106
+ files.each do |spath, minfos|
107
+ sinfo = SourceInfo.find(spath)
108
+ next unless sinfo
109
+ lines = sinfo.lines
110
+ source = File.readlines(spath)
111
+ minfos.each do |m|
112
+ contents = []
113
+ next if lines.size < m.eline
114
+ lines[(m.sline - 1)..(m.eline - 1)].each_with_index do |t, idx|
115
+ line = m.sline + idx
116
+ contents << [line.to_s, (t / @@divisor).to_s, source[line - 1]]
117
+ end
118
+ @@output.puts()
119
+ desc = " #{m.description} "
120
+ msg = build_message(desc, labels, contents, align)
121
+ @@output.puts(msg)
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
127
+
@@ -0,0 +1,54 @@
1
+ module PLine::Util
2
+ private
3
+
4
+ @@debug_level = 0
5
+ @@verbose_mode = false
6
+
7
+ DEBUG_LEVEL_MAX = 2
8
+ def self.set_debug_level(lv)
9
+ raise(ArgumentError.new("debug level should be Integer")) unless lv.is_a?(Integer)
10
+ raise(ArgumentError.new("debug level should be >= 0 && <= #{DEBUG_LEVEL_MAX}")) unless 0 <= lv && lv <= DEBUG_LEVEL_MAX
11
+ @@debug_level = lv
12
+ end
13
+
14
+ def self.set_verbose_mode(b)
15
+ @@verbose_mode = b
16
+ end
17
+
18
+ def dlog(message, level = 1)
19
+ if level <= @@debug_level
20
+ STDERR.puts(message)
21
+ end
22
+ end
23
+ public(:dlog)
24
+
25
+ def vlog(message)
26
+ if @@verbose_mode || @@debug_level > 0
27
+ STDERR.puts(message)
28
+ end
29
+ end
30
+ public(:vlog)
31
+
32
+ def bt_and_bye()
33
+ STDERR.puts("-------------------- backtrace --------------------")
34
+ begin
35
+ raise
36
+ rescue => e
37
+ STDERR.puts(e.backtrace)
38
+ end
39
+ exit
40
+ end
41
+
42
+ def todo(message = nil)
43
+ STDERR.puts("<<< TODO #{message} :#{caller[0]} >>>")
44
+ bt_and_bye()
45
+ end
46
+ public(:todo)
47
+
48
+ def bug(message = nil)
49
+ STDERR.puts("<<< BUG #{message} :#{caller[0]} >>>")
50
+ bt_and_bye()
51
+ end
52
+ public(:bug)
53
+ end
54
+
@@ -0,0 +1,28 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "pline"
3
+ spec.version = "0.0.3"
4
+ spec.platform = Gem::Platform::RUBY
5
+ spec.summary = "Performance Profiler for Ruby1.9.3 and Ruby1.9.2"
6
+ spec.description = <<-EOS
7
+ PLine is a profiler for Ruby1.9.3 and Ruby1.9.2.
8
+ PLine profiles each line of Ruby method (method written in Ruby) you specified.
9
+ Using PLine, you can profile each line of Ruby method easily.
10
+ EOS
11
+ spec.files = Dir['{lib/**/*,ext/**/*}'] + %w[
12
+ pline.gemspec
13
+ README
14
+ ]
15
+ #spec.bindir = 'bin'
16
+ #spec.executables << 'pline'
17
+ spec.require_path = 'lib'
18
+ spec.extensions = 'ext/pline/extconf.rb'
19
+ spec.has_rdoc = false
20
+ spec.extra_rdoc_files = ['README']
21
+ #spec.test_files = Dir['test/*']
22
+ spec.author = 'Satoshi Shiba'
23
+ spec.email = 'shiba@rvm.jp'
24
+ spec.homepage = 'https://github.com/soba1104/PLine'
25
+ #spec.rubyforge_project = 'pline'
26
+ spec.required_ruby_version = '>= 1.9.2'
27
+ end
28
+
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pline
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Satoshi Shiba
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-20 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: ! 'PLine is a profiler for Ruby1.9.3 and Ruby1.9.2.
15
+
16
+ PLine profiles each line of Ruby method (method written in Ruby) you specified.
17
+
18
+ Using PLine, you can profile each line of Ruby method easily.
19
+
20
+ '
21
+ email: shiba@rvm.jp
22
+ executables: []
23
+ extensions:
24
+ - ext/pline/extconf.rb
25
+ extra_rdoc_files:
26
+ - README
27
+ files:
28
+ - lib/pline.rb
29
+ - lib/pline/util.rb
30
+ - lib/pline/minfo.rb
31
+ - lib/pline/summarize.rb
32
+ - ext/pline/extconf.rb
33
+ - ext/pline/profiler.c
34
+ - ext/pline/depend
35
+ - ext/pline/minfo.c
36
+ - ext/pline/iseq.c
37
+ - ext/pline/pline.c.rb
38
+ - ext/pline/sinfo.c
39
+ - ext/pline/ruby_source/1.9.3/method.h
40
+ - ext/pline/ruby_source/1.9.3/atomic.h
41
+ - ext/pline/ruby_source/1.9.3/vm_insnhelper.h
42
+ - ext/pline/ruby_source/1.9.3/constant.h
43
+ - ext/pline/ruby_source/1.9.3/id.h
44
+ - ext/pline/ruby_source/1.9.3/iseq.h
45
+ - ext/pline/ruby_source/1.9.3/debug.h
46
+ - ext/pline/ruby_source/1.9.3/insns.inc
47
+ - ext/pline/ruby_source/1.9.3/node.h
48
+ - ext/pline/ruby_source/1.9.3/internal.h
49
+ - ext/pline/ruby_source/1.9.3/manual_update.h
50
+ - ext/pline/ruby_source/1.9.3/insns_info.inc
51
+ - ext/pline/ruby_source/1.9.3/gc.h
52
+ - ext/pline/ruby_source/1.9.3/thread_win32.h
53
+ - ext/pline/ruby_source/1.9.3/vm_exec.h
54
+ - ext/pline/ruby_source/1.9.3/thread_pthread.h
55
+ - ext/pline/ruby_source/1.9.3/vm_opts.h
56
+ - ext/pline/ruby_source/1.9.3/vm_insnhelper.c
57
+ - ext/pline/ruby_source/1.9.3/vm_core.h
58
+ - ext/pline/ruby_source/1.9.3/eval_intern.h
59
+ - ext/pline/ruby_source/1.9.2/method.h
60
+ - ext/pline/ruby_source/1.9.2/vm_insnhelper.h
61
+ - ext/pline/ruby_source/1.9.2/id.h
62
+ - ext/pline/ruby_source/1.9.2/iseq.h
63
+ - ext/pline/ruby_source/1.9.2/debug.h
64
+ - ext/pline/ruby_source/1.9.2/insns.inc
65
+ - ext/pline/ruby_source/1.9.2/node.h
66
+ - ext/pline/ruby_source/1.9.2/manual_update.h
67
+ - ext/pline/ruby_source/1.9.2/insns_info.inc
68
+ - ext/pline/ruby_source/1.9.2/gc.h
69
+ - ext/pline/ruby_source/1.9.2/thread_win32.h
70
+ - ext/pline/ruby_source/1.9.2/vm_exec.h
71
+ - ext/pline/ruby_source/1.9.2/thread_pthread.h
72
+ - ext/pline/ruby_source/1.9.2/vm_opts.h
73
+ - ext/pline/ruby_source/1.9.2/vm_insnhelper.c
74
+ - ext/pline/ruby_source/1.9.2/vm_core.h
75
+ - ext/pline/ruby_source/1.9.2/eval_intern.h
76
+ - pline.gemspec
77
+ - README
78
+ homepage: https://github.com/soba1104/PLine
79
+ licenses: []
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: 1.9.2
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ! '>='
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 1.8.11
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Performance Profiler for Ruby1.9.3 and Ruby1.9.2
102
+ test_files: []