Request: getBatteryRemaining and getCpuUsage

More is better! I would love to see the following routines added to Juce (for all platforms of course)

int getBatteryPercentRemaining();

int getPercentageCpuUsage();

More is certainly better!

I’d never thought about battery life, I guess that’d be quite straightforward to do.

The cpu percentage is something I have considered, but when you start thinking about it, it starts to sound like it could be a bit of a can of worms - e.g. when there are multiple cpus, how exactly do you work out the total, and what if you want to get the percentage for particular processes. threads, etc… Feels like it could end up being a feature-creep nightmare. It’s also quite fiddly to get these numbers on some OSes.

Well on Windows the function is “GetSystemPowerStatus()”.

As for the CPU, since Juce is heavily used for plugins, audio hosting apps, digital audio workstations, etc… really the use-case is just so the application can show the user if they are close to being maxed-out on CPU. In which case, bad things might happen like audio dropouts, buffer underruns or overruns, and what not.

So I think just a general CPU function that tells you to what extent you are using up the CPU resources available, would be great. It doesn’t have to be just for the current process in fact it should be for the system as a whole, including everything else that is running (since they are using up resources).

Now that I think of it, another choice for measuring CPU usage would be to compare the ratio of time spent inside the interrupt-driven audio hardware callback, to the total time. In other words, how much headroom does the audio processing callback have available before it can’t keep up.

You can already get that value with AudioDeviceManager::getCpuUsage()

Wow…now that is amazing!

getCpuUsage() is awesome.

Any word on battery? This could be useful on iOs and Android

It’s not something I’ve ever investigated. Am doing a lot more mobile work at the moment though, so may add it.