tracepoint 1.0.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -1,4 +1,15 @@
1
- = HISTORY
1
+ = RELEASE HISTORY
2
+
3
+ == 1.1 / 2009-12-26
4
+
5
+ This release fixes multi-tracing and adds named traces.
6
+
7
+ Changes:
8
+
9
+ * Support for multiple traces.
10
+ * Trace procedures can be named.
11
+ * TracePoint has file name and line number.
12
+
2
13
 
3
14
  == 1.0.0 / 2009-07-10
4
15
 
@@ -6,7 +17,7 @@ Tracepoint is a spin-off of Ruby Facets. This is it's first release as
6
17
  a stand alone project. Tracepoint is a Binding with event information that
7
18
  can be used to trace execution, akin to #set_trace_func.
8
19
 
9
- * 1 major enhancement
20
+ Changes:
10
21
 
11
- * Birthday!
22
+ * Happy Birthday!
12
23
 
data/LICENSE CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  = GNU LESSER GENERAL PUBLIC LICENSE
3
2
 
4
3
  Version 3, 29 June 2007
data/MANIFEST CHANGED
@@ -1,19 +1,20 @@
1
- test
2
- RELEASE
3
- LICENSE
4
- README
5
- HISTORY
6
- meta
1
+ #!mast lib meta test [A-Z]*
2
+ lib/tracepoint.rb
3
+ meta/authors
4
+ meta/collection
5
+ meta/copyright
7
6
  meta/created
8
- meta/repository
7
+ meta/description
9
8
  meta/homepage
10
- meta/summary
11
- meta/abstract
12
- meta/package
9
+ meta/license
10
+ meta/name
13
11
  meta/released
12
+ meta/repository
13
+ meta/summary
14
+ meta/title
14
15
  meta/version
15
- meta/license
16
- meta/authors
17
- meta/project
18
- lib
19
- lib/tracepoint.rb
16
+ test/demo/trace.qed
17
+ LICENSE
18
+ README
19
+ HISTORY
20
+ Syckfile
data/README CHANGED
@@ -1,51 +1,79 @@
1
- = Tracepoint
1
+ = TracePoint
2
2
 
3
- * http://death.rubyforge.org
4
- * http://death.rubyforge.org/tracepoint
3
+ * http://rubyworks.github.com/tracepoint
4
+ * http://github.com/rubyworks/tracepoint
5
5
 
6
- == DESCRIPTION:
7
6
 
8
- A TracePoint is a Binding with the addition of event information.
9
- Among other things, it functions very well as the join-point for AOP.
10
- In practice it provides a better means than #set_trace_func.
7
+ == DESCRIPTION
11
8
 
12
- == FEATURES/PROBLEMS:
9
+ TracePoint is a Binding with the addition of event information.
10
+ In theory it would function very well as the join-point for AOP.
11
+ In practice it provides a better approach to #set_trace_func.
13
12
 
14
- * Easier and more versitle than #set_trace_func.
15
- * Set mutliple traces easily.
16
13
 
17
- == RELEASE/NOTES:
14
+ == FEATURES
18
15
 
19
- Please see RELEASE file.
16
+ * More versitle than #set_trace_func.
17
+ * Easy to set mutliple traces.
20
18
 
21
- == SYNOPSIS:
22
19
 
23
- Let's watch everything that happens:
20
+ == SYNOPSIS
24
21
 
25
- TracePoint.trace { |tp|
26
- puts "#{tp.self.class}\t#{tp.called}\t#{tp.event}\t#{tp.return?}\t#{tp.back == tp.bind}"
27
- }
22
+ Using TracePoint is simply a matter of setting the #trace procedure.
23
+ For example to watch everything that happens during a Ruby process:
24
+
25
+ TracePoint.trace do |tp|
26
+ puts "#{tp.self.class}\t#{tp.callee}\t#{tp.event}\t#{tp.return?}"
27
+ end
28
+
29
+ TracePoint.activate
28
30
 
29
31
  1 + 1
30
32
 
