diff --git a/common/JackAPI.cpp b/common/JackAPI.cpp index c817c931..4abc35b7 100644 --- a/common/JackAPI.cpp +++ b/common/JackAPI.cpp @@ -195,6 +195,7 @@ extern "C" jack_time_t *next_usecs, float *period_usecs); LIB_EXPORT float jack_cpu_load(jack_client_t *client); + LIB_EXPORT float jack_max_cpu_load(jack_client_t *client); LIB_EXPORT jack_native_thread_t jack_client_thread_id(jack_client_t *); LIB_EXPORT void jack_set_error_function(print_function); LIB_EXPORT void jack_set_info_function(print_function); @@ -1457,6 +1458,20 @@ LIB_EXPORT float jack_cpu_load(jack_client_t* ext_client) } } +LIB_EXPORT float jack_max_cpu_load(jack_client_t* ext_client) +{ + JackGlobals::CheckContext("jack_max_cpu_load"); + + JackClient* client = (JackClient*)ext_client; + if (client == NULL) { + jack_error("jack_max_cpu_load called with a NULL client"); + return 0.0f; + } else { + JackEngineControl* control = GetEngineControl(); + return (control ? control->fMaxCPULoad : 0.0f); + } +} + LIB_EXPORT jack_native_thread_t jack_client_thread_id(jack_client_t* ext_client) { JackGlobals::CheckContext("jack_client_thread_id"); diff --git a/common/JackEngineControl.cpp b/common/JackEngineControl.cpp index 56b3bdea..751da951 100644 --- a/common/JackEngineControl.cpp +++ b/common/JackEngineControl.cpp @@ -83,6 +83,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)); } fRollingClientUsecsCnt++; diff --git a/common/JackEngineControl.h b/common/JackEngineControl.h index 90d7ca48..8434cf34 100644 --- a/common/JackEngineControl.h +++ b/common/JackEngineControl.h @@ -76,9 +76,10 @@ 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; + int fRollingClientUsecsIndex; + int fRollingInterval; float fCPULoad; + float fMaxCPULoad; // For OSX thread UInt64 fPeriod; @@ -124,6 +125,7 @@ struct SERVER_EXPORT JackEngineControl : public JackShmMem strncpy(fServerName, server_name, sizeof(fServerName)); fServerName[sizeof(fServerName) - 1] = 0; fCPULoad = 0.f; + fMaxCPULoad = 0.f; fPeriod = 0; fComputation = 0; fConstraint = 0; diff --git a/common/jack/jack.h b/common/jack/jack.h index 23850bbc..722f7f27 100644 --- a/common/jack/jack.h +++ b/common/jack/jack.h @@ -704,6 +704,14 @@ int jack_engine_takeover_timebase (jack_client_t *) JACK_OPTIONAL_WEAK_DEPRECATE */ float jack_cpu_load (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT; +/** + * @return the current maximum CPU load used by JACK. This is a running + * average of the time it takes to execute a full process cycle for + * all clients as a percentage of the real time available per cycle + * determined by the buffer size and sample rate. + */ +float jack_max_cpu_load (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT; + /**@}*/ /**