Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
ChangeLog
#########

* 1.9.23 (WIP)

* Add jack_max_cpu_load API call

* 1.9.22 (2023-02-02)

* The waf autooption ``--example-tools`` has been removed.
Expand Down
15 changes: 15 additions & 0 deletions common/JackAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
9 changes: 8 additions & 1 deletion common/JackEngineControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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));
Expand All @@ -83,6 +89,7 @@ void JackEngineControl::CalcCPULoad(JackClientInterface** table,
}

fCPULoad = ((1.f - (float(fSpareUsecs) / float(fPeriodUsecs))) * 50.f + (fCPULoad * 0.5f));
fMaxCPULoad = (1.f - float(fMaxUsecs < fPeriodUsecs ? fPeriodUsecs - fMaxUsecs : 0) / float(fPeriodUsecs)) * 100.f;
}

fRollingClientUsecsCnt++;
Expand Down
6 changes: 4 additions & 2 deletions common/JackEngineControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
unsigned int fRollingClientUsecsIndex;
unsigned int fRollingInterval;
float fCPULoad;
float fMaxCPULoad;

// For OSX thread
UInt64 fPeriod;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions common/jack/jack.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 the
* total 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;

/**@}*/

/**
Expand Down
2 changes: 1 addition & 1 deletion wscript
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ from waflib import Logs, Options, TaskGen
from waflib.Build import BuildContext, CleanContext, InstallContext, UninstallContext

# see also common/JackConstants.h
VERSION = '1.9.22'
VERSION = '1.9.23'
APPNAME = 'jack'
JACK_API_VERSION = '0.1.0'

Expand Down
Loading