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

Improve bevy_ecs inspectability and add debugging methods. #17331

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

AlephCubed
Copy link
Contributor

@AlephCubed AlephCubed commented Jan 12, 2025

My attempt at adopting #7758. Currently this is simply an update to modern Bevy and still has a ways to go.

Solution

  • Add len, is_empty, and iter methods to Bundle.
  • Add diagnostic methods to World, Schedules, Dag, and ComponentId (currently functions, not methods).

Todo

  • Convert the functions into methods as suggested by this review.
  • Add documentation to the methods.
  • Reimplement dependency flatten debugging (currently commented out).

Example output:

This is an example of World's diagnostic method/function output:

world:
  summary:
    component: 4
    bundle: 9
    archetype: 4
    entity: 1
    resource: 2
    resource(non send): 0
    table: 3
    sparse set: 5
  detail:
    bundles:
      BundleId(0): ["ComponentId(7)(world_diagnostic::HitPoint)"]
      BundleId(1): ["ComponentId(7)(world_diagnostic::HitPoint)", "ComponentId(6)(world_diagnostic::Counter)", "ComponentId(8)(world_diagnostic::HighlightFlag)"]
      BundleId(2): ["ComponentId(6)(world_diagnostic::Counter)"]
      BundleId(3): ["ComponentId(8)(world_diagnostic::HighlightFlag)"]
    components:
      ComponentId(0)(bevy_ecs::world::component_constants::OnAdd) SparseSet send_sync
      ComponentId(1)(bevy_ecs::world::component_constants::OnInsert) SparseSet send_sync
      ComponentId(2)(bevy_ecs::world::component_constants::OnReplace) SparseSet send_sync
      ComponentId(3)(bevy_ecs::world::component_constants::OnRemove) SparseSet send_sync
      ComponentId(4)(bevy_ecs::schedule::schedule::Schedules) Table send_sync
      ComponentId(5)(world_diagnostic::GameState) Table send_sync
      ComponentId(6)(world_diagnostic::Counter) Table send_sync
      ComponentId(7)(world_diagnostic::HitPoint) Table send_sync
      ComponentId(8)(world_diagnostic::HighlightFlag) SparseSet send_sync
    archetypes:
      ArchetypeId(0): components:[] table:TableId(0) entity:0
      ArchetypeId(1): components:["ComponentId(7)(world_diagnostic::HitPoint)"] table:TableId(1) entity:0
      ArchetypeId(2): components:["ComponentId(6)(world_diagnostic::Counter)", "ComponentId(7)(world_diagnostic::HitPoint)", "ComponentId(8)(world_diagnostic::HighlightFlag)"] table:TableId(2) entity:1
      ArchetypeId(3): components:["ComponentId(6)(world_diagnostic::Counter)", "ComponentId(7)(world_diagnostic::HitPoint)"] table:TableId(2) entity:0
    tables:
      [0] entities: 0
      [1] entities: 0
      [2] entities: 1
    resources:
      ComponentId(4)(bevy_ecs::schedule::schedule::Schedules)
      ComponentId(5)(world_diagnostic::GameState)
    sparse_set:
      ComponentId(0)(bevy_ecs::world::component_constants::OnAdd) entity:0
      ComponentId(1)(bevy_ecs::world::component_constants::OnInsert) entity:0
      ComponentId(2)(bevy_ecs::world::component_constants::OnReplace) entity:0
      ComponentId(3)(bevy_ecs::world::component_constants::OnRemove) entity:0
      ComponentId(8)(world_diagnostic::HighlightFlag) entity:1
