@@ -6,25 +6,46 @@ use bevy_platform::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
6
6
use crate :: { mesh:: allocator:: MeshAllocator , Extract , ExtractSchedule , RenderApp } ;
7
7
8
8
/// 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" ) ;
10
10
11
11
/// Total size of all slabs
12
- const MESH_ALLOCATOR_SLABS_SIZE : DiagnosticPath =
12
+ static MESH_ALLOCATOR_SLABS_SIZE : DiagnosticPath =
13
13
DiagnosticPath :: const_new ( "mesh_allocator_slabs_size" ) ;
14
14
15
15
/// Number of meshes allocated into slabs
16
- const MESH_ALLOCATOR_ALLOCATIONS : DiagnosticPath =
16
+ static MESH_ALLOCATOR_ALLOCATIONS : DiagnosticPath =
17
17
DiagnosticPath :: const_new ( "mesh_allocator_allocations" ) ;
18
18
19
19
pub struct MeshAllocatorDiagnosticPlugin ;
20
20
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
+
21
36
impl Plugin for MeshAllocatorDiagnosticPlugin {
22
37
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) ;
28
49
29
50
if let Some ( render_app) = app. get_sub_app_mut ( RenderApp ) {
30
51
render_app. add_systems ( ExtractSchedule , measure_allocator) ;
0 commit comments