Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8e26b52

Browse files
committed
Update to reflect changes to the low-level logreader: share the info
dictionary instead of building a new one, and provide an overridable method to allow subclasses to catch ADD_INFO records that are not part of the initial block of ADD_INFO records created by the profiler itself.
1 parent f3c54d6 commit 8e26b52

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

Lib/hotshot/log.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,25 @@ def __init__(self, logfn):
3434
# (fileno, lineno) -> filename, funcname
3535
self._funcmap = {}
3636

37-
self._info = {}
3837
self._reader = _hotshot.logreader(logfn)
3938
self._nextitem = self._reader.next
39+
self._info = self._reader.info
4040
self._stack = []
4141

42+
def addinfo(self, key, value):
43+
"""This method is called for each additional ADD_INFO record.
44+
45+
This can be overridden by applications that want to receive
46+
these events. The default implementation does not need to be
47+
called by alternate implementations.
48+
49+
The initial set of ADD_INFO records do not pass through this
50+
mechanism; this is only needed to receive notification when
51+
new values are added. Subclasses can inspect self._info after
52+
calling LogReader.__init__().
53+
"""
54+
pass
55+
4256
# Iteration support:
4357
# This adds an optional (& ignored) parameter to next() so that the
4458
# same bound method can be used as the __getitem__() method -- this
@@ -60,15 +74,10 @@ def next(self, index=0):
6074
self._funcmap[(fileno, lineno)] = (filename, tdelta)
6175
continue
6276
if what == WHAT_ADD_INFO:
63-
key = tdelta.lower()
64-
try:
65-
L = self._info[key]
66-
except KeyError:
67-
L = []
68-
self._info[key] = L
69-
L.append(lineno)
70-
if key == "current-directory":
71-
self.cwd = lineno
77+
# value already loaded into self.info; call the
78+
# overridable addinfo() handler so higher-level code
79+
# can pick up the new value
80+
self.addinfo(tdelta, lineno)
7281
continue
7382
if what == WHAT_ENTER:
7483
t = self._decode_location(fileno, lineno)

0 commit comments

Comments
 (0)