| 1 | #[cfg(feature = "cache-efficiency-debug")] |
| 2 | mod impl_rust-analyzer cargo gix-features 0.48.0 cache/impl_/ { |
| 3 | /// A helper to collect useful information about cache efficiency. |
| 4 | pub struct Debugrust-analyzer cargo gix-features 0.48.0 cache/impl_/Debug# { |
| 5 | ownerrust-analyzer cargo gix-features 0.48.0 cache/impl_/Debug#owner.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 6 | hitsrust-analyzer cargo gix-features 0.48.0 cache/impl_/Debug#hits.: usize, |
| 7 | putsrust-analyzer cargo gix-features 0.48.0 cache/impl_/Debug#puts.: usize, |
| 8 | missesrust-analyzer cargo gix-features 0.48.0 cache/impl_/Debug#misses.: usize, |
| 9 | } |
| 10 | |
| 11 | impl Debugrust-analyzer cargo gix-features 0.48.0 cache/impl_/Debug# { |
| 12 | /// Create a new instance |
| 13 | #[inline] |
| 14 | pub fn newrust-analyzer cargo gix-features 0.48.0 cache/impl_/impl#[Debug]new().(owner: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> Selfrust-analyzer cargo gix-features 0.48.0 cache/impl_/impl#[Debug] { |
| 15 | Debugrust-analyzer cargo gix-features 0.48.0 cache/impl_/Debug# { |
| 16 | ownerrust-analyzer cargo gix-features 0.48.0 cache/impl_/Debug#owner., |
| 17 | hitsrust-analyzer cargo gix-features 0.48.0 cache/impl_/Debug#hits.: 0, |
| 18 | putsrust-analyzer cargo gix-features 0.48.0 cache/impl_/Debug#puts.: 0, |
| 19 | missesrust-analyzer cargo gix-features 0.48.0 cache/impl_/Debug#misses.: 0, |
| 20 | } |
| 21 | } |
| 22 | /// Count cache insertions |
| 23 | #[inline] |
| 24 | pub fn putrust-analyzer cargo gix-features 0.48.0 cache/impl_/impl#[Debug]put().(&mut self) { |
| 25 | self.putsrust-analyzer cargo gix-features 0.48.0 cache/impl_/Debug#puts. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 26 | } |
| 27 | /// Count hits |
| 28 | #[inline] |
| 29 | pub fn hitrust-analyzer cargo gix-features 0.48.0 cache/impl_/impl#[Debug]hit().(&mut self) { |
| 30 | self.hitsrust-analyzer cargo gix-features 0.48.0 cache/impl_/Debug#hits. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 31 | } |
| 32 | /// Count misses |
| 33 | #[inline] |
| 34 | pub fn missrust-analyzer cargo gix-features 0.48.0 cache/impl_/impl#[Debug]miss().(&mut self) { |
| 35 | self.missesrust-analyzer cargo gix-features 0.48.0 cache/impl_/Debug#misses. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | impl Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for Debugrust-analyzer cargo gix-features 0.48.0 cache/impl_/Debug# { |
| 40 | fn droprust-analyzer cargo gix-features 0.48.0 cache/impl_/impl#[Debug][Drop]drop().(&mut self) { |
| 41 | let hits = self.hitsrust-analyzer cargo gix-features 0.48.0 cache/impl_/Debug#hits.; |
| 42 | let misses = self.missesrust-analyzer cargo gix-features 0.48.0 cache/impl_/Debug#misses.; |
| 43 | let ratio = hits as f32 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div().misses as f32; |
| 44 | eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!( |
| 45 | "{}[{:0x}]: {} / {} (hits/misses) = {:.02}%, puts = {}", |
| 46 | self.ownerrust-analyzer cargo gix-features 0.48.0 cache/impl_/Debug#owner., |
| 47 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::from_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/from_ref().(self) as usize, |
| 48 | hits, |
| 49 | misses, |
| 50 | ratio *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Mul<Self>`]mul(). 100.0, |
| 51 | self.putsrust-analyzer cargo gix-features 0.48.0 cache/impl_/Debug#puts. |
| 52 | ); |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | #[cfg(not(feature = "cache-efficiency-debug"))] |
| 57 | mod impl_rust-analyzer cargo gix-features 0.48.0 cache/impl_/ { |
| 58 | /// The disabled, zero size do-nothing equivalent |
| 59 | pub struct Debug; |
| 60 | |
| 61 | impl Debugrust-analyzer cargo gix-features 0.48.0 cache/impl_/Debug# { |
| 62 | /// Create a new instance |
| 63 | #[inline] |
| 64 | pub fn new(_owner: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> Self { |
| 65 | Debugrust-analyzer cargo gix-features 0.48.0 cache/impl_/Debug# |
| 66 | } |
| 67 | /// noop |
| 68 | pub fn put(&mut self) {} |
| 69 | /// noop |
| 70 | pub fn hit(&mut self) {} |
| 71 | /// noop |
| 72 | pub fn miss(&mut self) {} |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | pub use impl_rust-analyzer cargo gix-features 0.48.0 cache/impl_/::Debugrust-analyzer cargo gix-features 0.48.0 cache/impl_/Debug#; |