summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2004-06-13 20:45:11 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2004-06-13 20:45:11 (GMT)
commit7a135166f65232a39d1a607465bbd26ac993069a (patch)
treec69f33435bb6c86b420bf922c3aa5b8f2df7c79c /Modules
parent0f5aed4e41d1df04ffd004747fc0da4ace16350f (diff)
downloadcpython-7a135166f65232a39d1a607465bbd26ac993069a.zip
cpython-7a135166f65232a39d1a607465bbd26ac993069a.tar.gz
cpython-7a135166f65232a39d1a607465bbd26ac993069a.tar.bz2
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.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_hotshot.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/Modules/_hotshot.c b/Modules/_hotshot.c
index a04494f..0683be6 100644
--- a/Modules/_hotshot.c
+++ b/Modules/_hotshot.c
@@ -820,12 +820,14 @@ get_tdelta(ProfilerObject *self)
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);
+ 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;
}