31
- produces
33
+ Produces:
34
+
35
+ Object line false
36
+ Fixnum + c-call false
37
+ Fixnum + c-return false
38
+
39
+ Tracing can be deactived and reactivates on the fly by calling #deactivate
40
+ and #activate.
41
+
42
+ To add an additional trace procedure, simple call the #trace method again.
43
+ Trace procedures can also be nameed by providing a name argument to the
44
+ #trace method. This allows traces to be added and removed without affecting
45
+ other traces.
46
+
47
+ TracePoint.trace(:class_trace) do |tp|
48
+ puts tp.self.class
49
+ end
50
+
51
+ TracePoint.trace(:method_trace) do |tp|
52
+ puts tp.callee
53
+ end
54
+
55
+ # ...
56
+
57
+ TracePoint.clear(:class_trace)
58
+
59
+ Calling #clear with no arguments will remove all trace procedures and
60
+ deactivate tracing.
61
+
62
+ Please see the API documentation for more information.
63
+
32
64
 
33
- Class trace return true false
34
- Object line false false
35
- Fixnum + c-call false false
36
- Fixnum + c-return false false
65
+ == INSTALLATION
37
66
 
38
- See RDocs for more information.
67
+ Follow the usual procedure for installing via RubyGems:
39
68
 
40
- == INSTALL:
69
+ $ sudo gem install tracepoint
41
70
 
42
- * sudo gem install tracepoint
43
71
 
44
- == LICENSE:
72
+ == LICENSE
45
73
 
46
74
  (LGPL v3 License)
47
75
 
48
- Copyright (c) 2005,2009 The Coding Dead <death.rubyforge.org>
76
+ Copyright (c) 2005,2009 Thomas Sawyer
49
77
 
50
78
  This program is free software: you can redistribute it and/or modify
51
79
  it under the terms of the GNU Lesser General Public License as published
data/Syckfile ADDED
@@ -0,0 +1,81 @@
1
+ ---
2
+ box:
3
+ service: Box
4
+ types : [gem, gz]
5
+ include: [bin, demo, lib, meta, test, "[A-Z]*"]
6
+ exclude: ~
7
+ master : false
8
+ active : true
9
+
10
+ dnote:
11
+ service : DNote
12
+ loadpath : ~
13
+ labels : ~
14
+ output : ~
15
+ format : ~
16
+ active : true
17
+
18
+ stats:
19
+ service : Stats
20
+ title : ~
21
+ loadpath : ~
22
+ exclude : ~
23
+ output : ~
24
+ active : true
25
+
26
+ rdoc:
27
+ service : RDoc
28
+ template : redfish
29
+ include : ~
30
+ exclude : ~
31
+ main : ~
32
+ extra : ~
33
+ active : true
34
+
35
+ ridoc:
36
+ service: RIDoc
37
+ include: ~
38
+ exclude: ~
39
+ active : true
40
+
41
+ vclog:
42
+ service : VClog
43
+ # format : html # xml, txt
44
+ layout : rel # gnu
45
+ typed : true
46
+ output : ~
47
+ active : false
48
+
49
+ email:
50
+ service : Email
51
+ file : ~
52
+ subject : ~
53
+ mailto : ruby-talk@ruby-lang.org
54
+ from : <%= ENV['EMAIL_ACCOUNT'] %>
55
+ server : <%= ENV['EMAIL_SERVER'] %>
56
+ port : <%= ENV['EMAIL_PORT'] %>
57
+ account : <%= ENV['EMAIL_ACCOUNT'] %>
58
+ domain : <%= ENV['EMAIL_DOMAIN'] %>
59
+ login : <%= ENV['EMAIL_LOGIN'] %>
60
+ secure : <%= ENV['EMAIL_SECURE'] %>
61
+ active : true
62
+
63
+
64
+ #testrb:
65
+ # service : Testrb
66
+ # tests : ~
67
+ # exclude : ~
68
+ # loadpath : ~
69
+ # requires : ~
70
+ # live : false
71
+ # active : false
72
+
73
+ #rubyforge:
74
+ # service : Rubyforge
75
+ # unixname: <%= suite %>
76
+ # groupid : ~
77
+ # package : <%= name %>
78
+ # sitemap:
79
+ # doc/rdoc: <%= name %>
80
+ # active : false
81
+
data/lib/tracepoint.rb CHANGED
@@ -1,37 +1,5 @@
1
1
  # = TracePoint
2
2
  #
