diff options
-rw-r--r-- | Modules/_hotshot.c | 12 |
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; } |