Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

top: implement SUMMARY display #306

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Bluemangoo
Copy link

@Bluemangoo Bluemangoo commented Jan 13, 2025

Resolves #207

Tasks:

  • time and uptime
  • active user count
  • cpu load average
  • task summary
  • cpu load
  • memory and swap summary
  • determine memory unit from --scale-summary-mem

I add crate systemstat for some of the values.

top - 13:03:00 up 1:33, TODO, load average: 2.01, 1.48, 1.28
Tasks: 1040 total, 6 running, 974 sleeping, 0 stopped, 0 zombie
%Cpu(s):  13.9 us, 3.3 sy, 0.0 ni, 82.4 id, 0.3 wa, 0.0 hi, 0.1 si, 0.0 st
MiB Mem :   7636.4 total,    433.3 free,   6415.1 used,    788.0 buff/cache
MiB Swap:  30518.0 total,  27218.5 free,   3299.5 used,   1221.3 avail Mem

@Krysztal112233
Copy link
Collaborator

That's great. But can I ask if it can you use text instead of image? That would be more search friendly.

@Bluemangoo
Copy link
Author

There are no way to measure load average on Windows. We can only get an instantaneous CPU load with this command:

wmic cpu get loadpercentage

The Python wheel psutil emulates what Linux does (for sure, need time to collect data):

https://github.com/giampaolo/psutil/blob/d4b37d9628e634c00a2990e488b1cc38ea6a41b5/psutil/arch/windows/wmi.c#L16-L54

I'm not sure what should we do: ignore it, or do what psutil does.

@Krysztal112233
Copy link
Collaborator

Krysztal112233 commented Jan 15, 2025

In fact, the crate we used required us does the same thing:

https://github.com/uutils/procps/blob/c2c0baba2d0db19f40c04f86df073c5614333858/src/uu/top/src/top.rs#L53C1-L57C54

    // Must refresh twice.
    // https://docs.rs/sysinfo/0.31.2/sysinfo/struct.System.html#method.refresh_cpu_usage
    picker::sysinfo().write().unwrap().refresh_all();
    sleep(Duration::from_millis(200));
    picker::sysinfo().write().unwrap().refresh_all();

You can even use a multi-threaded background to refresh this data if sysinfo cannot doesn't meet your needs.

todo:
io wait(only Linux now)
cpu load average for Windows
cpu load for Macos
active user count
determine memory unit from `--scale-summary-mem`
@sylvestre sylvestre force-pushed the feature/top-summary branch from a7c23e8 to dbac1d6 Compare January 18, 2025 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement SUMMARY display for top
2 participants