diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-07 05:48:48 +0000 |
commit | ef24de24a82fe681581cc130f342363c47c0969a (patch) | |
tree | 0d494f7e1a38b95c92426f58fe6eaa877303a86c /vendor/gix-features-0.35.0/src/cache.rs | |
parent | Releasing progress-linux version 1.74.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-ef24de24a82fe681581cc130f342363c47c0969a.tar.xz rustc-ef24de24a82fe681581cc130f342363c47c0969a.zip |
Merging upstream version 1.75.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/gix-features-0.35.0/src/cache.rs')
-rw-r--r-- | vendor/gix-features-0.35.0/src/cache.rs | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/vendor/gix-features-0.35.0/src/cache.rs b/vendor/gix-features-0.35.0/src/cache.rs new file mode 100644 index 000000000..c56a34e12 --- /dev/null +++ b/vendor/gix-features-0.35.0/src/cache.rs @@ -0,0 +1,76 @@ +#[cfg(feature = "cache-efficiency-debug")] +mod impl_ { + /// A helper to collect useful information about cache efficiency. + pub struct Debug { + owner: String, + hits: usize, + puts: usize, + misses: usize, + } + + impl Debug { + /// Create a new instance + #[inline] + pub fn new(owner: String) -> Self { + Debug { + owner, + hits: 0, + puts: 0, + misses: 0, + } + } + /// Count cache insertions + #[inline] + pub fn put(&mut self) { + self.puts += 1; + } + /// Count hits + #[inline] + pub fn hit(&mut self) { + self.hits += 1; + } + /// Count misses + #[inline] + pub fn miss(&mut self) { + self.misses += 1; + } + } + + impl Drop for Debug { + fn drop(&mut self) { + let hits = self.hits; + let misses = self.misses; + let ratio = hits as f32 / misses as f32; + eprintln!( + "{}[{:0x}]: {} / {} (hits/misses) = {:.02}%, puts = {}", + self.owner, + self as *const _ as usize, + hits, + misses, + ratio * 100.0, + self.puts + ); + } + } +} +#[cfg(not(feature = "cache-efficiency-debug"))] +mod impl_ { + /// The disabled, zero size do-nothing equivalent + pub struct Debug; + + impl Debug { + /// Create a new instance + #[inline] + pub fn new(_owner: String) -> Self { + Debug + } + /// noop + pub fn put(&mut self) {} + /// noop + pub fn hit(&mut self) {} + /// noop + pub fn miss(&mut self) {} + } +} + +pub use impl_::Debug; |