Expose DiagnosticPath though the plugins
This commit is contained in:
parent
36a66839e9
commit
eca3de2fa2
@ -6,25 +6,46 @@ use bevy_platform::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
|
||||
use crate::{mesh::allocator::MeshAllocator, Extract, ExtractSchedule, RenderApp};
|
||||
|
||||
/// Number of meshes allocated by the allocator
|
||||
const MESH_ALLOCATOR_SLABS: DiagnosticPath = DiagnosticPath::const_new("mesh_allocator_slabs");
|
||||
static MESH_ALLOCATOR_SLABS: DiagnosticPath = DiagnosticPath::const_new("mesh_allocator_slabs");
|
||||
|
||||
/// Total size of all slabs
|
||||
const MESH_ALLOCATOR_SLABS_SIZE: DiagnosticPath =
|
||||
static MESH_ALLOCATOR_SLABS_SIZE: DiagnosticPath =
|
||||
DiagnosticPath::const_new("mesh_allocator_slabs_size");
|
||||
|
||||
/// Number of meshes allocated into slabs
|
||||
const MESH_ALLOCATOR_ALLOCATIONS: DiagnosticPath =
|
||||
static MESH_ALLOCATOR_ALLOCATIONS: DiagnosticPath =
|
||||
DiagnosticPath::const_new("mesh_allocator_allocations");
|
||||
|
||||
pub struct MeshAllocatorDiagnosticPlugin;
|
||||
|
||||
impl MeshAllocatorDiagnosticPlugin {
|
||||
/// Get the [`DiagnosticPath`] for slab count
|
||||
pub fn slabs_diagnostic_path() -> &'static DiagnosticPath {
|
||||
&MESH_ALLOCATOR_SLABS
|
||||
}
|
||||
/// Get the [`DiagnosticPath`] for total slabs size
|
||||
pub fn slabs_size_diagnostic_path() -> &'static DiagnosticPath {
|
||||
&MESH_ALLOCATOR_SLABS_SIZE
|
||||
}
|
||||
/// Get the [`DiagnosticPath`] for mesh allocations
|
||||
pub fn allocations_diagnostic_path() -> &'static DiagnosticPath {
|
||||
&MESH_ALLOCATOR_ALLOCATIONS
|
||||
}
|
||||
}
|
||||
|
||||
impl Plugin for MeshAllocatorDiagnosticPlugin {
|
||||
fn build(&self, app: &mut bevy_app::App) {
|
||||
app.register_diagnostic(Diagnostic::new(MESH_ALLOCATOR_SLABS).with_suffix(" slabs"))
|
||||
.register_diagnostic(Diagnostic::new(MESH_ALLOCATOR_SLABS_SIZE).with_suffix(" bytes"))
|
||||
.register_diagnostic(Diagnostic::new(MESH_ALLOCATOR_ALLOCATIONS).with_suffix(" meshes"))
|
||||
.init_resource::<MeshAllocatorMeasurements>()
|
||||
.add_systems(PreUpdate, add_mesh_allocator_measurement);
|
||||
app.register_diagnostic(
|
||||
Diagnostic::new(MESH_ALLOCATOR_SLABS.clone()).with_suffix(" slabs"),
|
||||
)
|
||||
.register_diagnostic(
|
||||
Diagnostic::new(MESH_ALLOCATOR_SLABS_SIZE.clone()).with_suffix(" bytes"),
|
||||
)
|
||||
.register_diagnostic(
|
||||
Diagnostic::new(MESH_ALLOCATOR_ALLOCATIONS.clone()).with_suffix(" meshes"),
|
||||
)
|
||||
.init_resource::<MeshAllocatorMeasurements>()
|
||||
.add_systems(PreUpdate, add_mesh_allocator_measurement);
|
||||
|
||||
if let Some(render_app) = app.get_sub_app_mut(RenderApp) {
|
||||
render_app.add_systems(ExtractSchedule, measure_allocator);
|
||||
|
||||
@ -12,7 +12,6 @@ use crate::{
|
||||
|
||||
pub struct RenderAssetDiagnosticPlugin<A: RenderAsset> {
|
||||
suffix: &'static str,
|
||||
path: DiagnosticPath,
|
||||
_phantom: PhantomData<A>,
|
||||
}
|
||||
|
||||
@ -20,17 +19,22 @@ impl<A: RenderAsset> RenderAssetDiagnosticPlugin<A> {
|
||||
pub fn new(suffix: &'static str) -> Self {
|
||||
Self {
|
||||
suffix,
|
||||
path: DiagnosticPath::from_components(["render_asset", type_name::<A>()]),
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render_asset_diagnostic_path() -> DiagnosticPath {
|
||||
DiagnosticPath::from_components(["render_asset", type_name::<A>()])
|
||||
}
|
||||
}
|
||||
|
||||
impl<A: RenderAsset> Plugin for RenderAssetDiagnosticPlugin<A> {
|
||||
fn build(&self, app: &mut bevy_app::App) {
|
||||
app.register_diagnostic(Diagnostic::new(self.path.clone()).with_suffix(self.suffix))
|
||||
.init_resource::<RenderAssetMeasurements<A>>()
|
||||
.add_systems(PreUpdate, add_render_asset_measurement::<A>);
|
||||
app.register_diagnostic(
|
||||
Diagnostic::new(Self::render_asset_diagnostic_path()).with_suffix(self.suffix),
|
||||
)
|
||||
.init_resource::<RenderAssetMeasurements<A>>()
|
||||
.add_systems(PreUpdate, add_render_asset_measurement::<A>);
|
||||
|
||||
if let Some(render_app) = app.get_sub_app_mut(RenderApp) {
|
||||
render_app.add_systems(ExtractSchedule, measure_render_asset::<A>);
|
||||
@ -58,7 +62,7 @@ fn add_render_asset_measurement<A: RenderAsset>(
|
||||
measurements: Res<RenderAssetMeasurements<A>>,
|
||||
) {
|
||||
diagnostics.add_measurement(
|
||||
&DiagnosticPath::from_components(["render_asset", type_name::<A>()]),
|
||||
&RenderAssetDiagnosticPlugin::<A>::render_asset_diagnostic_path(),
|
||||
|| measurements.assets.load(Ordering::Relaxed) as f64,
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user