Skip to content

Commit cae58ca

Browse files
authored
Add max dsp load API (#1007)
* Implement jack_max_cpu_load Signed-off-by: falkTX <[email protected]> * Bump version Signed-off-by: falkTX <[email protected]> * Fix JackEngineControl::CalcCPULoad for max value Signed-off-by: falkTX <[email protected]> * Fix function comment Signed-off-by: falkTX <[email protected]> * Add changelog entry Signed-off-by: falkTX <[email protected]> --------- Signed-off-by: falkTX <[email protected]>
1 parent 43e1173 commit cae58ca

File tree

6 files changed

+40
-4
lines changed

6 files changed

+40
-4
lines changed

ChangeLog.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
ChangeLog
22
#########
33

4+
* 1.9.23 (WIP)
5+
6+
* Add jack_max_cpu_load API call
7+
48
* 1.9.22 (2023-02-02)
59

610
* The waf autooption ``--example-tools`` has been removed.

common/JackAPI.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ extern "C"
195195
jack_time_t *next_usecs,
196196
float *period_usecs);
197197
LIB_EXPORT float jack_cpu_load(jack_client_t *client);
198+
LIB_EXPORT float jack_max_cpu_load(jack_client_t *client);
198199
LIB_EXPORT jack_native_thread_t jack_client_thread_id(jack_client_t *);
199200
LIB_EXPORT void jack_set_error_function(print_function);
200201
LIB_EXPORT void jack_set_info_function(print_function);
@@ -1457,6 +1458,20 @@ LIB_EXPORT float jack_cpu_load(jack_client_t* ext_client)
14571458
}
14581459
}
14591460

1461+
LIB_EXPORT float jack_max_cpu_load(jack_client_t* ext_client)
1462+
{
1463+
JackGlobals::CheckContext("jack_max_cpu_load");
1464+
1465+
JackClient* client = (JackClient*)ext_client;
1466+
if (client == NULL) {
1467+
jack_error("jack_max_cpu_load called with a NULL client");
1468+
return 0.0f;
1469+
} else {
1470+
JackEngineControl* control = GetEngineControl();
1471+
return (control ? control->fMaxCPULoad : 0.0f);
1472+
}
1473+
}
1474+
14601475
LIB_EXPORT jack_native_thread_t jack_client_thread_id(jack_client_t* ext_client)
14611476
{
14621477
JackGlobals::CheckContext("jack_client_thread_id");

common/JackEngineControl.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void JackEngineControl::CalcCPULoad(JackClientInterface** table,
6363

6464
// Each time we have a full set of iterations, recompute the current
6565
// usage from the latest JACK_ENGINE_ROLLING_COUNT client entries.
66-
if (fRollingClientUsecsCnt && (fRollingClientUsecsIndex == 0)) {
66+
if (fRollingClientUsecsCnt && (fRollingClientUsecsIndex == 0 || fRollingClientUsecsCnt == fRollingInterval)) {
6767
jack_time_t avg_usecs = 0;
6868
jack_time_t max_usecs = 0;
6969

@@ -74,6 +74,12 @@ void JackEngineControl::CalcCPULoad(JackClientInterface** table,
7474

7575
fMaxUsecs = JACK_MAX(fMaxUsecs, max_usecs);
7676

77+
if (fRollingClientUsecsCnt == fRollingInterval)
78+
{
79+
fMaxUsecs = max_usecs;
80+
fRollingClientUsecsCnt = 0;
81+
}
82+
7783
if (max_usecs < ((fPeriodUsecs * 95) / 100)) {
7884
// Average the values from our JACK_ENGINE_ROLLING_COUNT array
7985
fSpareUsecs = (jack_time_t)(fPeriodUsecs - (avg_usecs / JACK_ENGINE_ROLLING_COUNT));
@@ -83,6 +89,7 @@ void JackEngineControl::CalcCPULoad(JackClientInterface** table,
8389
}
8490

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

8895
fRollingClientUsecsCnt++;

common/JackEngineControl.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ struct SERVER_EXPORT JackEngineControl : public JackShmMem
7676
jack_time_t fMaxUsecs;
7777
jack_time_t fRollingClientUsecs[JACK_ENGINE_ROLLING_COUNT];
7878
unsigned int fRollingClientUsecsCnt;
79-
int fRollingClientUsecsIndex;
80-
int fRollingInterval;
79+
unsigned int fRollingClientUsecsIndex;
80+
unsigned int fRollingInterval;
8181
float fCPULoad;
82+
float fMaxCPULoad;
8283

8384
// For OSX thread
8485
UInt64 fPeriod;
@@ -124,6 +125,7 @@ struct SERVER_EXPORT JackEngineControl : public JackShmMem
124125
strncpy(fServerName, server_name, sizeof(fServerName));
125126
fServerName[sizeof(fServerName) - 1] = 0;
126127
fCPULoad = 0.f;
128+
fMaxCPULoad = 0.f;
127129
fPeriod = 0;
128130
fComputation = 0;
129131
fConstraint = 0;

common/jack/jack.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,14 @@ int jack_engine_takeover_timebase (jack_client_t *) JACK_OPTIONAL_WEAK_DEPRECATE
704704
*/
705705
float jack_cpu_load (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT;
706706

707+
/**
708+
* @return the current maximum CPU load used by JACK. This is the
709+
* total time it takes to execute a full process cycle for all clients
710+
* as a percentage of the real time available per cycle determined
711+
* by the buffer size and sample rate.
712+
*/
713+
float jack_max_cpu_load (jack_client_t *client) JACK_OPTIONAL_WEAK_EXPORT;
714+
707715
/**@}*/
708716

709717
/**

wscript

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ from waflib import Logs, Options, TaskGen
1010
from waflib.Build import BuildContext, CleanContext, InstallContext, UninstallContext
1111

1212
# see also common/JackConstants.h
13-
VERSION = '1.9.22'
13+
VERSION = '1.9.23'
1414
APPNAME = 'jack'
1515
JACK_API_VERSION = '0.1.0'
1616

0 commit comments

Comments
 (0)