xfce4-taskmanager: cpu usage feature
A ~very casual~ patch relying on Android top (and sysconf(_SC_NPROCESSORS_ONLN)) to bring CPU usage feature to xfce4-taskmanager, demonstrated in the image below.
~It is at least a better-than-none and no-harm patch, even it may not take Android version into careful consideration.~ -> Rewrote and there should be no harm for incompatible devices.
[Edit: Outdated image, see comments below]
Sorry for any confusions caused by committing again. Few corrections done:
TERMUX_PKG_REVISIONadd 1- The %CPU in the process list should add up to 100% (unlike in
top) meaning that it need to be divided by the cpu count. sysconf(_SC_NPROCESSORS_ONLN)instead ofsccanffromtopoutput to get the cpu count.
I believe that I have no more changes and it is ready for review. Thanks.
Indeed, htop could be patched in a similar way, given that sscanf the output of top -b -q -o PID,%CPU -s 2 -n 1 should be reliable.
Htop relied on /proc/stat file I believe for CPU usage which is patched to use the fake one if it can't read the actual one, crucial for it to launch, not sure how it can be substituted this way. Though other ideas are welcome
Note that xfce4-taskmanager also use /proc/stat and my patch is not on proc/stat file but directly feed information from top -b -q -o PID,%CPU -s 2 -n 1 to functions that generate CPU statistics (get_task_list and get_cpu_count).
For htop, that would probably be LinuxMachine_scanCPUTime. FYR: https://github.com/htop-dev/htop/blob/58efa4e131422721e6f916db5482ac0823d3a275/linux/LinuxMachine.c#L402-L509
The top in termux-tools is a wrapper of /system/bin/top https://github.com/termux/termux-tools/blob/3d614013a65475b0b1ef522d905fc58205ce11a6/scripts/Makefile.am#L26-L27
And the supplied /system/bin/top maybe a different variant in different Android versions (most notably between 7.0 toolbox and 8.0 toybox) https://android.googlesource.com/platform/system/core/+/refs/heads/main/shell_and_utilities/
So if that can be confirmed working I can help merge this.
@knyipab
When I try to render 4K@30fps video with the Shotcut build by sir, the CPU percentage is displayed well in the xfce4-taskmanager graph.
but In the task list, Shotcut's CPU usage is showing 0%.
@hansm629 it is probably melt-7 using high cpu not shotcut. I suggest you sorting the processes by CPU.
@knyipab This is an inquiry unrelated to the pull request, but...
Do you have any plans to build xfce4-cpugraph-plugin as well?
xfce4-cpugraph-plugin can monitor each CPU core,
I think it will be very useful.
:)
@truboxl
I rewrote to use data from get_task_list() (ultimately using /proc/[pid]/stat) instead of top. It should be more efficient, accurate in timing cpu time and require less resources. Probably also work on older Android devices, but still, I incorporated comment from @licy183 on another PR to trigger the new approach only when API level >= 28.
FYI, the jiffies_total calculation in get_cpu_usage_android_28() is basically from procps: https://gitlab.com/procps-ng/procps/-/blob/f57c132d6fd885e7fb6f6b1d43d5cdf102c329bb/library/pids.c#L1519-1519
Also, I kept the top approach in commit just in case /proc/[pid]/stat is no longer available and we need it in the future.
@knyipab
Hello sir,
I recently reset my device and reinstalled Termux.
However, when I tried to download xfce4-taskmanager, it appears to be expired and no longer available for download.
Do you know when the related PR might be merged? Or could you rebuild it so that it becomes available for download again?
Squashed. This PR should be ready to be merged.
@knyipab Thank you. I was able to reinstall it thanks to you!