Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add thread counter function #317

Merged
merged 2 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/cli/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<String>>().join(" ")
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions src/helper/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#[macro_use]
pub mod macros;
pub mod threads;
17 changes: 17 additions & 0 deletions src/helper/threads.rs
Original file line number Diff line number Diff line change
@@ -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));
});
}
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading