termux-packages icon indicating copy to clipboard operation
termux-packages copied to clipboard

xfce4-taskmanager: cpu usage feature

Open knyipab opened this issue 1 year ago • 9 comments

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] image

knyipab avatar Jun 01 '24 18:06 knyipab

Sorry for any confusions caused by committing again. Few corrections done:

  • TERMUX_PKG_REVISION add 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 of sccanf from top output to get the cpu count.

I believe that I have no more changes and it is ready for review. Thanks.

image

knyipab avatar Jun 02 '24 02:06 knyipab

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.

knyipab avatar Jun 02 '24 02:06 knyipab

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

zavocc avatar Jun 07 '24 15:06 zavocc

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

knyipab avatar Jun 08 '24 03:06 knyipab

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.

truboxl avatar Jun 14 '24 08:06 truboxl

@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.

Screenshot_2024-06-19_00-15-57

but In the task list, Shotcut's CPU usage is showing 0%.

Screenshot_2024-06-19_00-15-57 (copy 1)

hansm629 avatar Jun 18 '24 15:06 hansm629

@hansm629 it is probably melt-7 using high cpu not shotcut. I suggest you sorting the processes by CPU.

knyipab avatar Jun 18 '24 17:06 knyipab

@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.

:)

hansm629 avatar Jun 19 '24 13:06 hansm629

@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 avatar Jun 27 '24 16:06 knyipab

@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?

hansm629 avatar Oct 05 '24 19:10 hansm629

Squashed. This PR should be ready to be merged.

knyipab avatar Oct 06 '24 00:10 knyipab

@knyipab Thank you. I was able to reinstall it thanks to you!

hansm629 avatar Oct 06 '24 14:10 hansm629