aboutsummaryrefslogtreecommitdiff
path: root/azalea/examples/testbot/commands/debug.rs
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-02-23 03:10:21 +0000
committermat <git@matdoes.dev>2025-02-23 03:10:21 +0000
commitf8130c3c92946d2293634ba4e252d6bc93026c3c (patch)
tree08fc6097137d7b4d31b692f4ba993b23acc64eb7 /azalea/examples/testbot/commands/debug.rs
parent34f53baf85fb5c7163ec5d71a8ab9d45d3f271b6 (diff)
downloadazalea-drasl-f8130c3c92946d2293634ba4e252d6bc93026c3c.tar.xz
minor memory usage optimizations
Diffstat (limited to 'azalea/examples/testbot/commands/debug.rs')
-rw-r--r--azalea/examples/testbot/commands/debug.rs68
1 files changed, 66 insertions, 2 deletions
diff --git a/azalea/examples/testbot/commands/debug.rs b/azalea/examples/testbot/commands/debug.rs
index fe552668..df98511d 100644
--- a/azalea/examples/testbot/commands/debug.rs
+++ b/azalea/examples/testbot/commands/debug.rs
@@ -5,11 +5,15 @@ use std::{env, fs::File, io::Write, thread, time::Duration};
use azalea::{
BlockPos,
brigadier::prelude::*,
+ chunks::ReceiveChunkEvent,
entity::{LookDirection, Position},
interact::HitResultComponent,
+ packet_handling::game,
pathfinder::{ExecutingPath, Pathfinder},
world::MinecraftEntityId,
};
+use azalea_world::InstanceContainer;
+use bevy_ecs::event::Events;
use parking_lot::Mutex;
use super::{CommandSource, Ctx};
@@ -200,8 +204,53 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
writeln!(report).unwrap();
for (info, _) in ecs.iter_resources() {
- writeln!(report, "Resource: {}", info.name()).unwrap();
- writeln!(report, "- Size: {} bytes", info.layout().size()).unwrap();
+ let name = info.name();
+ writeln!(report, "Resource: {name}").unwrap();
+ // writeln!(report, "- Size: {} bytes",
+ // info.layout().size()).unwrap();
+
+ match name {
+ "azalea_world::container::InstanceContainer" => {
+ let instance_container = ecs.resource::<InstanceContainer>();
+ for (instance_name, instance) in &instance_container.instances {
+ writeln!(report, "- Name: {}", instance_name).unwrap();
+ writeln!(report, "- Reference count: {}", instance.strong_count())
+ .unwrap();
+ if let Some(instance) = instance.upgrade() {
+ let instance = instance.read();
+ let strong_chunks = instance
+ .chunks
+ .map
+ .iter()
+ .filter(|(_, v)| v.strong_count() > 0)
+ .count();
+ writeln!(
+ report,
+ "- Chunks: {} strongly referenced, {} in map",
+ strong_chunks,
+ instance.chunks.map.len()
+ )
+ .unwrap();
+ writeln!(
+ report,
+ "- Entities: {}",
+ instance.entities_by_chunk.len()
+ )
+ .unwrap();
+ }
+ }
+ }
+ "bevy_ecs::event::collections::Events<azalea_client::packet_handling::game::PacketEvent>" => {
+ let events = ecs.resource::<Events<game::PacketEvent>>();
+ writeln!(report, "- Event count: {}", events.len()).unwrap();
+ }
+ "bevy_ecs::event::collections::Events<azalea_client::chunks::ReceiveChunkEvent>" => {
+ let events = ecs.resource::<Events<ReceiveChunkEvent>>();
+ writeln!(report, "- Event count: {}", events.len()).unwrap();
+ }
+
+ _ => {}
+ }
}
println!("\x1b[1mWrote report to {}\x1b[m", report_path.display());
@@ -209,4 +258,19 @@ pub fn register(commands: &mut CommandDispatcher<Mutex<CommandSource>>) {
1
}));
+
+ commands.register(literal("exit").executes(|ctx: &Ctx| {
+ let source = ctx.source.lock();
+ source.reply("bye!");
+
+ source.bot.disconnect();
+
+ thread::spawn(move || {
+ thread::sleep(Duration::from_secs(1));
+
+ std::process::exit(0);
+ });
+
+ 1
+ }));
}