@@ -53,12 +53,20 @@ pub struct Metrics {
53
53
pub size_memory_cache : usize ,
54
54
}
55
55
56
+ #[ derive( Debug , Clone ) ]
57
+ pub struct PerModuleMetrics {
58
+ /// Hits (i.e. loads) of the module from the cache
59
+ pub hits : u32 ,
60
+ /// Size the module takes up in memory
61
+ pub size : usize ,
62
+ }
63
+
56
64
#[ derive( Debug , Clone ) ]
57
65
pub struct PinnedMetrics {
58
66
// It is *intentional* that this is only a vector
59
67
// We don't need a potentially expensive hashing algorithm here
60
68
// The checksums are sourced from a hashmap already, ensuring uniqueness of the checksums
61
- pub hits_per_contract : Vec < ( Checksum , u32 ) > ,
69
+ pub per_module : Vec < ( Checksum , PerModuleMetrics ) > ,
62
70
}
63
71
64
72
#[ derive( Clone , Debug ) ]
@@ -192,13 +200,20 @@ where
192
200
193
201
pub fn pinned_metrics ( & self ) -> PinnedMetrics {
194
202
let cache = self . inner . lock ( ) . unwrap ( ) ;
195
- let hits_per_contract = cache
203
+ let per_module = cache
196
204
. pinned_memory_cache
197
205
. iter ( )
198
- . map ( |( checksum, module) | ( * checksum, module. hits ) )
206
+ . map ( |( checksum, module) | {
207
+ let metrics = PerModuleMetrics {
208
+ hits : module. hits ,
209
+ size : module. module . size_estimate ,
210
+ } ;
211
+
212
+ ( * checksum, metrics)
213
+ } )
199
214
. collect ( ) ;
200
215
201
- PinnedMetrics { hits_per_contract }
216
+ PinnedMetrics { per_module }
202
217
}
203
218
204
219
pub fn metrics ( & self ) -> Metrics {
@@ -1436,34 +1451,38 @@ mod tests {
1436
1451
cache. pin ( & checksum) . unwrap ( ) ;
1437
1452
1438
1453
let pinned_metrics = cache. pinned_metrics ( ) ;
1439
- assert_eq ! ( pinned_metrics. hits_per_contract, [ ( checksum, 0 ) ] ) ;
1454
+ assert_eq ! ( pinned_metrics. per_module. len( ) , 1 ) ;
1455
+ assert_eq ! ( pinned_metrics. per_module[ 0 ] . 0 , checksum) ;
1456
+ assert_eq ! ( pinned_metrics. per_module[ 0 ] . 1 . hits, 0 ) ;
1440
1457
1441
1458
let backend = mock_backend ( & [ ] ) ;
1442
1459
let _ = cache
1443
1460
. get_instance ( & checksum, backend, TESTING_OPTIONS )
1444
1461
. unwrap ( ) ;
1445
1462
1446
1463
let pinned_metrics = cache. pinned_metrics ( ) ;
1447
- assert_eq ! ( pinned_metrics. hits_per_contract, [ ( checksum, 1 ) ] ) ;
1464
+ assert_eq ! ( pinned_metrics. per_module. len( ) , 1 ) ;
1465
+ assert_eq ! ( pinned_metrics. per_module[ 0 ] . 0 , checksum) ;
1466
+ assert_eq ! ( pinned_metrics. per_module[ 0 ] . 1 . hits, 1 ) ;
1448
1467
1449
1468
let empty_checksum = cache. save_wasm ( EMPTY_CONTRACT ) . unwrap ( ) ;
1450
1469
cache. pin ( & empty_checksum) . unwrap ( ) ;
1451
1470
1452
1471
let pinned_metrics = cache. pinned_metrics ( ) ;
1453
- assert_eq ! ( pinned_metrics. hits_per_contract . len( ) , 2 ) ;
1472
+ assert_eq ! ( pinned_metrics. per_module . len( ) , 2 ) ;
1454
1473
1455
1474
let get_module_hits = |checksum| {
1456
1475
pinned_metrics
1457
- . hits_per_contract
1476
+ . per_module
1458
1477
. iter ( )
1459
1478
. find ( |( iter_checksum, _module) | * iter_checksum == checksum)
1460
1479
. map ( |( _checksum, module) | module)
1461
- . copied ( )
1480
+ . cloned ( )
1462
1481
. unwrap ( )
1463
1482
} ;
1464
1483
1465
- assert_eq ! ( get_module_hits( checksum) , 1 ) ;
1466
- assert_eq ! ( get_module_hits( empty_checksum) , 0 ) ;
1484
+ assert_eq ! ( get_module_hits( checksum) . hits , 1 ) ;
1485
+ assert_eq ! ( get_module_hits( empty_checksum) . hits , 0 ) ;
1467
1486
}
1468
1487
1469
1488
#[ test]
0 commit comments