3
- # A TracePoint is a Binding with the addition event information.
4
- # And it's a better way to use set_trace_func.
5
- #
6
- # A TracePoint is a Binding with the addition of event information.
7
- # Among other things, it functions very well as the join-point for
8
- # Event-based AOP.
9
- #
10
- # == Usage
11
- #
12
- # TracePoint.trace { |tp|
13
- # puts "#{tp.self.class}\t#{tp.called}\t#{tp.event}\t#{tp.return?}\t#{tp.back == tp.bind}"
14
- # }
15
- #
16
- # 1 + 1
17
- #
18
- # produces
19
- #
20
- # Class trace return true false
21
- # Object line false false
22
- # Fixnum + c-call false false
23
- # Fixnum + c-return false false
24
- #
25
- # == Notes
26
- #
27
- # You can't subclass Binding, so we delegate (which is better anyway).
28
- #
29
- # == Authors
30
- #
31
- # * Thomas Sawyer
32
- #
33
- # == Copying
34
- #
35
3
  # Copyright (c) 2005 Thomas Sawyer
36
4
  #
37
5
  # Ruby License
@@ -53,6 +21,9 @@ CodePoint = Binding
53
21
 
54
22
  # = TracePoint
55
23
  #
24
+ # A TracePoint is a Binding with the addition event information.
25
+ # And it's a better way to use set_trace_func.
26
+ #
56
27
  # A TracePoint is a Binding with the addition of event information.
57
28
  # Among other things, it functions very well as the join-point for
58
29
  # Event-based AOP.
@@ -79,24 +50,31 @@ CodePoint = Binding
79
50
  class TracePoint #< Codepoint
80
51
 
81
52
  # -- class ---------------------
53
+
82
54
  class << self
83
55
 
84
56
  @@active = false
85
57
 
86
- def active ; @@active ; end
58
+ @@index = {}
59
+ @@procs = []
87
60
 
88
- def active=(x)
89
- @@active = x ? true : false
90
- unless @@active
91
- set_trace_func nil
92
- end
61
+ # Trace execution using a TracePoint.
62
+ def trace(name=nil, &procedure)
63
+ @@index[name] = procedure if name
64
+ @@procs << procedure
93
65
  end
94
66
 
95
- # Trace execution using a TracePoint.
96
- def trace # :yield:
97
- if active
98
- bb_stack = []
99
- set_trace_func proc{ |e, f, l, m, b, k|
67
+ # Is tracing active?
68
+ def active?
69
+ @@active
70
+ end
71
+
72
+ # Activate tracing.
73
+ def activate
74
+ @@active = true
75
+ bb_stack = []
76
+ fn = lambda do |e, f, l, m, b, k|
77
+ unless k == TracePoint or (k == Kernel && m = :set_trace_func)
100
78
  #(p e, f, l, m, b, k, @@bb_stack; puts "---") if $DEBUG
101
79
  if ['call','c-call','class'].include?(e)
102
80
  bb_stack << b
@@ -104,9 +82,28 @@ class TracePoint #< Codepoint
104
82
  bb = bb_stack.pop
105
83
  end
106
84
  b = bb if ! b # this sucks!
107
- tp = TracePoint.new(e,m,b,bb)
108
- yield(tp)
109
- }
85
+ tp = TracePoint.new(e, f, l, m, b, bb)
86
+ @@procs.each{ |fn| fn.call(tp) }
87
+ end
88
+ end
89
+ set_trace_func(fn)
90
+ end
91
+
92
+ # Deactivate tracing.
93
+ def deactivate
94
+ @@active = false
95
+ set_trace_func nil
96
+ end
97
+
98
+ # Clear all trace procedures, or a specific trace by name.
99
+ def clear(name=nil)
100
+ if name
101
+ raise "Undefined trace -- #{name}" unless @@index.key?(name)
102
+ @@procs.delete(@@index.delete(name))
103
+ else
104
+ deactivate
105
+ @@index = {}
106
+ @@procs = []
110
107
  end
111
108
  end
112
109
 
@@ -114,31 +111,42 @@ class TracePoint #< Codepoint
114
111
 
115
112
  # -- instance -------------------
116
113
 
117
- attr_accessor :event, :binding, :back_binding
114
+ attr_accessor :event, :file, :line, :binding, :back_binding
118
115
 
