summaryrefslogtreecommitdiffstats
path: root/src/app/data_harvester/processes.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/data_harvester/processes.rs')
-rw-r--r--src/app/data_harvester/processes.rs47
1 files changed, 36 insertions, 11 deletions
diff --git a/src/app/data_harvester/processes.rs b/src/app/data_harvester/processes.rs
index 0f082e00..44f132d9 100644
--- a/src/app/data_harvester/processes.rs
+++ b/src/app/data_harvester/processes.rs
@@ -1,37 +1,41 @@
//! Data collection for processes.
//!
//! For Linux, this is handled by a custom set of functions.
-//! For Windows and macOS, this is handled by sysinfo.
+//! For Windows, macOS, FreeBSD, Android, and Linux, this is handled by sysinfo.
-cfg_if::cfg_if! {
+use cfg_if::cfg_if;
+use std::{borrow::Cow, time::Duration};
+
+use super::DataCollector;
+
+use crate::{utils::error, Pid};
+
+cfg_if! {
if #[cfg(target_os = "linux")] {
pub mod linux;
pub use self::linux::*;
} else if #[cfg(target_os = "macos")] {
pub mod macos;
- mod macos_freebsd;
- pub use self::macos::*;
+ pub(crate) use self::macos::*;
} else if #[cfg(target_os = "windows")] {
pub mod windows;
pub use self::windows::*;
} else if #[cfg(target_os = "freebsd")] {
pub mod freebsd;
- mod macos_freebsd;
- pub use self::freebsd::*;
+ pub(crate) use self::freebsd::*;
+ } else if #[cfg(target_family = "unix")] {
+ pub(crate) struct GenericProcessExt;
+ impl UnixProcessExt for GenericProcessExt {}
}
}
-cfg_if::cfg_if! {
+cfg_if! {
if #[cfg(target_family = "unix")] {
pub mod unix;
pub use self::unix::*;
}
}
-use std::{borrow::Cow, time::Duration};
-
-use crate::Pid;
-
#[derive(Debug, Clone, Default)]
pub struct ProcessHarvest {
/// The pid of the process.
@@ -96,3 +100,24 @@ impl ProcessHarvest {
self.time += rhs.time;
}
}
+
+impl DataCollector {
+ pub(crate) fn get_processes(&mut self) -> error::Result<Vec<ProcessHarvest>> {
+ cfg_if! {
+ if #[cfg(target_os = "linux")] {
+ let time_diff = self.data.collection_time
+ .duration_since(self.last_collection_time)
+ .as_secs();
+
+ linux_process_data(
+ self,
+ time_diff,
+ )
+ } else if #[cfg(any(target_os = "freebsd", target_os = "macos", target_os = "windows", target_os = "android", target_os = "ios"))] {
+ sysinfo_process_data(self)
+ } else {
+ Err(error::BottomError::GenericError("Unsupported OS".to_string()))
+ }
+ }
+ }
+}