Skip to content

Commit

Permalink
Update string table and use const thread_local
Browse files Browse the repository at this point in the history
  • Loading branch information
morrisonlevi committed Feb 26, 2024
1 parent 0ecc7f2 commit e614517
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
32 changes: 12 additions & 20 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions profiling/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ bumpalo = { version = "3.12", features = ["collections"] }
cfg-if = { version = "1.0" }
cpu-time = { version = "1.0" }
crossbeam-channel = { version = "0.5", default-features = false, features = ["std"] }
datadog-profiling = { git = "https://github.com/DataDog/libdatadog", rev = "600678b" }
ddcommon = { git = "https://github.com/DataDog/libdatadog", rev = "600678b" }
datadog-profiling = { git = "https://github.com/DataDog/libdatadog", rev = "a21056a5fa3c0f54d555a978bd1f3ea9726ef0f8" }
ddcommon = { git = "https://github.com/DataDog/libdatadog", rev = "a21056a5fa3c0f54d555a978bd1f3ea9726ef0f8" }
env_logger = { version = "0.10" }
indexmap = { version = "2.2" }
lazy_static = { version = "1.4" }
Expand Down
19 changes: 17 additions & 2 deletions profiling/src/profiling/stalk_walking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::str::Utf8Error;
/// the fact that there are two cache slots used, and they don't have to be in
/// sync. However, they usually are, so we simplify.
#[cfg(php_run_time_cache)]
#[derive(Debug, Default)]
#[derive(Debug)]
pub struct FunctionRunTimeCacheStats {
hit: usize,
missed: usize,
Expand All @@ -17,16 +17,31 @@ pub struct FunctionRunTimeCacheStats {

#[cfg(php_run_time_cache)]
impl FunctionRunTimeCacheStats {
pub const fn new() -> Self {
Self {
hit: 0,
missed: 0,
not_applicable: 0,
}
}

pub fn hit_rate(&self) -> f64 {
let denominator = (self.hit + self.missed + self.not_applicable) as f64;
self.hit as f64 / denominator
}
}

#[cfg(php_run_time_cache)]
impl Default for FunctionRunTimeCacheStats {
fn default() -> Self {
Self::new()
}
}

#[cfg(php_run_time_cache)]
thread_local! {
static CACHED_STRINGS: RefCell<StringTable> = RefCell::new(StringTable::new());
pub static FUNCTION_CACHE_STATS: RefCell<FunctionRunTimeCacheStats> = RefCell::new(Default::default())
pub static FUNCTION_CACHE_STATS: RefCell<FunctionRunTimeCacheStats> = const { RefCell::new(FunctionRunTimeCacheStats::new()) };
}

/// # Safety
Expand Down

0 comments on commit e614517

Please sign in to comment.