Browse Source

Add max dsp load API (#1007)

* Implement jack_max_cpu_load

Signed-off-by: falkTX <falktx@falktx.com>

* Bump version

Signed-off-by: falkTX <falktx@falktx.com>

* Fix JackEngineControl::CalcCPULoad for max value

Signed-off-by: falkTX <falktx@falktx.com>

* Fix function comment

Signed-off-by: falkTX <falktx@falktx.com>

* Add changelog entry

Signed-off-by: falkTX <falktx@falktx.com>

---------

Signed-off-by: falkTX <falktx@falktx.com>
develop
Filipe Coelho GitHub 2 months ago
parent
commit
cae58cafee
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
6 changed files with 40 additions and 4 deletions
  1. +4
    -0
      ChangeLog.rst
  2. +15
    -0
      common/JackAPI.cpp
  3. +8
    -1
      common/JackEngineControl.cpp
  4. +4
    -2
      common/JackEngineControl.h
  5. +8
    -0
      common/jack/jack.h
  6. +1
    -1
      wscript

+ 4
- 0
ChangeLog.rst View File

@@ -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.


+ 15
- 0
common/JackAPI.cpp View File

@@ -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");


+ 8
- 1
common/JackEngineControl.cpp View File

@@ -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,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++;


+ 4
- 2
common/JackEngineControl.h View File

@@ -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;
@@ -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;


+ 8
- 0
common/jack/jack.h View File

@@ -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;

/**@}*/

/**


+ 1
- 1
wscript View File

@@ -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'



Loading…
Cancel
Save