tracy 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/README.md +8 -0
- data/bin/callsites +4 -3
- data/features/callsites.feature +151 -0
- data/features/support/env.rb +1 -0
- data/lib/tracy.rb +2 -2
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 631bc8183b1b43ede424ac04cf23ced46988c526
|
4
|
+
data.tar.gz: 76b569411afced0e320002a6c9d928ad322f48c8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 101a39adb260ee6293fa906784300269fbb5c37cceac00970dc13eaaa43b4d54ebc0b4ff654aa4fcaf9bdc726b9546c2469dd132ac71e2d525b052000a2e0543
|
7
|
+
data.tar.gz: bb8b69174c5682fa3d759428bcfd328ad9055ee86583f8afaff10b3def11077966c112f01636842ab515d92a422949ff53c1a443b7ed955f90acbf0b1e5534be
|
data/Gemfile
ADDED
data/README.md
CHANGED
@@ -4,6 +4,10 @@ A set of experiments to investigate the possibility of using tracing
|
|
4
4
|
information gathered during, e.g., the running of a test suite to aid in
|
5
5
|
refactoring.
|
6
6
|
|
7
|
+
## Installing
|
8
|
+
|
9
|
+
gem install tracy
|
10
|
+
|
7
11
|
If the gem is not installed, you should run the commands listed below using
|
8
12
|
`bundle exec`.
|
9
13
|
|
@@ -38,3 +42,7 @@ The following example will rename the method `Foo#baz`, but not `OtherFoo#baz`:
|
|
38
42
|
|
39
43
|
ruby rename-method.rb experiment.rb:17 baz foodeldoo
|
40
44
|
|
45
|
+
## Problems
|
46
|
+
|
47
|
+
Gathering information like this is currently excruciatingly slow in real-world
|
48
|
+
projects.
|
data/bin/callsites
CHANGED
@@ -20,12 +20,13 @@ Location = Struct.new(:method_name, :class_name, :line, :file) do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
location = ARGV[0]
|
23
|
-
|
23
|
+
|
24
|
+
if location =~ /:\d+$/
|
24
25
|
file, line = location.split ':'
|
25
26
|
line = line.to_i
|
26
27
|
else
|
27
28
|
class_name, method_name = location.split '#'
|
28
|
-
method_name = method_name.to_sym
|
29
|
+
method_name = method_name.to_sym if method_name
|
29
30
|
end
|
30
31
|
|
31
32
|
target_location = Location.new(method_name, class_name, line, file)
|
@@ -39,7 +40,7 @@ end
|
|
39
40
|
|
40
41
|
selection.each do |key, callers|
|
41
42
|
puts "#{Location.new(*key).pretty_print} is called by"
|
42
|
-
callers.each do |call_site|
|
43
|
+
callers.keys.each do |call_site|
|
43
44
|
puts " #{Location.new(*call_site).pretty_print}"
|
44
45
|
end
|
45
46
|
end
|
@@ -0,0 +1,151 @@
|
|
1
|
+
Feature: Looking up callsites
|
2
|
+
|
3
|
+
Scenario: Printing callsites of a method
|
4
|
+
Given a file named "program.rb" with:
|
5
|
+
"""
|
6
|
+
require 'tracy'
|
7
|
+
|
8
|
+
tracy = Tracy.new
|
9
|
+
tracy.start
|
10
|
+
|
11
|
+
class Foo
|
12
|
+
def baz
|
13
|
+
puts 'baz'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class OtherFoo
|
18
|
+
def baz
|
19
|
+
puts 'this is not the original baz'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class Bar
|
24
|
+
def initialize foo
|
25
|
+
@foo = foo
|
26
|
+
end
|
27
|
+
|
28
|
+
def bar
|
29
|
+
@foo.baz
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def blub
|
34
|
+
puts 'Blub'
|
35
|
+
Foo.new.baz
|
36
|
+
end
|
37
|
+
|
38
|
+
foo = Foo.new
|
39
|
+
foo.baz
|
40
|
+
|
41
|
+
bar = Bar.new foo
|
42
|
+
bar.bar
|
43
|
+
foo.baz
|
44
|
+
|
45
|
+
otherfoo = OtherFoo.new
|
46
|
+
otherfoo.baz
|
47
|
+
|
48
|
+
3.times { blub }
|
49
|
+
|
50
|
+
tracy.done
|
51
|
+
"""
|
52
|
+
When I run `ruby program.rb`
|
53
|
+
And I run `callsites Foo#baz`
|
54
|
+
Then the output from "callsites Foo#baz" should contain exactly:
|
55
|
+
"""
|
56
|
+
Foo#baz at program.rb:7 is called by
|
57
|
+
<main> at program.rb:34
|
58
|
+
Bar#bar at program.rb:24
|
59
|
+
<main> at program.rb:38
|
60
|
+
Object#blub at program.rb:30
|
61
|
+
"""
|
62
|
+
|
63
|
+
Scenario: Printing callsites of a method in a nested class
|
64
|
+
Given a file named "program.rb" with:
|
65
|
+
"""
|
66
|
+
require 'tracy'
|
67
|
+
|
68
|
+
tracy = Tracy.new
|
69
|
+
tracy.start
|
70
|
+
|
71
|
+
module Foo
|
72
|
+
class Bar
|
73
|
+
def baz
|
74
|
+
# whatever
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
foo = Foo::Bar.new
|
80
|
+
foo.baz
|
81
|
+
|
82
|
+
tracy.done
|
83
|
+
"""
|
84
|
+
When I run `ruby program.rb`
|
85
|
+
And I run `callsites Foo::Bar#baz`
|
86
|
+
Then the output from "callsites Foo::Bar#baz" should contain exactly:
|
87
|
+
"""
|
88
|
+
Foo::Bar#baz at program.rb:8 is called by
|
89
|
+
<main> at program.rb:15
|
90
|
+
"""
|
91
|
+
|
92
|
+
Scenario: Printing all callsites of class
|
93
|
+
Given a file named "program.rb" with:
|
94
|
+
"""
|
95
|
+
require 'tracy'
|
96
|
+
|
97
|
+
tracy = Tracy.new
|
98
|
+
tracy.start
|
99
|
+
|
100
|
+
class Foo
|
101
|
+
def bar
|
102
|
+
# whatever
|
103
|
+
end
|
104
|
+
|
105
|
+
def baz
|
106
|
+
# whatever
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
foo = Foo.new
|
111
|
+
foo.bar
|
112
|
+
foo.baz
|
113
|
+
|
114
|
+
tracy.done
|
115
|
+
"""
|
116
|
+
When I run `ruby program.rb`
|
117
|
+
And I run `callsites Foo`
|
118
|
+
Then the output from "callsites Foo" should contain exactly:
|
119
|
+
"""
|
120
|
+
Foo#bar at program.rb:7 is called by
|
121
|
+
<main> at program.rb:17
|
122
|
+
Foo#baz at program.rb:11 is called by
|
123
|
+
<main> at program.rb:18
|
124
|
+
"""
|
125
|
+
|
126
|
+
Scenario: Printing callsites by file and line
|
127
|
+
Given a file named "program.rb" with:
|
128
|
+
"""
|
129
|
+
require 'tracy'
|
130
|
+
|
131
|
+
tracy = Tracy.new
|
132
|
+
tracy.start
|
133
|
+
|
134
|
+
class Foo
|
135
|
+
def bar
|
136
|
+
# whatever
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
foo = Foo.new
|
141
|
+
foo.bar
|
142
|
+
|
143
|
+
tracy.done
|
144
|
+
"""
|
145
|
+
When I run `ruby program.rb`
|
146
|
+
And I run `callsites program.rb:7`
|
147
|
+
Then the output from "callsites program.rb:7" should contain exactly:
|
148
|
+
"""
|
149
|
+
Foo#bar at program.rb:7 is called by
|
150
|
+
<main> at program.rb:13
|
151
|
+
"""
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'aruba/cucumber'
|
data/lib/tracy.rb
CHANGED
@@ -2,11 +2,11 @@ require 'yaml'
|
|
2
2
|
|
3
3
|
class Tracy
|
4
4
|
def initialize
|
5
|
-
@callers = Hash.new { |hash, key| hash[key] =
|
5
|
+
@callers = Hash.new { |hash, key| hash[key] = {} }
|
6
6
|
@trace = TracePoint.new(:call, :line) do |tp|
|
7
7
|
case tp.event
|
8
8
|
when :call
|
9
|
-
@callers[data_array(tp)]
|
9
|
+
@callers[data_array(tp)][@current_location] = 1
|
10
10
|
when :line
|
11
11
|
@current_location = data_array(tp)
|
12
12
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tracy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matijs van Zuijlen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -59,9 +59,12 @@ executables:
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
+
- Gemfile
|
62
63
|
- README.md
|
63
64
|
- Rakefile
|
64
65
|
- bin/callsites
|
66
|
+
- features/callsites.feature
|
67
|
+
- features/support/env.rb
|
65
68
|
- lib/tracy.rb
|
66
69
|
homepage: http://www.matijs.net
|
67
70
|
licenses: []
|