diff --git a/common/JackEngineControl.cpp b/common/JackEngineControl.cpp index 751da951..ea4697b7 100644 --- a/common/JackEngineControl.cpp +++ b/common/JackEngineControl.cpp @@ -63,7 +63,7 @@ void JackEngineControl::CalcCPULoad(JackClientInterface** table, // Each time we have a full set of iterations, recompute the current // usage from the latest JACK_ENGINE_ROLLING_COUNT client entries. - if (fRollingClientUsecsCnt && (fRollingClientUsecsIndex == 0)) { + if (fRollingClientUsecsCnt && (fRollingClientUsecsIndex == 0 || fRollingClientUsecsCnt == fRollingInterval)) { jack_time_t avg_usecs = 0; jack_time_t max_usecs = 0; @@ -74,6 +74,12 @@ void JackEngineControl::CalcCPULoad(JackClientInterface** table, fMaxUsecs = JACK_MAX(fMaxUsecs, max_usecs); + if (fRollingClientUsecsCnt == fRollingInterval) + { + fMaxUsecs = max_usecs; + fRollingClientUsecsCnt = 0; + } + if (max_usecs < ((fPeriodUsecs * 95) / 100)) { // Average the values from our JACK_ENGINE_ROLLING_COUNT array fSpareUsecs = (jack_time_t)(fPeriodUsecs - (avg_usecs / JACK_ENGINE_ROLLING_COUNT)); @@ -83,7 +89,7 @@ void JackEngineControl::CalcCPULoad(JackClientInterface** table, } fCPULoad = ((1.f - (float(fSpareUsecs) / float(fPeriodUsecs))) * 50.f + (fCPULoad * 0.5f)); - fMaxCPULoad = 1.f - (float(fMaxUsecs) / float(fPeriodUsecs)); + fMaxCPULoad = (1.f - float(fMaxUsecs < fPeriodUsecs ? fPeriodUsecs - fMaxUsecs : 0) / float(fPeriodUsecs)) * 100.f; } fRollingClientUsecsCnt++; diff --git a/common/JackEngineControl.h b/common/JackEngineControl.h index 8434cf34..ca9663bd 100644 --- a/common/JackEngineControl.h +++ b/common/JackEngineControl.h @@ -76,8 +76,8 @@ struct SERVER_EXPORT JackEngineControl : public JackShmMem jack_time_t fMaxUsecs; jack_time_t fRollingClientUsecs[JACK_ENGINE_ROLLING_COUNT]; unsigned int fRollingClientUsecsCnt; - int fRollingClientUsecsIndex; - int fRollingInterval; + unsigned int fRollingClientUsecsIndex; + unsigned int fRollingInterval; float fCPULoad; float fMaxCPULoad;