Skip to content

Commit

Permalink
add spans when recursively despawning an entity
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Mar 5, 2022
1 parent 25848a1 commit 0cb2a0a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/bevy_internal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ keywords = ["game", "engine", "gamedev", "graphics", "bevy"]
categories = ["game-engines", "graphics", "gui", "rendering"]

[features]
trace = [ "bevy_app/trace", "bevy_ecs/trace", "bevy_log/trace", "bevy_render/trace" ]
trace = [ "bevy_app/trace", "bevy_ecs/trace", "bevy_log/trace", "bevy_render/trace", "bevy_transform/trace" ]
trace_chrome = [ "bevy_log/tracing-chrome" ]
trace_tracy = [ "bevy_log/tracing-tracy" ]
wgpu_trace = ["bevy_render/wgpu_trace"]
Expand Down
3 changes: 3 additions & 0 deletions crates/bevy_transform/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ repository = "https://github.com/bevyengine/bevy"
license = "MIT OR Apache-2.0"
keywords = ["bevy"]

[features]
trace = []

[dependencies]
# bevy
bevy_app = { path = "../bevy_app", version = "0.6.0" }
Expand Down
34 changes: 34 additions & 0 deletions crates/bevy_transform/src/hierarchy/hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,28 @@ fn despawn_children(world: &mut World, entity: Entity) {

impl Command for DespawnRecursive {
fn write(self, world: &mut World) {
#[cfg(feature = "trace")]
let span = bevy_utils::tracing::info_span!(
"command",
name = "DespawnRecursive",
entity = bevy_utils::tracing::field::debug(self.entity)
);
#[cfg(feature = "trace")]
let _guard = span.enter();
despawn_with_children_recursive(world, self.entity);
}
}

impl Command for DespawnChildrenRecursive {
fn write(self, world: &mut World) {
#[cfg(feature = "trace")]
let span = bevy_utils::tracing::info_span!(
"command",
name = "DespawnChildrenRecursive",
entity = bevy_utils::tracing::field::debug(self.entity)
);
#[cfg(feature = "trace")]
let _guard = span.enter();
despawn_children(world, self.entity);
}
}
Expand Down Expand Up @@ -92,6 +108,15 @@ impl<'w> DespawnRecursiveExt for EntityMut<'w> {
/// Despawns the provided entity and its children.
fn despawn_recursive(mut self) {
let entity = self.id();

#[cfg(feature = "trace")]
let span = bevy_utils::tracing::info_span!(
"despawn_recursive",
entity = bevy_utils::tracing::field::debug(entity)
);
#[cfg(feature = "trace")]
let _guard = span.enter();

// SAFE: EntityMut is consumed so even though the location is no longer
// valid, it cannot be accessed again with the invalid location.
unsafe {
Expand All @@ -101,6 +126,15 @@ impl<'w> DespawnRecursiveExt for EntityMut<'w> {

fn despawn_descendants(&mut self) {
let entity = self.id();

#[cfg(feature = "trace")]
let span = bevy_utils::tracing::info_span!(
"despawn_descendants",
entity = bevy_utils::tracing::field::debug(entity)
);
#[cfg(feature = "trace")]
let _guard = span.enter();

// SAFE: The location is updated.
unsafe {
despawn_children(self.world_mut(), entity);
Expand Down

0 comments on commit 0cb2a0a

Please sign in to comment.