From 9fe4543aa6724b7702ccd5d93e4a4c196593b9d3 Mon Sep 17 00:00:00 2001 From: m1ngsama Date: Tue, 16 Dec 2025 17:49:15 +0800 Subject: [PATCH] optimize: improve build profile, CI, and remove redundant cpu sleeps - Add release profile with LTO and stripping for smaller binaries - Add Rust checks (fmt, clippy, test) to CI - Remove redundant 200ms sleep in cpu monitoring for better continuous performance - Fix dead code warnings in various modules --- .github/workflows/ci.yml | 17 +++++++++++++++++ Cargo.toml | 6 ++++++ src/alert.rs | 2 ++ src/exporter.rs | 1 + src/logger.rs | 1 + src/monitor.rs | 6 ++++-- 6 files changed, 31 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6caf353..34ab220 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,3 +59,20 @@ jobs: # Exit-zero treats all errors as warnings flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics continue-on-error: true + + rust-checks: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + + - name: Check formatting + run: cargo fmt --all -- --check + + - name: Run clippy + run: cargo clippy -- -D warnings + + - name: Run tests + run: cargo test diff --git a/Cargo.toml b/Cargo.toml index 13b0fe7..6a3035a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,9 @@ log = "0.4" env_logger = "0.11" csv = "1.3" anyhow = "1.0" + +[profile.release] +lto = true +codegen-units = 1 +strip = true + diff --git a/src/alert.rs b/src/alert.rs index f62f6ba..fbcaabe 100644 --- a/src/alert.rs +++ b/src/alert.rs @@ -8,6 +8,7 @@ pub struct AlertSystem { } #[derive(Debug, Clone)] +#[allow(dead_code)] pub struct Alert { pub alert_type: String, pub message: String, @@ -62,6 +63,7 @@ impl AlertSystem { println!("\n⚠️ ALERT: {}", message); } + #[allow(dead_code)] pub fn get_alert_history(&self) -> &[Alert] { &self.alert_history } diff --git a/src/exporter.rs b/src/exporter.rs index bc67e41..7cf9cd3 100644 --- a/src/exporter.rs +++ b/src/exporter.rs @@ -1,3 +1,4 @@ +#![allow(dead_code)] use serde::Serialize; use std::fs; use std::path::PathBuf; diff --git a/src/logger.rs b/src/logger.rs index 5bdf7d4..feeb45b 100644 --- a/src/logger.rs +++ b/src/logger.rs @@ -44,6 +44,7 @@ impl TrackerLogger { self.write_log("WARNING", &alert_message); } + #[allow(dead_code)] pub fn log_error(&self, error_message: &str) { let error_msg = format!("ERROR: {}", error_message); self.write_log("ERROR", &error_msg); diff --git a/src/monitor.rs b/src/monitor.rs index 647da6c..7a43d62 100644 --- a/src/monitor.rs +++ b/src/monitor.rs @@ -32,8 +32,6 @@ impl SystemMonitor { } pub fn get_cpu_usage(&mut self) -> f32 { - self.sys.refresh_cpu_all(); - std::thread::sleep(std::time::Duration::from_millis(200)); self.sys.refresh_cpu_all(); self.sys.global_cpu_usage() } @@ -163,6 +161,7 @@ impl SystemMonitor { pub struct MemoryInfo { pub total: u64, pub used: u64, + #[allow(dead_code)] pub available: u64, pub percent: f32, } @@ -171,6 +170,7 @@ pub struct MemoryInfo { pub struct DiskInfo { pub total: u64, pub used: u64, + #[allow(dead_code)] pub free: u64, pub percent: f32, } @@ -179,6 +179,8 @@ pub struct DiskInfo { pub struct NetworkStats { pub bytes_sent: u64, pub bytes_recv: u64, + #[allow(dead_code)] pub packets_sent: u64, + #[allow(dead_code)] pub packets_recv: u64, }