diff --git a/Cargo.lock b/Cargo.lock index 84da1ff..0e11ba6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2187,7 +2187,7 @@ dependencies = [ [[package]] name = "socktop_agent" -version = "1.40.65" +version = "1.40.66" dependencies = [ "anyhow", "assert_cmd", diff --git a/scripts/check-windows.sh b/scripts/check-windows.sh new file mode 100644 index 0000000..719933a --- /dev/null +++ b/scripts/check-windows.sh @@ -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." + diff --git a/socktop_agent/Cargo.toml b/socktop_agent/Cargo.toml index 3589a21..8bda2b1 100644 --- a/socktop_agent/Cargo.toml +++ b/socktop_agent/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "socktop_agent" -version = "1.40.65" +version = "1.40.66" authors = ["Jason Witty "] description = "Remote system monitor over WebSocket, TUI like top" edition = "2021" diff --git a/socktop_agent/src/metrics.rs b/socktop_agent/src/metrics.rs index a758f50..9718236 100644 --- a/socktop_agent/src/metrics.rs +++ b/socktop_agent/src/metrics.rs @@ -454,14 +454,15 @@ pub async fn collect_processes_all(state: &AppState) -> ProcessesPayload { new_name }; - // Normalize CPU by core count (like Linux implementation) - let raw = p.cpu_usage(); - let normalized_cpu = (raw / cpu_count).clamp(0.0, 100.0); + // Convert to percentage of total CPU capacity + // e.g., 100% on 2 cores of 8 core system = 25% total CPU + 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 { pid, name, - cpu_usage: normalized_cpu, + cpu_usage: total_cpu, mem_bytes: p.memory(), }); }