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.
This commit is contained in:
parent
f3c54d6fc7
commit
8e26b52a5c
|
@ -34,11 +34,25 @@ class LogReader:
|
||||||
# (fileno, lineno) -> filename, funcname
|
# (fileno, lineno) -> filename, funcname
|
||||||
self._funcmap = {}
|
self._funcmap = {}
|
||||||
|
|
||||||
self._info = {}
|
|
||||||
self._reader = _hotshot.logreader(logfn)
|
self._reader = _hotshot.logreader(logfn)
|
||||||
self._nextitem = self._reader.next
|
self._nextitem = self._reader.next
|
||||||
|
self._info = self._reader.info
|
||||||
self._stack = []
|
self._stack = []
|
||||||
|
|
||||||
|
def addinfo(self, key, value):
|
||||||
|
"""This method is called for each additional ADD_INFO record.
|
||||||
|
|
||||||
|
This can be overridden by applications that want to receive
|
||||||
|
these events. The default implementation does not need to be
|
||||||
|
called by alternate implementations.
|
||||||
|
|
||||||
|
The initial set of ADD_INFO records do not pass through this
|
||||||
|
mechanism; this is only needed to receive notification when
|
||||||
|
new values are added. Subclasses can inspect self._info after
|
||||||
|
calling LogReader.__init__().
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
# Iteration support:
|
# Iteration support:
|
||||||
# This adds an optional (& ignored) parameter to next() so that the
|
# This adds an optional (& ignored) parameter to next() so that the
|
||||||
# same bound method can be used as the __getitem__() method -- this
|
# same bound method can be used as the __getitem__() method -- this
|
||||||
|
@ -60,15 +74,10 @@ class LogReader:
|
||||||
self._funcmap[(fileno, lineno)] = (filename, tdelta)
|
self._funcmap[(fileno, lineno)] = (filename, tdelta)
|
||||||
continue
|
continue
|
||||||
if what == WHAT_ADD_INFO:
|
if what == WHAT_ADD_INFO:
|
||||||
key = tdelta.lower()
|
# value already loaded into self.info; call the
|
||||||
try:
|
# overridable addinfo() handler so higher-level code
|
||||||
L = self._info[key]
|
# can pick up the new value
|
||||||
except KeyError:
|
self.addinfo(tdelta, lineno)
|
||||||
L = []
|
|
||||||
self._info[key] = L
|
|
||||||
L.append(lineno)
|
|
||||||
if key == "current-directory":
|
|
||||||
self.cwd = lineno
|
|
||||||
continue
|
continue
|
||||||
if what == WHAT_ENTER:
|
if what == WHAT_ENTER:
|
||||||
t = self._decode_location(fileno, lineno)
|
t = self._decode_location(fileno, lineno)
|
||||||
|
|
Loading…
Reference in New Issue