119
116
  # Until Ruby has a built-in way to get the name of the calling method
120
117
  # that information must be passed into the TracePoint.
121
- def initialize( event, method, bind, back_binding=bind )
122
- @event = event
123
- @method = method
118
+ def initialize( event, file, line, method, bind, back_binding=bind )
119
+ @event = event
120
+ @file = file
121
+ @line = line
122
+ @method = method
124
123
  @binding = bind
125
124
  @back_binding = back_binding
126
125
  end
127
126
 
128
- # shorthand for binding
129
- def bind ; @binding ; end
127
+ # Shorthand for #binding.
128
+ def bind
129
+ @binding
130
+ end
130
131
 
131
- # shorthand for back_binding
132
- def back ; @back_binding ; end
132
+ # Shorthand for #back_binding.
133
+ def back
134
+ @back_binding
135
+ end
133
136
 
134
137
  # Delegates "self" to the binding which
135
138
  # in turn delegates the binding object.
136
- def self ; @binding.self ; end
139
+ def self
140
+ @binding.self
141
+ end
137
142
 
138
143
  # Returns the name of the event's method.
144
+ #--
139
145
  # This could delegate to the binding if Ruby had
140
146
  # an internal way to retrieve the current method name.
147
+ #++
141
148
  def callee ; @method ; end
149
+
142
150
  #def method ; @method ; end # TODO Conflict with Kernel#method?
143
151
  alias_method( :called, :callee ) # TODO deprecate
144
152
  alias_method( :method_name, :called ) # TODO deprecate
@@ -148,7 +156,7 @@ class TracePoint #< Codepoint
148
156
  # @binding.send(meth, *args, &blk)
149
157
  #end
150
158
 
151
- ### methods for working with events
159
+ # methods for working with events
152
160
 
153
161
  EVENT_MAP = {
154
162
  :all => ['call', 'c-call', 'return', 'c-return', 'line', 'class', 'end', 'raise'],
@@ -175,35 +183,9 @@ class TracePoint #< Codepoint
175
183
  end
176
184
 
177
185
  # Creates an <event>? method for each of the above event mappings.
178
- EVENT_MAP.each_pair { |m,v|
186
+ EVENT_MAP.each_pair do |m,v|
179
187
  define_method( "#{m}?" ){ v.include?(@event) }
180
- }
188
+ end
181
189
 
182
190
  end
183
191
 
184
-
185
-
186
- # _____ _
187
- # |_ _|__ ___| |_
188
- # | |/ _ \/ __| __|
189
- # | | __/\__ \ |_
190
- # |_|\___||___/\__|
191
- #
192
-
193
- # TODO
194
-
195
- =begin #test
196
-
197
- # Note: TracePoint will probably prove tricky to test, since
198
- # manipulating set_trace_func tends to wreak havoc on errors,
199
- # the call stack, and so on.
200
-
201
- TracePoint.active = true
202
-
203
- TracePoint.trace { |tp|
204
- puts "#{tp.self.class}\t#{tp.called}\t#{tp.event}\t#{tp.return?}\t#{tp.back == tp.bind}"
205
- }
206
-
207
- 1 + 1
208
-
209
- =end
data/meta/authors CHANGED
@@ -1 +1 @@
1
- Trans <transfire@gmail.com>
1
+ Thomas Sawyer <transfire@gmail.com>
data/meta/collection ADDED
@@ -0,0 +1 @@
1
+ rubyworks
data/meta/copyright ADDED
@@ -0,0 +1 @@
1
+ (c) 2005 Thomas Sawyer
File without changes
data/meta/homepage CHANGED
@@ -1 +1 @@
1
- http://death.rubyforge.org/tracepoint
1
+ http://rubyworks.github.com/tracepoint
File without changes
data/meta/repository CHANGED
@@ -1 +1 @@
1
- svn://rubyforge.org/var/svn/death/tracepoint
1
+ git://github.com/rubyworks/tracepoint.git
data/meta/title ADDED
@@ -0,0 +1 @@
1
+ TracePoint
data/meta/version CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1
@@ -0,0 +1,32 @@
1
+ = TracePoint
2
+
3
+ To demonstrate TracePoint, we will simply have it feed all
4
+ even parameters into the log for a simple arethmetic call.
5
+
6
+ First we need to load the tracepoint.rb library.
7
+
8
+ require 'tracepoint'
9
+
10
+ Now we can setup the trace procedure.
11
+
12
+ trace_log = []
13
+
14
+ TracePoint.trace do |tp|
15
+ trace_log << [tp.self.class, tp.callee, tp.event, tp.return?, tp.back == tp.bind]
16
+ end
17
+
18
+ And then we can activate the trace, call out arethmetic function,
19
+ and deactivate the trace.
20
+
21
+ TracePoint.activate
22
+ 1 + 1
23
+ TracePoint.deactivate
24
+
25
+ We should now see in the log the set of events required to
26
+ perform the addition operation.
27
+
28
+ trace_log[1].assert == [Fixnum, :'+', 'c-call', false, false]
29
+ trace_log[2].assert == [Fixnum, :'+', 'c-return', false, false]
30
+
31
+ For reference, trace_log[0] and trace_log[3] simply refer to the
32
+ QED run context.
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tracepoint
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: "1.1"
5
5
  platform: ruby
6
6
  authors:
7
- - Trans <transfire@gmail.com>
7
+ - Thomas Sawyer <transfire@gmail.com>
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-11 00:00:00 -04:00
12
+ date: 2009-12-27 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -17,7 +17,7 @@ description: |-
17
17
  A TracePoint is a Binding with the addition of event information.
18
18
  Among other things, it functions very well as the join-point for AOP.
19
19
  In practice it provides a better alternative to using #set_trace_func.
20
- email: transfire@gmail.com
20
+ email:
21
21
  executables: []
22
22
 
23
23
  extensions: []
@@ -25,36 +25,38 @@ extensions: []
25
25
  extra_rdoc_files:
26
26
  - README
27
27
  - MANIFEST
28
- - RELEASE
29
28
  - LICENSE
30
29
  - HISTORY
30
+ - Syckfile
31
31
  files:
32
- - RELEASE
33
- - LICENSE
34
- - README
35
- - HISTORY
32
+ - lib/tracepoint.rb
33
+ - meta/authors
34
+ - meta/collection
35
+ - meta/copyright
36
36
  - meta/created
37
- - meta/repository
37
+ - meta/description
38
38
  - meta/homepage
39
- - meta/summary
40
- - meta/abstract
41
- - meta/package
39
+ - meta/license
40
+ - meta/name
42
41
  - meta/released
42
+ - meta/repository
43
+ - meta/summary
44
+ - meta/title
43
45
  - meta/version
44
- - meta/license
45
- - meta/authors
46
- - meta/project
47
- - lib/tracepoint.rb
46
+ - test/demo/trace.qed
47
+ - LICENSE
48
+ - README
49
+ - HISTORY
50
+ - Syckfile
48
51
  - MANIFEST
49
52
  has_rdoc: true
50
- homepage: http://death.rubyforge.org/tracepoint
53
+ homepage: http://rubyworks.github.com/tracepoint
51
54
  licenses: []
52
55
 
53
56
  post_install_message:
54
57
  rdoc_options:
55
- - --inline-source
56
58
  - --title
57
- - tracepoint api
59
+ - TracePoint API
58
60
  - --main
59
61
  - README
60
62
  require_paths:
@@ -73,10 +75,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
75
  version:
74
76
  requirements: []
75
77
 
76
- rubyforge_project: death
77
- rubygems_version: 1.3.4
78
+ rubyforge_project: tracepoint
79
+ rubygems_version: 1.3.5
78
80
  signing_key:
79
81
  specification_version: 3
80
- summary: A TracePoint is a Binding with the addition of event information.
82
+ summary: "An alternate to #set_trace_func."
81
83
  test_files: []
82
84
 
data/RELEASE DELETED
@@ -1,12 +0,0 @@
1
- = RELEASE NOTES
2
-
3
- Tracepoint is a spin-off of Ruby Facets. This is it's first release as
4
- a stand alone project. Tracepoint is a Binding with event information that
5
- can be used to trace execution, akin to #set_trace_func.
6
-
7
- ### 1.0.0 / 2009-07-10
8
-
9
- * 1 major enhancement
10
-
11
- * Birthday!
12
-
data/meta/project DELETED
@@ -1 +0,0 @@
1
- death