2

Question Is there an API for Windows and/or Linux that will let me find out which processes are draining battery?

A few notes:

  • It doesn't have to be precise, I'd be ok with only three levels (low energy cost/fair energy cost/high energy cost) if that's all I can get.
  • I already have CPU load information, that's not what I am looking for, as experience shows that processes with very low CPU use can nevertheless drain battery by having high I/O, high swapping or frequent wakeups. This is why I'd like to piggyback on whatever the OS is already using: OS developers are much more likely than me to have actually tested this.
  • I found a partial solution for macOS. See answers.
  • MSDN doesn't seem to indicate any energy-related API.
  • I cannot request admin/root rights for running my task manager, so I cannot simply parse the syslogs looking for power usage alerts.
Yoric
  • 3,348
  • 3
  • 19
  • 26
  • As OSs they are in charge of scheduling processes and hence already have the information (at least of execution time and ration of total load). They do not need to get the info from somewhere. It would be your need to ask them. Please clarify your question by contrasting it in detail to this. – Yunnosch Aug 27 '20 at 07:35
  • The kernel has the information. The UI needs to get it from somewhere. – Yoric Aug 27 '20 at 07:49
  • 1
    As your notes describe, it's a convoluted metric to evaluate power usage. This post might be related https://superuser.com/a/524810/648722 . Since there is not much information out there, my guess is there is no public api for your request at the moment. – Louis Go Aug 27 '20 at 08:03
  • @LouisGo, yes, because it's so convoluted, I'd prefer piggybacking on whatever the OS is already doing. – Yoric Aug 27 '20 at 08:19
  • Apparently, the question is off-topic for SuperUser: https://superuser.com/questions/1580993/how-do-oses-decide-what-process-take-too-much-energy?noredirect=1#comment2408390_1580993 – Yoric Aug 27 '20 at 10:25

1 Answers1

1

I've found a great reference for how macOS does it.

https://blog.mozilla.org/nnethercote/2015/08/26/what-does-the-os-x-activity-monitors-energy-impact-actually-measure/

That should be fairly easy to follow.

Yoric
  • 3,348
  • 3
  • 19
  • 26
  • 1
    Linux has [powertop](https://wiki.archlinux.org/index.php/Powertop). – Louis Go Aug 28 '20 at 01:44
  • Yeah, I've tried it and it's very, very powerful. Unfortunately, it needs to run as root, but it's possible that I could be able to extract stuff that doesn't require root privileges from it. – Yoric Aug 28 '20 at 04:39