patch from bug 116483 to avoid doing some pr_log related work when we don't need to. r=dougt sr=brendan

This commit is contained in:
pavlov%netscape.com 2002-01-15 01:20:47 +00:00
parent 1af143b53c
commit 36aa1ffff0
2 changed files with 53 additions and 37 deletions

View File

@ -151,10 +151,12 @@ NS_IMETHODIMP TimerThread::Run()
if (theTimer) {
#ifdef DEBUG_TIMERS
PRIntervalTime now = PR_IntervalNow();
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("Timer thread woke up %dms from when it was supposed to\n",
((now > theTimer->mTimeout) ? PR_IntervalToMilliseconds(now - theTimer->mTimeout) :
-(PRInt32)PR_IntervalToMilliseconds(theTimer->mTimeout - now))));
if (PR_LOG_TEST(gTimerLog, PR_LOG_DEBUG)) {
PRIntervalTime now = PR_IntervalNow();
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("Timer thread woke up %dms from when it was supposed to\n",
((now > theTimer->mTimeout) ? PR_IntervalToMilliseconds(now - theTimer->mTimeout) :
-(PRInt32)PR_IntervalToMilliseconds(theTimer->mTimeout - now))));
}
#endif
// We are going to let the call to Fire here handle the release of the timer so that
@ -183,12 +185,14 @@ NS_IMETHODIMP TimerThread::Run()
}
#ifdef DEBUG_TIMERS
if (waitFor == PR_INTERVAL_NO_TIMEOUT)
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("waiting for PR_INTERVAL_NO_TIMEOUT\n"));
else if (waitFor == PR_INTERVAL_NO_WAIT)
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("waiting for PR_INTERVAL_NO_WAIT\n"));
else
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("waiting for %u\n", PR_IntervalToMilliseconds(waitFor)));
if (PR_LOG_TEST(gTimerLog, PR_LOG_DEBUG)) {
if (waitFor == PR_INTERVAL_NO_TIMEOUT)
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("waiting for PR_INTERVAL_NO_TIMEOUT\n"));
else if (waitFor == PR_INTERVAL_NO_WAIT)
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("waiting for PR_INTERVAL_NO_WAIT\n"));
else
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("waiting for %u\n", PR_IntervalToMilliseconds(waitFor)));
}
#endif
mWaiting = PR_TRUE;

View File

@ -119,11 +119,13 @@ nsTimerImpl::~nsTimerImpl()
void nsTimerImpl::Shutdown()
{
#ifdef DEBUG_TIMERS
double mean = 0, stddev = 0;
myNS_MeanAndStdDev(sNum, sDeltaSum, sDeltaSumSquared, &mean, &stddev);
if (PR_LOG_TEST(gTimerLog, PR_LOG_DEBUG)) {
double mean = 0, stddev = 0;
myNS_MeanAndStdDev(sNum, sDeltaSum, sDeltaSumSquared, &mean, &stddev);
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("sNum = %f, sDeltaSum = %f, sDeltaSumSquared = %f\n", sNum, sDeltaSum, sDeltaSumSquared));
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("mean: %fms, stddev: %fms\n", mean, stddev));
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("sNum = %f, sDeltaSum = %f, sDeltaSumSquared = %f\n", sNum, sDeltaSum, sDeltaSumSquared));
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("mean: %fms, stddev: %fms\n", mean, stddev));
}
#endif
if (!gThread)
@ -217,21 +219,24 @@ void nsTimerImpl::Process()
return;
#ifdef DEBUG_TIMERS
PRIntervalTime now = PR_IntervalNow();
PRIntervalTime a = now - mStart; // actual delay in intervals
PRUint32 b = PR_MillisecondsToInterval(mDelay); // expected delay in intervals
PRUint32 d = PR_IntervalToMilliseconds((a > b) ? a - b : 0); // delta in ms
sDeltaSum += d;
sDeltaSumSquared += double(d) * double(d);
sNum++;
PRIntervalTime now;
if (PR_LOG_TEST(gTimerLog, PR_LOG_DEBUG)) {
now = PR_IntervalNow();
PRIntervalTime a = now - mStart; // actual delay in intervals
PRUint32 b = PR_MillisecondsToInterval(mDelay); // expected delay in intervals
PRUint32 d = PR_IntervalToMilliseconds((a > b) ? a - b : 0); // delta in ms
sDeltaSum += d;
sDeltaSumSquared += double(d) * double(d);
sNum++;
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("[this=%p] expected delay time %dms\n", this, mDelay));
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("[this=%p] actual delay time %dms\n", this, PR_IntervalToMilliseconds(a)));
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("[this=%p] -------\n", this));
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("[this=%p] delta %dms\n", this, d));
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("[this=%p] expected delay time %dms\n", this, mDelay));
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("[this=%p] actual delay time %dms\n", this, PR_IntervalToMilliseconds(a)));
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("[this=%p] -------\n", this));
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("[this=%p] delta %dms\n", this, d));
mStart = mStart2;
mStart2 = 0;
mStart = mStart2;
mStart2 = 0;
}
#endif
mFiring = PR_TRUE;
@ -247,8 +252,10 @@ void nsTimerImpl::Process()
mFiring = PR_FALSE;
#ifdef DEBUG_TIMERS
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("[this=%p] Took %dms to fire process timer callback\n", this,
PR_IntervalToMilliseconds(PR_IntervalNow() - now)));
if (PR_LOG_TEST(gTimerLog, PR_LOG_DEBUG)) {
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("[this=%p] Took %dms to fire process timer callback\n", this,
PR_IntervalToMilliseconds(PR_IntervalNow() - now)));
}
#endif
if (mType == NS_TYPE_REPEATING_SLACK) {
@ -271,9 +278,10 @@ struct MyEventType {
void* handleMyEvent(MyEventType* event)
{
#ifdef DEBUG_TIMERS
PRIntervalTime now = PR_IntervalNow();
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("[this=%p] time between Fire() and Process(): %dms\n",
event->e.owner, PR_IntervalToMilliseconds(now - event->mInit)));
if (PR_LOG_TEST(gTimerLog, PR_LOG_DEBUG)) {
PR_LOG(gTimerLog, PR_LOG_DEBUG, ("[this=%p] time between Fire() and Process(): %dms\n",
event->e.owner, PR_IntervalToMilliseconds(PR_IntervalNow() - event->mInit)));
}
#endif
NS_STATIC_CAST(nsTimerImpl*, event->e.owner)->Process();
return NULL;
@ -305,7 +313,9 @@ void nsTimerImpl::Fire()
// in destroyMyEvent.
#ifdef DEBUG_TIMERS
event->mInit = PR_IntervalNow();
if (PR_LOG_TEST(gTimerLog, PR_LOG_DEBUG)) {
event->mInit = PR_IntervalNow();
}
#endif
// If this is a repeating precise timer, we need to calulate the time for the next timer to fire
@ -335,9 +345,11 @@ void nsTimerImpl::SetDelayInternal(PRUint32 aDelay)
mTimeout = now + PR_MillisecondsToInterval(mDelay);
#ifdef DEBUG_TIMERS
if (mStart == 0)
mStart = now;
else
mStart2 = now;
if (PR_LOG_TEST(gTimerLog, PR_LOG_DEBUG)) {
if (mStart == 0)
mStart = now;
else
mStart2 = now;
}
#endif
}