@@ -54,11 +54,11 @@ pub struct Metrics {
5454}
5555
5656#[ derive( Debug , Clone ) ]
57- pub struct HeavyMetrics {
57+ pub struct PinnedMetrics {
5858 // It is *intentional* that this is only a vector
5959 // We don't need a potentially expensive hashing algorithm here
6060 // The checksums are sourced from a hashmap already, ensuring uniqueness of the checksums
61- pub hits_per_pinned_contract : Vec < ( Checksum , u32 ) > ,
61+ pub hits_per_contract : Vec < ( Checksum , u32 ) > ,
6262}
6363
6464#[ derive( Clone , Debug ) ]
@@ -190,17 +190,15 @@ where
190190 self . inner . lock ( ) . unwrap ( ) . stats
191191 }
192192
193- pub fn heavy_metrics ( & self ) -> HeavyMetrics {
193+ pub fn pinned_metrics ( & self ) -> PinnedMetrics {
194194 let cache = self . inner . lock ( ) . unwrap ( ) ;
195- let hits_per_pinned_contract = cache
195+ let hits_per_contract = cache
196196 . pinned_memory_cache
197197 . iter ( )
198198 . map ( |( checksum, module) | ( * checksum, module. hits ) )
199199 . collect ( ) ;
200200
201- HeavyMetrics {
202- hits_per_pinned_contract,
203- }
201+ PinnedMetrics { hits_per_contract }
204202 }
205203
206204 pub fn metrics ( & self ) -> Metrics {
@@ -1431,22 +1429,41 @@ mod tests {
14311429 }
14321430
14331431 #[ test]
1434- fn heavy_metrics_works ( ) {
1432+ fn pinned_metrics_works ( ) {
14351433 let cache = unsafe { Cache :: new ( make_testing_options ( ) ) . unwrap ( ) } ;
14361434 let checksum = cache. save_wasm ( CONTRACT ) . unwrap ( ) ;
14371435
14381436 cache. pin ( & checksum) . unwrap ( ) ;
14391437
1440- let heavy_metrics = cache. heavy_metrics ( ) ;
1441- assert_eq ! ( heavy_metrics . hits_per_pinned_contract , [ ( checksum, 0 ) ] ) ;
1438+ let pinned_metrics = cache. pinned_metrics ( ) ;
1439+ assert_eq ! ( pinned_metrics . hits_per_contract , [ ( checksum, 0 ) ] ) ;
14421440
14431441 let backend = mock_backend ( & [ ] ) ;
14441442 let _ = cache
14451443 . get_instance ( & checksum, backend, TESTING_OPTIONS )
14461444 . unwrap ( ) ;
14471445
1448- let heavy_metrics = cache. heavy_metrics ( ) ;
1449- assert_eq ! ( heavy_metrics. hits_per_pinned_contract, [ ( checksum, 1 ) ] ) ;
1446+ let pinned_metrics = cache. pinned_metrics ( ) ;
1447+ assert_eq ! ( pinned_metrics. hits_per_contract, [ ( checksum, 1 ) ] ) ;
1448+
1449+ let empty_checksum = cache. save_wasm ( EMPTY_CONTRACT ) . unwrap ( ) ;
1450+ cache. pin ( & empty_checksum) . unwrap ( ) ;
1451+
1452+ let pinned_metrics = cache. pinned_metrics ( ) ;
1453+ assert_eq ! ( pinned_metrics. hits_per_contract. len( ) , 2 ) ;
1454+
1455+ let get_module_hits = |checksum| {
1456+ pinned_metrics
1457+ . hits_per_contract
1458+ . iter ( )
1459+ . find ( |( iter_checksum, _module) | * iter_checksum == checksum)
1460+ . map ( |( _checksum, module) | module)
1461+ . copied ( )
1462+ . unwrap ( )
1463+ } ;
1464+
1465+ assert_eq ! ( get_module_hits( checksum) , 1 ) ;
1466+ assert_eq ! ( get_module_hits( empty_checksum) , 0 ) ;
14501467 }
14511468
14521469 #[ test]
0 commit comments