[Python-checkins] CVS: python/dist/src/Lib/hotshot log.py,1.3,1.4

Fred L. Drake fdrake@users.sourceforge.net
Mon, 29 Oct 2001 12:57:25 -0800


Update of /cvsroot/python/python/dist/src/Lib/hotshot
In directory usw-pr-cvs1:/tmp/cvs-serv16081/Lib/hotshot

Modified Files:
	log.py 
Log Message:
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.


Index: log.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/hotshot/log.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** log.py	2001/10/15 22:05:32	1.3
--- log.py	2001/10/29 20:57:23	1.4
***************
*** 35,43 ****
          self._funcmap = {}
  
-         self._info = {}
          self._reader = _hotshot.logreader(logfn)
          self._nextitem = self._reader.next
          self._stack = []
  
      # Iteration support:
      # This adds an optional (& ignored) parameter to next() so that the
--- 35,57 ----
          self._funcmap = {}
  
          self._reader = _hotshot.logreader(logfn)
          self._nextitem = self._reader.next
+         self._info = self._reader.info
          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:
      # This adds an optional (& ignored) parameter to next() so that the
***************
*** 61,73 ****
                  continue
              if what == WHAT_ADD_INFO:
!                 key = tdelta.lower()
!                 try:
!                     L = self._info[key]
!                 except KeyError:
!                     L = []
!                     self._info[key] = L
!                 L.append(lineno)
!                 if key == "current-directory":
!                     self.cwd = lineno
                  continue
              if what == WHAT_ENTER:
--- 75,82 ----
                  continue
              if what == WHAT_ADD_INFO:
!                 # value already loaded into self.info; call the
!                 # overridable addinfo() handler so higher-level code
!                 # can pick up the new value
!                 self.addinfo(tdelta, lineno)
                  continue
              if what == WHAT_ENTER: