diff --git a/src/cli/manager.rs b/src/cli/manager.rs index 22808f70..c2fe5cb8 100644 --- a/src/cli/manager.rs +++ b/src/cli/manager.rs @@ -90,6 +90,13 @@ pub fn default_settings() -> Option<&'static str> { return MANAGER.as_ref().clap_matches.value_of("default-settings"); } +pub fn enable_thread_counter() -> bool { + return MANAGER + .as_ref() + .clap_matches + .is_present("enable-thread-counter"); +} + // Return the command line used to start this application pub fn command_line_string() -> String { std::env::args().collect::>().join(" ") @@ -217,6 +224,12 @@ fn get_clap_matches<'a>() -> clap::ArgMatches<'a> { .long("enable-tracy") .help("Turns on the Tracy tool integration. Learn more: https://github.com/wolfpld/tracy") .takes_value(false), + ) + .arg( + clap::Arg::with_name("enable-thread-counter") + .long("enable-thread-counter") + .help("Enable a thread that prints the number of children processes.") + .takes_value(false), ); matches.get_matches() diff --git a/src/helper/mod.rs b/src/helper/mod.rs index 10532f0d..28f540e6 100644 --- a/src/helper/mod.rs +++ b/src/helper/mod.rs @@ -1,2 +1,3 @@ #[macro_use] pub mod macros; +pub mod threads; diff --git a/src/helper/threads.rs b/src/helper/threads.rs new file mode 100644 index 00000000..8ecf62ff --- /dev/null +++ b/src/helper/threads.rs @@ -0,0 +1,17 @@ +use std::thread; +use std::time::Duration; +use sysinfo::{System, SystemExt}; +use tracing::*; + +pub fn start_thread_counter_thread() { + let mut system = System::new_all(); + let pid = sysinfo::get_current_pid().expect("Failed to get current PID."); + thread::spawn(move || loop { + system.refresh_process(pid); + info!( + "Number of child processes: {}", + system.process(pid).unwrap().tasks.len() + ); + thread::sleep(Duration::from_secs(1)); + }); +} diff --git a/src/main.rs b/src/main.rs index 227cd4b3..030e1b61 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,6 +34,10 @@ async fn main() -> Result<(), std::io::Error> { settings::manager::set_mavlink_endpoint(endpoint); } + if cli::manager::enable_thread_counter() { + helper::threads::start_thread_counter_thread(); + } + stream::webrtc::signalling_server::SignallingServer::default(); if let Err(error) = stream::manager::start_default() {