diff --git a/src/agent/Cargo.lock b/src/agent/Cargo.lock index 24ebc998de..ce29738926 100644 --- a/src/agent/Cargo.lock +++ b/src/agent/Cargo.lock @@ -374,12 +374,6 @@ dependencies = [ "serde", ] -[[package]] -name = "core-foundation-sys" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea221b5284a47e40033bf9b66f35f984ec0ea2931eb03505246cd27a963f981b" - [[package]] name = "coverage" version = "0.1.0" @@ -1800,7 +1794,6 @@ dependencies = [ "storage-queue", "strum", "strum_macros", - "sysinfo", "tempfile", "tokio", "tokio-stream", @@ -2944,21 +2937,6 @@ dependencies = [ "unicode-xid 0.2.2", ] -[[package]] -name = "sysinfo" -version = "0.21.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f88d66f3341b688163d3585037954ff276cf24a234d015b30025318a3e3449a" -dependencies = [ - "cfg-if 1.0.0", - "core-foundation-sys", - "libc", - "ntapi", - "once_cell", - "rayon", - "winapi 0.3.9", -] - [[package]] name = "tap" version = "1.0.1" diff --git a/src/agent/onefuzz-agent/src/tasks/fuzz/libfuzzer_fuzz.rs b/src/agent/onefuzz-agent/src/tasks/fuzz/libfuzzer_fuzz.rs index 66024c6f75..8d59fe90f3 100644 --- a/src/agent/onefuzz-agent/src/tasks/fuzz/libfuzzer_fuzz.rs +++ b/src/agent/onefuzz-agent/src/tasks/fuzz/libfuzzer_fuzz.rs @@ -10,10 +10,9 @@ use onefuzz::{ libfuzzer::{LibFuzzer, LibFuzzerLine}, process::ExitStatus, syncdir::{continuous_sync, SyncOperation::Pull, SyncedDir}, - system, }; use onefuzz_telemetry::{ - Event::{new_coverage, new_result, process_stats, runtime_stats}, + Event::{new_coverage, new_result, runtime_stats}, EventData, }; use serde::Deserialize; @@ -21,19 +20,11 @@ use std::{collections::HashMap, path::PathBuf, sync::Arc}; use tempfile::{tempdir_in, TempDir}; use tokio::{ io::{AsyncBufReadExt, BufReader}, - select, sync::{mpsc, Notify}, - task, time::{sleep, Duration, Instant}, }; use uuid::Uuid; -// Delay to allow for observation of CPU usage when reporting proc info. -const PROC_INFO_COLLECTION_DELAY: Duration = Duration::from_secs(1); - -// Period of reporting proc info about running processes. -const PROC_INFO_PERIOD: Duration = Duration::from_secs(30); - // Period of reporting fuzzer-generated runtime stats. const RUNTIME_STATS_PERIOD: Duration = Duration::from_secs(60); @@ -223,14 +214,7 @@ impl LibFuzzerFuzzTask { &self.config.common.setup_dir, ); let mut running = fuzzer.fuzz(crash_dir.path(), local_inputs, &inputs).await?; - let running_id = running.id(); let notify = Arc::new(Notify::new()); - let sys_info = task::spawn(report_fuzzer_sys_info( - worker_id, - run_id, - running_id.unwrap_or_default(), - notify.clone(), - )); // Splitting borrow. let stderr = running @@ -257,7 +241,6 @@ impl LibFuzzerFuzzTask { let exit_status = running.wait().await; notify.notify_one(); - let _ = sys_info.await; let exit_status: ExitStatus = exit_status?.into(); @@ -338,48 +321,6 @@ fn try_report_iter_update( Ok(()) } -async fn report_fuzzer_sys_info( - worker_id: usize, - run_id: Uuid, - fuzzer_pid: u32, - cancellation: Arc, -) -> Result<()> { - // Allow for sampling CPU usage. - let mut period = tokio::time::interval_at( - Instant::now() + PROC_INFO_COLLECTION_DELAY, - PROC_INFO_PERIOD, - ); - loop { - select! { - () = cancellation.notified() => break, - _ = period.tick() => (), - } - - // process doesn't exist - if !system::refresh_process(fuzzer_pid)? { - break; - } - - if let Some(proc_info) = system::proc_info(fuzzer_pid)? { - event!(process_stats; - EventData::WorkerId = worker_id, - EventData::RunId = run_id, - EventData::Name = proc_info.name, - EventData::Pid = proc_info.pid, - EventData::ProcessStatus = proc_info.status, - EventData::CpuUsage = proc_info.cpu_usage, - EventData::PhysicalMemory = proc_info.memory_kb, - EventData::VirtualMemory = proc_info.virtual_memory_kb - ); - } else { - // The process no longer exists. - break; - } - } - - Ok(()) -} - #[derive(Clone, Debug)] pub struct RuntimeStats { worker_id: usize, diff --git a/src/agent/onefuzz-telemetry/src/lib.rs b/src/agent/onefuzz-telemetry/src/lib.rs index 756020e2a4..95f3735ce7 100644 --- a/src/agent/onefuzz-telemetry/src/lib.rs +++ b/src/agent/onefuzz-telemetry/src/lib.rs @@ -94,7 +94,6 @@ pub enum Event { new_result, new_coverage, runtime_stats, - process_stats, new_report, new_unique_report, new_unable_to_reproduce, @@ -110,7 +109,6 @@ impl Event { Self::new_coverage => "new_coverage", Self::new_result => "new_result", Self::runtime_stats => "runtime_stats", - Self::process_stats => "process_stats", Self::new_report => "new_report", Self::new_unique_report => "new_unique_report", Self::new_unable_to_reproduce => "new_unable_to_reproduce", diff --git a/src/agent/onefuzz/Cargo.toml b/src/agent/onefuzz/Cargo.toml index 074551b928..093e009f7f 100644 --- a/src/agent/onefuzz/Cargo.toml +++ b/src/agent/onefuzz/Cargo.toml @@ -26,7 +26,6 @@ serde = "1.0" serde_json = "1.0" rand = "0.8" serde_derive = "1.0" -sysinfo = "0.21" tokio = { version = "1.15", features = ["full"] } tokio-stream = { version = "0.1", features = ["fs", "time", "tokio-util"] } tokio-util = { version = "0.6", features = ["full"] } diff --git a/src/agent/onefuzz/src/lib.rs b/src/agent/onefuzz/src/lib.rs index 91bdded9ba..42ec26ae45 100644 --- a/src/agent/onefuzz/src/lib.rs +++ b/src/agent/onefuzz/src/lib.rs @@ -4,9 +4,6 @@ #[macro_use] extern crate anyhow; -#[macro_use] -extern crate lazy_static; - #[macro_use] extern crate onefuzz_telemetry; @@ -27,7 +24,6 @@ pub mod monitor; pub mod process; pub mod sha256; pub mod syncdir; -pub mod system; pub mod utils; #[cfg(target_os = "linux")] diff --git a/src/agent/onefuzz/src/system.rs b/src/agent/onefuzz/src/system.rs deleted file mode 100644 index 516a245c92..0000000000 --- a/src/agent/onefuzz/src/system.rs +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -use std::sync::RwLock; - -use anyhow::Result; -use sysinfo::{Pid, ProcessExt, ProcessorExt, SystemExt}; - -pub fn refresh() -> Result<()> { - let mut s = SYSTEM.write().map_err(|e| format_err!("{}", e))?; - s.refresh(); - Ok(()) -} - -pub fn system_info() -> Result { - let s = SYSTEM.read().map_err(|e| format_err!("{}", e))?; - Ok(s.system_info()) -} - -pub fn proc_info(pid: u32) -> Result> { - let s = SYSTEM.read().map_err(|e| format_err!("{}", e))?; - Ok(s.proc_info(pid)) -} - -pub fn refresh_process(pid: u32) -> Result { - let mut s = SYSTEM.write().map_err(|e| format_err!("{}", e))?; - Ok(s.refresh_process(pid)) -} - -lazy_static! { - static ref SYSTEM: RwLock = { - let mut s = System::new(); - s.refresh(); - RwLock::new(s) - }; -} - -struct System { - system: sysinfo::System, -} - -// Mark our private `System` wrapper as `Send` and `Sync`, we can make a global. -// -// We may mark the type as `Sync` because we will wrap a `RwLock` around the only instance. -// We will synchronize access to the instance within the functions exported from this module. -// -// We may mark the type as `Send` because we only have one global instance, which is private, -// and we will not move it across threads. It is not actually `Send`, and must not be exported. -unsafe impl Send for System {} -unsafe impl Sync for System {} - -impl System { - pub fn new() -> Self { - let mut system = sysinfo::System::new_all(); - system.refresh_all(); - - Self { system } - } - - pub fn refresh(&mut self) { - self.system.refresh_all(); - } - - pub fn refresh_process(&mut self, pid: u32) -> bool { - self.system.refresh_process(pid as Pid) - } - - pub fn system_info(&self) -> SystemInfo { - let system = &self.system; - - let total_memory_kib = system.total_memory(); - let used_memory_kib = system.used_memory(); - let free_memory_kib = system.free_memory(); - let total_swap_kib = system.total_swap(); - let used_swap_kib = system.used_swap(); - let uptime = system.uptime(); - - let load_avg = system.load_average(); - let load_avg_1min = load_avg.one; - let load_avg_5min = load_avg.five; - let load_avg_15min = load_avg.fifteen; - - let global_cpu = system.global_processor_info(); - let cpu_usage = global_cpu.cpu_usage(); - - SystemInfo { - total_memory_kib, - used_memory_kib, - free_memory_kib, - total_swap_kib, - used_swap_kib, - uptime, - load_avg_1min, - load_avg_5min, - load_avg_15min, - cpu_usage, - } - } - - pub fn proc_info(&self, pid: u32) -> Option { - let system = &self.system; - let pi = system.process(pid as Pid)?; - - let name = pi.name().into(); - let status = format!("{}", pi.status()); - let cpu_usage = pi.cpu_usage(); - let memory_kb = pi.memory(); - let virtual_memory_kb = pi.virtual_memory(); - - Some(ProcInfo { - name, - pid, - status, - cpu_usage, - memory_kb, - virtual_memory_kb, - }) - } -} - -#[derive(Clone, Debug)] -pub struct SystemInfo { - pub total_memory_kib: u64, - pub used_memory_kib: u64, - pub free_memory_kib: u64, - pub total_swap_kib: u64, - pub used_swap_kib: u64, - pub uptime: u64, - pub load_avg_1min: f64, - pub load_avg_5min: f64, - pub load_avg_15min: f64, - pub cpu_usage: f32, -} - -#[derive(Clone, Debug)] -pub struct ProcInfo { - pub name: String, - pub pid: u32, - pub status: String, - pub cpu_usage: f32, - pub memory_kb: u64, - pub virtual_memory_kb: u64, -}