Skip to content

Commit

Permalink
Implement jack_max_cpu_load
Browse files Browse the repository at this point in the history
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Jan 28, 2025
1 parent 43e1173 commit cb26df3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
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
1 change: 1 addition & 0 deletions common/JackEngineControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
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;
int fRollingClientUsecsIndex;
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 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;

/**@}*/

/**
Expand Down

0 comments on commit cb26df3

Please sign in to comment.