traceur 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -9
- data/lib/traceur/traceur.rb +78 -44
- data/lib/traceur/version.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -5,8 +5,8 @@ An experiment to have some fun with SVG and learn a little more
|
|
5
5
|
about Ruby.
|
6
6
|
If you want to get a visual for what is going on in your code you can
|
7
7
|
pass in a regular expression like ".+" or "downthetube".
|
8
|
-
Be specific otherwise you will end up with an SVG file so big
|
9
|
-
that no program can open it.
|
8
|
+
Be specific otherwise you will end up with an SVG file so big
|
9
|
+
that no program can open it.
|
10
10
|
|
11
11
|
Usage:
|
12
12
|
------
|
@@ -16,13 +16,10 @@ require 'rubygems'
|
|
16
16
|
require 'traceur'
|
17
17
|
require 'downthetube'
|
18
18
|
|
19
|
-
Traceur.watch_paths("downthetube", ".")
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
Traceur.stop
|
20
|
+
Traceur.watch_paths("downthetube", "/home/mike/Desktop") do
|
21
|
+
Youtube.playlists_for "stephensam"
|
22
|
+
end
|
26
23
|
```
|
27
24
|
|
28
25
|
|
@@ -30,7 +27,7 @@ LICENSE:
|
|
30
27
|
|
31
28
|
(The MIT License)
|
32
29
|
|
33
|
-
Copyright ©
|
30
|
+
Copyright © 2013 Mike Williamson
|
34
31
|
|
35
32
|
|
36
33
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
data/lib/traceur/traceur.rb
CHANGED
@@ -1,20 +1,71 @@
|
|
1
1
|
class Traceur
|
2
|
+
|
3
|
+
class NoBlockError < StandardError; end
|
2
4
|
##
|
3
5
|
# The traceur class provides methods to trace the execution
|
4
|
-
# of the Ruby interpreter and writes an SVG file into the
|
6
|
+
# of the Ruby interpreter and writes an SVG file into the
|
5
7
|
# directory you choose.
|
6
8
|
#
|
7
9
|
@start_time = nil
|
8
|
-
@svg_file = nil
|
10
|
+
@svg_file = nil
|
9
11
|
@trace_points = []
|
10
12
|
@x = 0
|
11
|
-
@y =
|
13
|
+
@y = 100
|
14
|
+
@max_y = @y
|
12
15
|
@footer = <<-EOSVG
|
13
|
-
" style="fill:none;stroke:black;stroke-width:3" />
|
14
16
|
</g>
|
15
17
|
</svg>
|
16
18
|
EOSVG
|
17
|
-
|
19
|
+
|
20
|
+
def self.watch_paths(expr, output_dir)
|
21
|
+
raise NoBlockError "You must call this method with a block" unless block_given?
|
22
|
+
block = Proc.new #this grabs the block
|
23
|
+
|
24
|
+
raise SystemCallError "Directory does not exist" unless Dir.exists?(output_dir)
|
25
|
+
|
26
|
+
labels = []
|
27
|
+
points = []
|
28
|
+
expression = Regexp.new expr
|
29
|
+
proc = Proc.new do |event, file, line, methodname, binding, classname|
|
30
|
+
if expression.match file
|
31
|
+
@start_time ||= Time.now.strftime("%s.%L").to_f
|
32
|
+
@x += 1
|
33
|
+
if event.to_s == "call"
|
34
|
+
points << " #{@x},#{@y}"
|
35
|
+
labels << ["#{classname}##{methodname}", [@x + 1, @y]]
|
36
|
+
@y += 10
|
37
|
+
@max_y = @y if @y > @max_y
|
38
|
+
points << " #{@x},#{@y}"
|
39
|
+
elsif event.to_s == "return"
|
40
|
+
points << " #{@x},#{@y}"
|
41
|
+
@y -= 10
|
42
|
+
points << " #{@x},#{@y}"
|
43
|
+
labels << ["#{classname}##{methodname}", [@x - 1, @y]]
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
Object.send(:set_trace_func, proc)
|
48
|
+
block.call
|
49
|
+
Object.send(:set_trace_func, nil)
|
50
|
+
write_svg points, labels, output_dir, {x: @x, y: @max_y}
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def self.write_svg points, labels, directory, dimensions
|
56
|
+
filename = "trace_#{Time.now.strftime('%Y%m%d%H%M%S')}.svg"
|
57
|
+
@svg_file = File.open(File.join(directory, filename), 'w+')
|
58
|
+
@svg_file.write(header(dimensions))
|
59
|
+
@svg_file.write(polygon(points))
|
60
|
+
labels.each do |details|
|
61
|
+
@svg_file.write label(details)
|
62
|
+
end
|
63
|
+
@svg_file.write(@footer)
|
64
|
+
@svg_file.close
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.header dimensions
|
68
|
+
header = <<-EOXML
|
18
69
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
19
70
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
20
71
|
|
@@ -29,7 +80,9 @@ EOSVG
|
|
29
80
|
id="svg2"
|
30
81
|
version="1.1"
|
31
82
|
inkscape:version="0.48.2 r9819"
|
32
|
-
sodipodi:docname="drawing.svg"
|
83
|
+
sodipodi:docname="drawing.svg"
|
84
|
+
width="#{dimensions[:x]}"
|
85
|
+
height="#{dimensions[:y]}">
|
33
86
|
<defs
|
34
87
|
id="defs4" />
|
35
88
|
<sodipodi:namedview
|
@@ -39,17 +92,15 @@ EOSVG
|
|
39
92
|
borderopacity="1.0"
|
40
93
|
inkscape:pageopacity="0.0"
|
41
94
|
inkscape:pageshadow="2"
|
42
|
-
inkscape:zoom="
|
43
|
-
inkscape:cx="375"
|
44
|
-
inkscape:cy="520"
|
95
|
+
inkscape:zoom="1"
|
45
96
|
inkscape:document-units="px"
|
46
97
|
inkscape:current-layer="layer1"
|
47
98
|
showgrid="false"
|
48
|
-
inkscape:window-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
99
|
+
inkscape:window-maximized="1"
|
100
|
+
fit-margin-top="0"
|
101
|
+
fit-margin-left="0"
|
102
|
+
fit-margin-right="0"
|
103
|
+
fit-margin-bottom="0" />
|
53
104
|
<metadata
|
54
105
|
id="metadata7">
|
55
106
|
<rdf:RDF>
|
@@ -64,40 +115,23 @@ EOSVG
|
|
64
115
|
</metadata>
|
65
116
|
<g inkscape:label="Layer 1"
|
66
117
|
inkscape:groupmode="layer"
|
67
|
-
id="layer1"
|
118
|
+
id="layer1">
|
68
119
|
EOXML
|
69
|
-
|
70
|
-
def self.watch_paths(expr, output_dir)
|
71
|
-
|
72
|
-
raise SystemCallError "Directory does not exist" unless Dir.exists?(output_dir)
|
73
|
-
|
74
|
-
@svg_file = File.open(File.join(output_dir, "trace.svg"), 'w+')
|
75
|
-
@svg_file.write(@header)
|
76
|
-
expression = Regexp.new expr
|
77
|
-
proc = Proc.new do |event, file, line, id, binding, classname|
|
78
|
-
if expression.match file
|
79
|
-
@start_time ||= Time.now.strftime("%s.%L").to_f
|
80
|
-
@x += 1 unless ((@start_time - Time.now.strftime("%s.%L").to_f).abs <= 0.1)
|
81
|
-
if event.to_s == "call"
|
82
|
-
@svg_file.write " #{@x},#{@y}"
|
83
|
-
@y += 10
|
84
|
-
@svg_file.write " #{@x},#{@y}"
|
85
|
-
elsif event.to_s == "return"
|
86
|
-
@svg_file.write " #{@x},#{@y}"
|
87
|
-
@y -= 10
|
88
|
-
@svg_file.write " #{@x},#{@y}"
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
Object.send(:set_trace_func, proc)
|
93
120
|
end
|
94
121
|
|
95
|
-
def self.
|
96
|
-
|
97
|
-
|
98
|
-
@svg_file.write(@footer)
|
122
|
+
def self.polygon points
|
123
|
+
"<polyline points=\"0,100#{ points.join }\" style=\"fill:none;stroke:black;stroke-width:1;opacity:0.5\" />"
|
124
|
+
end
|
99
125
|
|
100
|
-
|
126
|
+
def self.label details
|
127
|
+
text =<<-EOTXT
|
128
|
+
<text style="font-size:1px;fill:#000000;stroke:none;font-family:Sans"
|
129
|
+
transform="rotate(90 #{details[1][0]},#{details[1][1]})"
|
130
|
+
x="#{details[1][0]}"
|
131
|
+
y="#{details[1][1]}"
|
132
|
+
id="text2988">#{details[0]}</text>
|
133
|
+
EOTXT
|
101
134
|
end
|
135
|
+
|
102
136
|
end
|
103
137
|
|
data/lib/traceur/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: traceur
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-03-21 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! ' An experimental library to trace method calls using SVG '
|
15
15
|
email:
|
@@ -46,7 +46,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
46
46
|
version: '0'
|
47
47
|
requirements: []
|
48
48
|
rubyforge_project: traceur
|
49
|
-
rubygems_version: 1.8.
|
49
|
+
rubygems_version: 1.8.24
|
50
50
|
signing_key:
|
51
51
|
specification_version: 3
|
52
52
|
summary: Tracing method calls with SVG
|