Schedule:
  schedules: 1
    label: Bar kind:SingleThreaded
  hierachy:
    nodes:
      Set(6)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(), world_diagnostic::second_system>()))
      Set(5)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(), world_diagnostic::first_system>()))
      Set(4)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(bevy_ecs::change_detection::Res<world_diagnostic::GameState>, bevy_ecs::system::query::Query<&mut world_diagnostic::Counter>), world_diagnostic::sync_counter>()))
      System(2)(world_diagnostic::sync_counter)
      Set(3)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(bevy_ecs::change_detection::ResMut<world_diagnostic::GameState>), world_diagnostic::increase_game_state_count>()))
      Set(2)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(), world_diagnostic::empty_system>()))
      Set(1)(Set2)
      System(4)(world_diagnostic::second_system)
      System(3)(world_diagnostic::first_system)
      Set(0)(Set1)
      System(1)(world_diagnostic::increase_game_state_count)
      System(0)(world_diagnostic::empty_system)
    edges:
      Set(3)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(bevy_ecs::change_detection::ResMut<world_diagnostic::GameState>), world_diagnostic::increase_game_state_count>())) -> System(1)(world_diagnostic::increase_game_state_count)
      Set(1)(Set2) -> System(4)(world_diagnostic::second_system)
      Set(5)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(), world_diagnostic::first_system>())) -> System(3)(world_diagnostic::first_system)
      Set(6)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(), world_diagnostic::second_system>())) -> System(4)(world_diagnostic::second_system)
      Set(1)(Set2) -> System(3)(world_diagnostic::first_system)
      Set(0)(Set1) -> System(1)(world_diagnostic::increase_game_state_count)
      Set(4)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(bevy_ecs::change_detection::Res<world_diagnostic::GameState>, bevy_ecs::system::query::Query<&mut world_diagnostic::Counter>), world_diagnostic::sync_counter>())) -> System(2)(world_diagnostic::sync_counter)
      Set(2)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(), world_diagnostic::empty_system>())) -> System(0)(world_diagnostic::empty_system)
      Set(0)(Set1) -> System(0)(world_diagnostic::empty_system)
    topsorted:
      Set(6)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(), world_diagnostic::second_system>()))
      Set(5)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(), world_diagnostic::first_system>()))
      Set(4)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(bevy_ecs::change_detection::Res<world_diagnostic::GameState>, bevy_ecs::system::query::Query<&mut world_diagnostic::Counter>), world_diagnostic::sync_counter>()))
      System(2)(world_diagnostic::sync_counter)
      Set(3)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(bevy_ecs::change_detection::ResMut<world_diagnostic::GameState>), world_diagnostic::increase_game_state_count>()))
      Set(2)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(), world_diagnostic::empty_system>()))
      Set(1)(Set2)
      System(4)(world_diagnostic::second_system)
      System(3)(world_diagnostic::first_system)
      Set(0)(Set1)
      System(1)(world_diagnostic::increase_game_state_count)
      System(0)(world_diagnostic::empty_system)
  dependency:
    nodes:
      Set(0)(Set1)
      Set(1)(Set2)
      System(0)(world_diagnostic::empty_system)
      Set(2)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(), world_diagnostic::empty_system>()))
      System(1)(world_diagnostic::increase_game_state_count)
      Set(3)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(bevy_ecs::change_detection::ResMut<world_diagnostic::GameState>), world_diagnostic::increase_game_state_count>()))
      Set(4)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(bevy_ecs::change_detection::Res<world_diagnostic::GameState>, bevy_ecs::system::query::Query<&mut world_diagnostic::Counter>), world_diagnostic::sync_counter>()))
      System(2)(world_diagnostic::sync_counter)
      System(3)(world_diagnostic::first_system)
      Set(5)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(), world_diagnostic::first_system>()))
      Set(6)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(), world_diagnostic::second_system>()))
      System(4)(world_diagnostic::second_system)
    edges:
      System(1)(world_diagnostic::increase_game_state_count) -> Set(4)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(bevy_ecs::change_detection::Res<world_diagnostic::GameState>, bevy_ecs::system::query::Query<&mut world_diagnostic::Counter>), world_diagnostic::sync_counter>()))
      System(3)(world_diagnostic::first_system) -> Set(6)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(), world_diagnostic::second_system>()))
    topsorted:
      System(4)(world_diagnostic::second_system)
      Set(5)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(), world_diagnostic::first_system>()))
      System(3)(world_diagnostic::first_system)
      Set(6)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(), world_diagnostic::second_system>()))
      System(2)(world_diagnostic::sync_counter)
      Set(3)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(bevy_ecs::change_detection::ResMut<world_diagnostic::GameState>), world_diagnostic::increase_game_state_count>()))
      System(1)(world_diagnostic::increase_game_state_count)
      Set(4)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(bevy_ecs::change_detection::Res<world_diagnostic::GameState>, bevy_ecs::system::query::Query<&mut world_diagnostic::Counter>), world_diagnostic::sync_counter>()))
      Set(2)(SystemTypeSet(fn bevy_ecs::system::function_system::FunctionSystem<fn(), world_diagnostic::empty_system>()))
      System(0)(world_diagnostic::empty_system)
      Set(1)(Set2)
      Set(0)(Set1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants