[Python-checkins] python/dist/src/Modules _hotshot.c,1.35,1.36

nnorwitz at users.sourceforge.net nnorwitz at users.sourceforge.net
Sun Jun 13 16:45:28 EDT 2004


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20562/Modules

Modified Files:
	_hotshot.c 
Log Message:
SF patch #969180, hotshot incorrectly computes elapsed time by Jason 
Beardsley.

If the seconds are different, we still need to calculate the differences
between milliseconds.

Also, on a Gentoo Linux (2.6.5) dual Athlon MP box with glibc 2.3,
time can go backwards.  This probably happens when the process switches
the CPU it's running on.  Time can also go backwards when running NTP.
If we detect a negative time delta (ie, time went backwards), return
a delta of 0.  This prevents an illegal array access elsewhere.
I think it's safest to *not* update prev_timeofday in this case, so we
return without updating.

Backport candidate.


Index: _hotshot.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/_hotshot.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -C2 -d -r1.35 -r1.36
*** _hotshot.c	20 Nov 2003 01:44:58 -0000	1.35
--- _hotshot.c	13 Jun 2004 20:45:11 -0000	1.36
***************
*** 821,830 ****
      GETTIMEOFDAY(&tv);
  
!     if (tv.tv_sec == self->prev_timeofday.tv_sec)
!         tdelta = tv.tv_usec - self->prev_timeofday.tv_usec;
!     else
!         tdelta = ((tv.tv_sec - self->prev_timeofday.tv_sec) * 1000000
!                   + tv.tv_usec);
  #endif
      self->prev_timeofday = tv;
      return tdelta;
--- 821,832 ----
      GETTIMEOFDAY(&tv);
  
!     tdelta = tv.tv_usec - self->prev_timeofday.tv_usec;
!     if (tv.tv_sec != self->prev_timeofday.tv_sec)
!         tdelta += (tv.tv_sec - self->prev_timeofday.tv_sec) * 1000000;
  #endif
+     /* time can go backwards on some multiprocessor systems or by NTP */
+     if (tdelta < 0)
+         return 0;
+ 
      self->prev_timeofday = tv;
      return tdelta;




More information about the Python-checkins mailing list