These functions allow to monitor CPU usage of the whole audio thread or of arbitrary sections of the program while it is running.
Manually calling Bela_cpuTic() and Bela_cpuToc() around specific sections of the code, the CPU performance of these sections can be evaluated. Calling these functions incurs an overhead.
When setting the internal CPU monitoring via Bela_cpuMonitoringInit(), the user can compute the CPU time of the entire audio thread. The core code internally calls Bela_cpuTic() and Bela_cpuToc() and the user can get the CPU usage details vai Bela_cpuMonitoringGet();
- Note
- These measurements are based on reading a monotonic clock and therefore they include not only actual CPU cycles consumed by the current thread but also any time the thread spends idle, either because it's blocked or because a higher priority thread is running.
int Bela_cpuMonitoringInit |
( |
int |
count | ) |
|
Set internal CPU monitoring for the audio thread.
- Parameters
-
count | Number of samples (tic/toc pairs) in a acquisition cycle. Use 0 to disable. |
- Returns
- 0 on success, an error code otherwise.
Get stats about internal CPU monitoring.
- Returns
- a pointer to a BelaCpuData structure which contains data about the CPU usage of the audio thread.
Start measuring CPU time. When data->currentCount
reaches data->count
, a acquisition cycle is completed. data->percentage
gives the average CPU busy time during the latest completed acquisition cycle.
- Parameters
-
data | The count field is an input and needs to be populated before calling. Other fields are used as I/O by the function. |
Stop measuring CPU time.
- Parameters
-
data | The count field is an input and needs to be populated before calling. Other fields are used as I/O by the function. |