clamp then divide by cores for more accurate statistics
This commit is contained in:
parent
61fe1cc38e
commit
7592709a43
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -2187,7 +2187,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "socktop_agent"
|
name = "socktop_agent"
|
||||||
version = "1.40.65"
|
version = "1.40.66"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"assert_cmd",
|
"assert_cmd",
|
||||||
|
|||||||
47
scripts/check-windows.sh
Normal file
47
scripts/check-windows.sh
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
# Cross-check Windows build from Linux using the GNU (MinGW) toolchain.
|
||||||
|
# - Ensures target `x86_64-pc-windows-gnu` is installed
|
||||||
|
# - Verifies MinGW cross-compiler is available (x86_64-w64-mingw32-gcc)
|
||||||
|
# - Runs cargo clippy with warnings-as-errors for the Windows target
|
||||||
|
# - Builds release binaries for the Windows target
|
||||||
|
|
||||||
|
echo "[socktop] Windows cross-check: clippy + build (GNU target)"
|
||||||
|
|
||||||
|
have() { command -v "$1" >/dev/null 2>&1; }
|
||||||
|
|
||||||
|
if ! have rustup; then
|
||||||
|
echo "error: rustup not found. Install Rust via rustup first (see README)." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! rustup target list --installed | grep -q '^x86_64-pc-windows-gnu$'; then
|
||||||
|
echo "+ rustup target add x86_64-pc-windows-gnu"
|
||||||
|
rustup target add x86_64-pc-windows-gnu
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! have x86_64-w64-mingw32-gcc; then
|
||||||
|
echo "error: Missing MinGW cross-compiler (x86_64-w64-mingw32-gcc)." >&2
|
||||||
|
if have pacman; then
|
||||||
|
echo "Arch Linux: sudo pacman -S --needed mingw-w64-gcc" >&2
|
||||||
|
elif have apt-get; then
|
||||||
|
echo "Debian/Ubuntu: sudo apt-get install -y mingw-w64" >&2
|
||||||
|
elif have dnf; then
|
||||||
|
echo "Fedora: sudo dnf install -y mingw64-gcc" >&2
|
||||||
|
else
|
||||||
|
echo "Install the mingw-w64 toolchain for your distro, then re-run." >&2
|
||||||
|
fi
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
CARGO_FLAGS=(--workspace --all-targets --all-features --target x86_64-pc-windows-gnu)
|
||||||
|
|
||||||
|
echo "+ cargo clippy ${CARGO_FLAGS[*]} -- -D warnings"
|
||||||
|
cargo clippy "${CARGO_FLAGS[@]}" -- -D warnings
|
||||||
|
|
||||||
|
echo "+ cargo build --release ${CARGO_FLAGS[*]}"
|
||||||
|
cargo build --release "${CARGO_FLAGS[@]}"
|
||||||
|
|
||||||
|
echo "✅ Windows clippy and build completed successfully."
|
||||||
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "socktop_agent"
|
name = "socktop_agent"
|
||||||
version = "1.40.65"
|
version = "1.40.66"
|
||||||
authors = ["Jason Witty <jasonpwitty+socktop@proton.me>"]
|
authors = ["Jason Witty <jasonpwitty+socktop@proton.me>"]
|
||||||
description = "Remote system monitor over WebSocket, TUI like top"
|
description = "Remote system monitor over WebSocket, TUI like top"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|||||||
@ -454,14 +454,15 @@ pub async fn collect_processes_all(state: &AppState) -> ProcessesPayload {
|
|||||||
new_name
|
new_name
|
||||||
};
|
};
|
||||||
|
|
||||||
// Normalize CPU by core count (like Linux implementation)
|
// Convert to percentage of total CPU capacity
|
||||||
let raw = p.cpu_usage();
|
// e.g., 100% on 2 cores of 8 core system = 25% total CPU
|
||||||
let normalized_cpu = (raw / cpu_count).clamp(0.0, 100.0);
|
let raw = p.cpu_usage(); // This is per-core percentage
|
||||||
|
let total_cpu = raw.clamp(0.0, 100.0) / cpu_count;
|
||||||
|
|
||||||
proc_cache.reusable_vec.push(ProcessInfo {
|
proc_cache.reusable_vec.push(ProcessInfo {
|
||||||
pid,
|
pid,
|
||||||
name,
|
name,
|
||||||
cpu_usage: normalized_cpu,
|
cpu_usage: total_cpu,
|
||||||
mem_bytes: p.memory(),
|
mem_bytes: p.memory(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user