tracy 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +40 -0
  3. data/Rakefile +5 -0
  4. data/bin/callsites +45 -0
  5. data/lib/tracy.rb +31 -0
  6. metadata +90 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fd60e31e3f6e8541482229b04bce7fe5965113e0
4
+ data.tar.gz: a395a7a7db2b9a6514a3c2ef2f07a7d91ce0b562
5
+ SHA512:
6
+ metadata.gz: 3c0f8b853662f0a1c9bd886bd7ab4895d2b61a072baf29868628fbd8ac1e2a9c0a150709e764b973ca2a767821dc759173b918ba4ab77e98df3cf0666a5e5b05
7
+ data.tar.gz: a716884b8a957751392dd7503e8b27f707a5d861e108041157106362b4136594532ad5fa978324756c8c14081017ddfe980d7fe736b346576af3532c2fe23e0e
@@ -0,0 +1,40 @@
1
+ # Fun with tracing
2
+
3
+ A set of experiments to investigate the possibility of using tracing
4
+ information gathered during, e.g., the running of a test suite to aid in
5
+ refactoring.
6
+
7
+ If the gem is not installed, you should run the commands listed below using
8
+ `bundle exec`.
9
+
10
+ ## Gathering caller info
11
+
12
+ Running `ruby experiment.rb` will generate `callsite-info.yml` containing a
13
+ list of callers for each method in `experiment.rb`.
14
+
15
+ ## Showing caller info
16
+
17
+ The `callsites` script simply fetches info from `callsites-info.yml`. The
18
+ following will display callers of the method defined on line 7 of
19
+ `experiment.rb`:
20
+
21
+ callsites experiment.rb:7
22
+
23
+ Alternatively, you can fetch call sites for a method by name like so:
24
+
25
+ callsites Foo#baz
26
+
27
+ ## Renaming methods
28
+
29
+ The `rename-method.rb` script performs a simple informed method renaming. It
30
+ will only rename methods on the caller locations found in `callsites-info.yml`.
31
+
32
+ Because this script currently does a simple string replace on the listed lines,
33
+ it could get confused if the method name occurs more than once on the same
34
+ line. Therefore, it aborts if this happens, rather than accidentally renaming
35
+ the wrong thing.
36
+
37
+ The following example will rename the method `Foo#baz`, but not `OtherFoo#baz`:
38
+
39
+ ruby rename-method.rb experiment.rb:17 baz foodeldoo
40
+
@@ -0,0 +1,5 @@
1
+ require 'rake/clean'
2
+ require 'bundler/gem_tasks'
3
+ require 'cucumber/rake/task'
4
+
5
+ Cucumber::Rake::Task.new
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+ require 'yaml'
3
+
4
+ Location = Struct.new(:method_name, :class_name, :line, :file) do
5
+ def match(other)
6
+ (other.method_name.nil? || other.method_name == method_name) &&
7
+ (other.class_name.nil? || other.class_name == class_name) &&
8
+ (other.line.nil? || other.line == line) &&
9
+ (other.file.nil? || other.file == file)
10
+ end
11
+
12
+ def pretty_print
13
+ if method_name
14
+ name = "#{class_name}##{method_name}"
15
+ else
16
+ name = '<main>'
17
+ end
18
+ "#{name} at #{file}:#{line}"
19
+ end
20
+ end
21
+
22
+ location = ARGV[0]
23
+ if location =~ /:/
24
+ file, line = location.split ':'
25
+ line = line.to_i
26
+ else
27
+ class_name, method_name = location.split '#'
28
+ method_name = method_name.to_sym
29
+ end
30
+
31
+ target_location = Location.new(method_name, class_name, line, file)
32
+
33
+ location_data = YAML.load(File.read('callsite-info.yml'))
34
+
35
+ selection = location_data.select do |key, callers|
36
+ loc = Location.new(*key)
37
+ loc.match(target_location)
38
+ end
39
+
40
+ selection.each do |key, callers|
41
+ puts "#{Location.new(*key).pretty_print} is called by"
42
+ callers.each do |call_site|
43
+ puts " #{Location.new(*call_site).pretty_print}"
44
+ end
45
+ end
@@ -0,0 +1,31 @@
1
+ require 'yaml'
2
+
3
+ class Tracy
4
+ def initialize
5
+ @callers = Hash.new { |hash, key| hash[key] = [] }
6
+ @trace = TracePoint.new(:call, :line) do |tp|
7
+ case tp.event
8
+ when :call
9
+ @callers[data_array(tp)].push @current_location
10
+ when :line
11
+ @current_location = data_array(tp)
12
+ end
13
+ end
14
+ end
15
+
16
+ def start
17
+ @trace.enable
18
+ end
19
+
20
+ def done
21
+ @trace.disable
22
+ IO.write('callsite-info.yml', YAML.dump(@callers))
23
+ end
24
+
25
+ private
26
+
27
+ def data_array(trace_point)
28
+ klass = trace_point.defined_class
29
+ [trace_point.method_id, klass ? klass.name : '', trace_point.lineno, trace_point.path]
30
+ end
31
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tracy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matijs van Zuijlen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aruba
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.10.2
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.10.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: cucumber
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ description:
56
+ email: matijs@matijs.net
57
+ executables:
58
+ - callsites
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - README.md
63
+ - Rakefile
64
+ - bin/callsites
65
+ - lib/tracy.rb
66
+ homepage: http://www.matijs.net
67
+ licenses: []
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.4.5.1
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Fun with tracing
90
+ test_files: []