Skip to content

Commit da17648

Browse files
committed
Expose DiagnosticPath though the plugins
1 parent 20b0647 commit da17648

File tree

2 files changed

+39
-14
lines changed

2 files changed

+39
-14
lines changed

crates/bevy_render/src/diagnostic/mesh_allocator_diagnostic_plugin.rs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,46 @@ use bevy_platform::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
66
use crate::{mesh::allocator::MeshAllocator, Extract, ExtractSchedule, RenderApp};
77

88
/// Number of meshes allocated by the allocator
9-
const MESH_ALLOCATOR_SLABS: DiagnosticPath = DiagnosticPath::const_new("mesh_allocator_slabs");
9+
static MESH_ALLOCATOR_SLABS: DiagnosticPath = DiagnosticPath::const_new("mesh_allocator_slabs");
1010

1111
/// Total size of all slabs
12-
const MESH_ALLOCATOR_SLABS_SIZE: DiagnosticPath =
12+
static MESH_ALLOCATOR_SLABS_SIZE: DiagnosticPath =
1313
DiagnosticPath::const_new("mesh_allocator_slabs_size");
1414

1515
/// Number of meshes allocated into slabs
16-
const MESH_ALLOCATOR_ALLOCATIONS: DiagnosticPath =
16+
static MESH_ALLOCATOR_ALLOCATIONS: DiagnosticPath =
1717
DiagnosticPath::const_new("mesh_allocator_allocations");
1818

1919
pub struct MeshAllocatorDiagnosticPlugin;
2020

21+
impl MeshAllocatorDiagnosticPlugin {
22+
/// Get the [`DiagnosticPath`] for slab count
23+
pub fn slabs_diagnostic_path() -> &'static DiagnosticPath {
24+
&MESH_ALLOCATOR_SLABS
25+
}
26+
/// Get the [`DiagnosticPath`] for total slabs size
27+
pub fn slabs_size_diagnostic_path() -> &'static DiagnosticPath {
28+
&MESH_ALLOCATOR_SLABS_SIZE
29+
}
30+
/// Get the [`DiagnosticPath`] for mesh allocations
31+
pub fn allocations_diagnostic_path() -> &'static DiagnosticPath {
32+
&MESH_ALLOCATOR_ALLOCATIONS
33+
}
34+
}
35+
2136
impl Plugin for MeshAllocatorDiagnosticPlugin {
2237
fn build(&self, app: &mut bevy_app::App) {
23-
app.register_diagnostic(Diagnostic::new(MESH_ALLOCATOR_SLABS).with_suffix(" slabs"))
24-
.register_diagnostic(Diagnostic::new(MESH_ALLOCATOR_SLABS_SIZE).with_suffix(" bytes"))
25-
.register_diagnostic(Diagnostic::new(MESH_ALLOCATOR_ALLOCATIONS).with_suffix(" meshes"))
26-
.init_resource::<MeshAllocatorMeasurements>()
27-
.add_systems(PreUpdate, add_mesh_allocator_measurement);
38+
app.register_diagnostic(
39+
Diagnostic::new(MESH_ALLOCATOR_SLABS.clone()).with_suffix(" slabs"),
40+
)
41+
.register_diagnostic(
42+
Diagnostic::new(MESH_ALLOCATOR_SLABS_SIZE.clone()).with_suffix(" bytes"),
43+
)
44+
.register_diagnostic(
45+
Diagnostic::new(MESH_ALLOCATOR_ALLOCATIONS.clone()).with_suffix(" meshes"),
46+
)
47+
.init_resource::<MeshAllocatorMeasurements>()
48+
.add_systems(PreUpdate, add_mesh_allocator_measurement);
2849

2950
if let Some(render_app) = app.get_sub_app_mut(RenderApp) {
3051
render_app.add_systems(ExtractSchedule, measure_allocator);

crates/bevy_render/src/diagnostic/render_asset_diagnostic_plugin.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,29 @@ use crate::{
1212

1313
pub struct RenderAssetDiagnosticPlugin<A: RenderAsset> {
1414
suffix: &'static str,
15-
path: DiagnosticPath,
1615
_phantom: PhantomData<A>,
1716
}
1817

1918
impl<A: RenderAsset> RenderAssetDiagnosticPlugin<A> {
2019
pub fn new(suffix: &'static str) -> Self {
2120
Self {
2221
suffix,
23-
path: DiagnosticPath::from_components(["render_asset", type_name::<A>()]),
2422
_phantom: PhantomData,
2523
}
2624
}
25+
26+
pub fn render_asset_diagnostic_path() -> DiagnosticPath {
27+
DiagnosticPath::from_components(["render_asset", type_name::<A>()])
28+
}
2729
}
2830

2931
impl<A: RenderAsset> Plugin for RenderAssetDiagnosticPlugin<A> {
3032
fn build(&self, app: &mut bevy_app::App) {
31-
app.register_diagnostic(Diagnostic::new(self.path.clone()).with_suffix(self.suffix))
32-
.init_resource::<RenderAssetMeasurements<A>>()
33-
.add_systems(PreUpdate, add_render_asset_measurement::<A>);
33+
app.register_diagnostic(
34+
Diagnostic::new(Self::render_asset_diagnostic_path()).with_suffix(self.suffix),
35+
)
36+
.init_resource::<RenderAssetMeasurements<A>>()
37+
.add_systems(PreUpdate, add_render_asset_measurement::<A>);
3438

3539
if let Some(render_app) = app.get_sub_app_mut(RenderApp) {
3640
render_app.add_systems(ExtractSchedule, measure_render_asset::<A>);
@@ -58,7 +62,7 @@ fn add_render_asset_measurement<A: RenderAsset>(
5862
measurements: Res<RenderAssetMeasurements<A>>,
5963
) {
6064
diagnostics.add_measurement(
61-
&DiagnosticPath::from_components(["render_asset", type_name::<A>()]),
65+
&RenderAssetDiagnosticPlugin::<A>::render_asset_diagnostic_path(),
6266
|| measurements.assets.load(Ordering::Relaxed) as f64,
6367
);
6468
}

0 commit comments

Comments
 (0)