Skip to content

Commit 86fa2ac

Browse files
authored
Fix issues in log_diagnostics example (#18652)
# Objective Adopts / builds on top of #18435. The `log_diagnostics` example has bit-rotted and accumulated multiple issues: - It didn't explain the ordering constraint on DefaultPlugins, as noted by the original PR - Apparently `AssetCountDiagnosticsPlugin` no longer exists (?!). I couldn't figure out when or why it was removed, maybe it got missed in Assets v2? - The comments didn't explain what kind of info you get by the various plugins, making you do work to figure it out - ~As far as I can tell `RenderDiagnosticsPlugin` currently doesn't register any diagnostics in the traditional sense, but is only focused on rendering spans? At least it doesn't print anything extra when added for me, so having it here is misleading.~ It didn't print anything because there was nothing to render in this example ## Solution - Make all plugins be commented in to prevent further bit-rot - Remove reference to the missing plugin - Add extra comments describing the diagnostics in more detail - Add something to render so we get render diagnostics ## Testing Run the example, see relevant diagnostics printed out
1 parent 5973ba4 commit 86fa2ac

File tree

1 file changed

+48
-14
lines changed

1 file changed

+48
-14
lines changed

examples/diagnostics/log_diagnostics.rs

+48-14
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,56 @@ use bevy::{
88
fn main() {
99
App::new()
1010
.add_plugins((
11+
// The diagnostics plugins need to be added after DefaultPlugins as they use e.g. the time plugin for timestamps.
1112
DefaultPlugins,
12-
// Adds frame time diagnostics
13-
FrameTimeDiagnosticsPlugin::default(),
14-
// Adds a system that prints diagnostics to the console
13+
// Adds a system that prints diagnostics to the console.
14+
// The other diagnostics plugins can still be used without this if you want to use them in an ingame overlay for example.
1515
LogDiagnosticsPlugin::default(),
16-
// Any plugin can register diagnostics. Uncomment this to add an entity count diagnostics:
17-
// bevy::diagnostic::EntityCountDiagnosticsPlugin::default(),
18-
19-
// Uncomment this to add an asset count diagnostics:
20-
// bevy::asset::diagnostic::AssetCountDiagnosticsPlugin::<Texture>::default(),
21-
22-
// Uncomment this to add system info diagnostics:
23-
// bevy::diagnostic::SystemInformationDiagnosticsPlugin::default()
24-
25-
// Uncomment this to add rendering diagnostics:
26-
// bevy::render::diagnostic::RenderDiagnosticsPlugin::default(),
16+
// Adds frame time, FPS and frame count diagnostics.
17+
FrameTimeDiagnosticsPlugin::default(),
18+
// Adds an entity count diagnostic.
19+
bevy::diagnostic::EntityCountDiagnosticsPlugin,
20+
// Adds cpu and memory usage diagnostics for systems and the entire game process.
21+
bevy::diagnostic::SystemInformationDiagnosticsPlugin,
22+
// Forwards various diagnostics from the render app to the main app.
23+
// These are pretty verbose but can be useful to pinpoint performance issues.
24+
bevy_render::diagnostic::RenderDiagnosticsPlugin,
2725
))
26+
// No rendering diagnostics are emitted unless something is drawn to the screen,
27+
// so we spawn a small scene.
28+
.add_systems(Startup, setup)
2829
.run();
2930
}
31+
32+
/// set up a simple 3D scene
33+
fn setup(
34+
mut commands: Commands,
35+
mut meshes: ResMut<Assets<Mesh>>,
36+
mut materials: ResMut<Assets<StandardMaterial>>,
37+
) {
38+
// circular base
39+
commands.spawn((
40+
Mesh3d(meshes.add(Circle::new(4.0))),
41+
MeshMaterial3d(materials.add(Color::WHITE)),
42+
Transform::from_rotation(Quat::from_rotation_x(-std::f32::consts::FRAC_PI_2)),
43+
));
44+
// cube
45+
commands.spawn((
46+
Mesh3d(meshes.add(Cuboid::new(1.0, 1.0, 1.0))),
47+
MeshMaterial3d(materials.add(Color::srgb_u8(124, 144, 255))),
48+
Transform::from_xyz(0.0, 0.5, 0.0),
49+
));
50+
// light
51+
commands.spawn((
52+
PointLight {
53+
shadows_enabled: true,
54+
..default()
55+
},
56+
Transform::from_xyz(4.0, 8.0, 4.0),
57+
));
58+
// camera
59+
commands.spawn((
60+
Camera3d::default(),
61+
Transform::from_xyz(-2.5, 4.5, 9.0).looking_at(Vec3::ZERO, Vec3::Y),
62+
));
63+
}

0 commit comments

Comments
 (0)