Merge lp:~jml/launchpad/remove-unused-tracers into lp:launchpad

Proposed by Jonathan Lange
Status: Merged
Approved by: Robert Collins
Approved revision: no longer in the source branch.
Merged at revision: 11170
Proposed branch: lp:~jml/launchpad/remove-unused-tracers
Merge into: lp:launchpad
Diff against target: 256 lines (+0/-245)
2 files modified
lib/canonical/database/testing/tracers.py (+0/-80)
lib/canonical/launchpad/doc/storm-tracers.txt (+0/-165)
To merge this branch: bzr merge lp:~jml/launchpad/remove-unused-tracers
Reviewer Review Type Date Requested Status
Robert Collins (community) Approve
Review via email: mp+30214@code.launchpad.net

Description of the change

This patch removes some code that is apparently unused.

To post a comment you must log in.
Revision history for this message
Robert Collins (lifeless) wrote :

I don't know what they are for, but if they aren't useful, they shouldn't be here.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed directory 'lib/canonical/database/testing'
2=== removed file 'lib/canonical/database/testing/__init__.py'
3=== removed file 'lib/canonical/database/testing/tracers.py'
4--- lib/canonical/database/testing/tracers.py 2009-06-25 05:30:52 +0000
5+++ lib/canonical/database/testing/tracers.py 1970-01-01 00:00:00 +0000
6@@ -1,80 +0,0 @@
7-# Copyright 2009 Canonical Ltd. This software is licensed under the
8-# GNU Affero General Public License version 3 (see the file LICENSE).
9-
10-"""Storm tracers for debugging."""
11-
12-__metaclass__ = type
13-__all__ = [
14- 'BaseTracer',
15- 'CountAllTracer',
16- 'StderrDebugTracer',
17- ]
18-
19-
20-import sys
21-import storm.tracer
22-
23-
24-class BaseTracer:
25- """Base class for all tracers."""
26-
27- def __init__(self):
28- # A flag indicating whether tracing should be enabled or not.
29- self.trace = False
30-
31- def install(self, only=False):
32- """Install this tracer.
33-
34- :param only: When True, remove all existing tracers before adding this
35- one.
36- :type only: boolean
37- """
38- if only:
39- storm.tracer.remove_all_tracers()
40- storm.tracer.install_tracer(self)
41-
42- def uninstall(self):
43- """Uninstall all tracers of this instance's type."""
44- storm.tracer.remove_tracer_type(type(self))
45-
46- # The trace API
47- def connection_raw_execute(self, *args):
48- pass
49-
50- def connection_raw_execute_error(self, *args):
51- pass
52-
53- def set_statement_timeout(self, *args):
54- pass
55-
56-
57-
58-class CountAllTracer(BaseTracer):
59- """A counter of all SQL statements executed by Storm."""
60-
61- def __init__(self):
62- super(CountAllTracer, self).__init__()
63- self.count = 0
64-
65- def connection_raw_execute(self, *args):
66- if self.trace:
67- self.count += 1
68-
69-
70-class StderrDebugTracer(BaseTracer):
71- """Print all executed SQL statements to a stream.
72-
73- By default, print to the real stderr (e.g. not a possibly
74- doctest-redirected stderr).
75- """
76-
77- def __init__(self, stream=None):
78- super(StderrDebugTracer, self).__init__()
79- if stream is None:
80- self.stream = sys.__stderr__
81- else:
82- self.stream = stream
83-
84- def connection_raw_execute(self, connection, cursor, statement, params):
85- if self.trace:
86- print >> self.stream, statement
87
88=== removed file 'lib/canonical/launchpad/doc/storm-tracers.txt'
89--- lib/canonical/launchpad/doc/storm-tracers.txt 2009-04-17 10:32:16 +0000
90+++ lib/canonical/launchpad/doc/storm-tracers.txt 1970-01-01 00:00:00 +0000
91@@ -1,165 +0,0 @@
92-= Storm tracers =
93-
94-The Storm ORM supports an interface for installing 'tracers', methods of which
95-get called during certain parts of the query workflow. Launchpad itself
96-provides a few helpers for tracing all SQL, or just those statements which
97-succeed or fail. Demonstrating the entire Storm tracer API is outside of the
98-scope of this document, but here you'll see Launchpad's convenience tracers.
99-
100-The base class for tracers provides the basic infrastructure for enabling,
101-disabling, installing and uninstalling tracers.
102-
103- # Save the global tracer state so that we can restore them after the test.
104- >>> import storm.tracer
105- >>> global_tracers = storm.tracer._tracers[:]
106-
107- >>> from canonical.database.testing import tracers
108-
109- >>> messages = []
110- >>> class WaveToTheCrowdTracer(tracers.BaseTracer):
111- ... def connection_raw_execute(self, *args):
112- ... if self.trace:
113- ... messages.append('hello world')
114-
115- >>> tracer = WaveToTheCrowdTracer()
116- >>> tracer.install()
117-
118-Even though the tracer is installed, it won't get called until it's enabled.
119-
120- >>> from lp.registry.interfaces.person import IPersonSet
121- >>> person_set = getUtility(IPersonSet)
122- >>> person = person_set.getByName('name12')
123- >>> len(messages)
124- 0
125-
126-Once it's enabled, the tracer does its thing.
127-
128- >>> tracer.trace = True
129- >>> person = person_set.getByName('name12')
130- >>> len(messages)
131- 1
132-
133-Of course, disabling it, stops the tracer from doing its thing.
134-
135- >>> tracer.trace = False
136- >>> person = person_set.getByName('name12')
137- >>> len(messages)
138- 1
139-
140-Let's re-enable it...
141-
142- >>> tracer.trace = True
143- >>> person = person_set.getByName('name12')
144- >>> len(messages)
145- 2
146-
147-...and then uninstall it.
148-
149- >>> tracer.uninstall()
150- >>> person = person_set.getByName('name12')
151- >>> len(messages)
152- 2
153-
154-We can install more than one tracer and both will run.
155-
156- >>> messages = []
157- >>> class WaveToTheCrowdTracer(tracers.BaseTracer):
158- ... def connection_raw_execute(self, *args):
159- ... messages.append('hello world')
160-
161- >>> tracer_one = WaveToTheCrowdTracer()
162- >>> tracer_two = WaveToTheCrowdTracer()
163- >>> tracer_one.install()
164- >>> tracer_two.install()
165-
166- >>> person = person_set.getByName('name12')
167- >>> len(messages)
168- 2
169- >>> person = person_set.getByName('name12')
170- >>> len(messages)
171- 4
172-
173-Because of the API presented by Storm, uninstalling a tracer actually
174-uninstalls all tracers of its type.
175-
176- >>> tracer_one.uninstall()
177- >>> person = person_set.getByName('name12')
178- >>> len(messages)
179- 4
180-
181-When installing a tracer, we can request that all other tracers first be
182-removed.
183-
184- >>> messages = []
185- >>> tracer_one.install()
186- >>> tracer_two.install(only=True)
187- >>> person = person_set.getByName('name12')
188- >>> len(messages)
189- 1
190- >>> person = person_set.getByName('name12')
191- >>> len(messages)
192- 2
193-
194- # Clear all the tracers for the next batch of tests.
195- >>> tracer_one.uninstall()
196-
197-
198-== A counting tracer ==
199-
200-Launchpad provides a counting tracer which can be used to count the total
201-number of SQL queries in a particular section of code.
202-
203- >>> counter = tracers.CountAllTracer()
204- >>> counter.install()
205- >>> counter.trace = True
206-
207- >>> person = person_set.getByName('name12')
208- >>> person = person_set.getByName('name12')
209- >>> counter.count
210- 2
211-
212- >>> counter.trace = False
213- >>> person = person_set.getByName('name12')
214- >>> person = person_set.getByName('name12')
215- >>> counter.count
216- 2
217-
218- # Clear all the tracers for the next batch of tests.
219- >>> counter.uninstall()
220-
221-
222-== SQL debugging ==
223-
224-Launchpad also provides a tracer that can print SQL statements to a file
225-stream. By default, it prints to the real stderr.
226-
227- >>> import sys
228- >>> from cStringIO import StringIO
229-
230- >>> old_real_stderr = sys.__stderr__
231- >>> sys.__stderr__ = out = StringIO()
232- >>> try:
233- ... debug = tracers.StderrDebugTracer()
234- ... debug.install()
235- ... debug.trace = True
236- ... person = person_set.getByName('name12')
237- ... finally:
238- ... sys.__stderr__ = old_real_stderr
239- >>> print out.getvalue()
240- SELECT Person...
241-
242- # Clear all the tracers for the next batch of tests.
243- >>> debug.uninstall()
244-
245-You can also tell it to print to a specific stream.
246-
247- >>> out = StringIO()
248- >>> debug = tracers.StderrDebugTracer(out)
249- >>> debug.install()
250- >>> debug.trace = True
251- >>> person = person_set.getByName('name12')
252- >>> print out.getvalue()
253- SELECT Person...
254-
255- # Restore the global state of the tracers before this test was run.
256- >>> storm.tracer._tracers = global_tracers