diff options
| author | mat <git@matdoes.dev> | 2025-02-21 21:51:26 +0000 |
|---|---|---|
| committer | mat <git@matdoes.dev> | 2025-02-21 21:51:26 +0000 |
| commit | f5f15362f2cb48088eb8ccf80988f994fecd81c9 (patch) | |
| tree | a6c697556aaa3a43ed12eb15fc43946de9ffdb0f /azalea/examples/testbot/commands/debug.rs | |
| parent | 5fdea4c0b7c5617133a8b497b9ead8829a21135d (diff) | |
| download | azalea-drasl-f5f15362f2cb48088eb8ccf80988f994fecd81c9.tar.xz | |
fix some components not being removed from clients and add debugecsleak testbot command
Diffstat (limited to 'azalea/examples/testbot/commands/debug.rs')
| -rw-r--r-- | azalea/examples/testbot/commands/debug.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/azalea/examples/testbot/commands/debug.rs b/azalea/examples/testbot/commands/debug.rs index 1e0846f4..a7f15d2b 100644 --- a/azalea/examples/testbot/commands/debug.rs +++ b/azalea/examples/testbot/commands/debug.rs @@ -1,5 +1,7 @@ //! Commands for debugging and getting the current state of the bot. +use std::{env, fs::File, io::Write, thread, time::Duration}; + use azalea::{ brigadier::prelude::*, entity::{LookDirection, Position}, @@ -161,4 +163,48 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) { )); 1 })); + + commands.register(literal("debugecsleak").executes(|ctx: &Ctx| { + let source = ctx.source.lock(); + + source.reply("Ok!"); + source.bot.disconnect(); + + let ecs = source.bot.ecs.clone(); + thread::spawn(move || { + thread::sleep(Duration::from_secs(1)); + // dump the ecs + + let ecs = ecs.lock(); + + let report_path = env::temp_dir().join("azalea-ecs-leak-report.txt"); + let mut report = File::create(&report_path).unwrap(); + + for entity in ecs.iter_entities() { + writeln!(report, "Entity: {}", entity.id()).unwrap(); + let archetype = entity.archetype(); + let component_count = archetype.component_count(); + + let component_names = archetype + .components() + .map(|c| ecs.components().get_info(c).unwrap().name()) + .collect::<Vec<_>>(); + writeln!( + report, + "- {component_count} components: {}", + component_names.join(", ") + ) + .unwrap(); + } + + for (info, _) in ecs.iter_resources() { + writeln!(report, "Resource: {}", info.name()).unwrap(); + writeln!(report, "- Size: {} bytes", info.layout().size()).unwrap(); + } + + println!("\x1b[1mWrote report to {}\x1b[m", report_path.display()); + }); + + 1 + })); } |
