mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
move testbot deadlock detection to a function and add additional comments
This commit is contained in:
parent
f68af5cbc6
commit
25c0e91435
1 changed files with 26 additions and 25 deletions
|
@ -14,8 +14,8 @@
|
|||
mod commands;
|
||||
pub mod killaura;
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use std::{sync::Arc, thread};
|
||||
|
||||
use azalea::brigadier::command_dispatcher::CommandDispatcher;
|
||||
use azalea::ecs::prelude::*;
|
||||
|
@ -37,30 +37,7 @@ const PATHFINDER_DEBUG_PARTICLES: bool = false;
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
{
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use parking_lot::deadlock;
|
||||
|
||||
// Create a background thread which checks for deadlocks every 10s
|
||||
thread::spawn(move || loop {
|
||||
thread::sleep(Duration::from_secs(10));
|
||||
let deadlocks = deadlock::check_deadlock();
|
||||
if deadlocks.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
println!("{} deadlocks detected", deadlocks.len());
|
||||
for (i, threads) in deadlocks.iter().enumerate() {
|
||||
println!("Deadlock #{i}");
|
||||
for t in threads {
|
||||
println!("Thread Id {:#?}", t.thread_id());
|
||||
println!("{:#?}", t.backtrace());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
thread::spawn(deadlock_detection_thread);
|
||||
|
||||
let account = Account::offline(USERNAME);
|
||||
|
||||
|
@ -85,6 +62,30 @@ async fn main() {
|
|||
.unwrap();
|
||||
}
|
||||
|
||||
/// Runs a loop that checks for deadlocks every 10 seconds.
|
||||
///
|
||||
/// Note that this requires the `deadlock_detection` parking_lot feature to be
|
||||
/// enabled, which is only enabled in azalea by default when running in debug
|
||||
/// mode.
|
||||
fn deadlock_detection_thread() {
|
||||
loop {
|
||||
thread::sleep(Duration::from_secs(10));
|
||||
let deadlocks = parking_lot::deadlock::check_deadlock();
|
||||
if deadlocks.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
||||
println!("{} deadlocks detected", deadlocks.len());
|
||||
for (i, threads) in deadlocks.iter().enumerate() {
|
||||
println!("Deadlock #{i}");
|
||||
for t in threads {
|
||||
println!("Thread Id {:#?}", t.thread_id());
|
||||
println!("{:#?}", t.backtrace());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
|
||||
pub enum BotTask {
|
||||
#[default]
|
||||
|
|
Loading…
Add table
Reference in a new issue