-
Notifications
You must be signed in to change notification settings - Fork 572
Fix average write duration and extend server stats #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,7 +119,6 @@ pub struct SccacheServer<C: CommandCreatorSync + 'static> { | |
} | ||
|
||
/// Statistics about the cache. | ||
#[derive(Default)] | ||
struct ServerStats { | ||
/// The count of client compile requests. | ||
pub compile_requests: u64, | ||
|
@@ -146,15 +145,41 @@ struct ServerStats { | |
/// The count of errors writing to cache. | ||
pub cache_write_errors: u64, | ||
/// The number of successful cache writes. | ||
pub cache_writes: u32, | ||
/// The total seconds spent writing cache entries. | ||
pub cache_write_duration_s: u64, | ||
/// The total nanoseconds spent writing cache entries. | ||
pub cache_write_duration_ns: u32, | ||
pub cache_writes: u64, | ||
/// The total time spent writing cache entries. | ||
pub cache_write_duration: Duration, | ||
/// The total time spent reading cache hits. | ||
pub cache_read_hit_duration: Duration, | ||
/// The total time spent reading cache misses. | ||
pub cache_read_miss_duration: Duration, | ||
/// The count of compilation failures. | ||
pub compile_fails: u64, | ||
} | ||
|
||
impl Default for ServerStats { | ||
fn default() -> ServerStats { | ||
ServerStats { | ||
compile_requests: u64::default(), | ||
requests_unsupported_compiler: u64::default(), | ||
requests_not_compile: u64::default(), | ||
requests_not_cacheable: u64::default(), | ||
requests_executed: u64::default(), | ||
cache_errors: u64::default(), | ||
cache_hits: u64::default(), | ||
cache_misses: u64::default(), | ||
non_cacheable_compilations: u64::default(), | ||
forced_recaches: u64::default(), | ||
cache_read_errors: u64::default(), | ||
cache_write_errors: u64::default(), | ||
cache_writes: u64::default(), | ||
cache_write_duration: Duration::new(0, 0), | ||
cache_read_hit_duration: Duration::new(0, 0), | ||
cache_read_miss_duration: Duration::new(0, 0), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I avoided doing this because I was too lazy to spell all this out, and There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not think a second about |
||
compile_fails: u64::default(), | ||
} | ||
} | ||
} | ||
|
||
impl ServerStats { | ||
fn to_cache_statistics(&self) -> Vec<CacheStatistic> { | ||
macro_rules! set_stat { | ||
|
@@ -166,6 +191,20 @@ impl ServerStats { | |
}}; | ||
} | ||
|
||
macro_rules! set_duration_stat { | ||
($vec:ident, $dur:expr, $num:expr, $name:expr) => {{ | ||
let mut stat = CacheStatistic::new(); | ||
stat.set_name(String::from($name)); | ||
if $num > 0 { | ||
let duration = $dur / $num as u32; | ||
stat.set_str(format!("{}.{:03} s", duration.as_secs(), duration.subsec_nanos() / 1000_000)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really wish |
||
} else { | ||
stat.set_str("0.000 s".to_owned()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if there'd be any value in adding a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah. We can fix that later, it would make fixing that nicer certainly. |
||
} | ||
$vec.push(stat); | ||
}}; | ||
} | ||
|
||
let mut stats_vec = vec!(); | ||
set_stat!(stats_vec, self.compile_requests, "Compile requests"); | ||
set_stat!(stats_vec, self.requests_executed, "Compile requests executed"); | ||
|
@@ -180,16 +219,9 @@ impl ServerStats { | |
set_stat!(stats_vec, self.requests_not_cacheable, "Non-cacheable calls"); | ||
set_stat!(stats_vec, self.requests_not_compile, "Non-compilation calls"); | ||
set_stat!(stats_vec, self.requests_unsupported_compiler, "Unsupported compiler calls"); | ||
// Set this as a string so we can view subsecond values. | ||
let mut stat = CacheStatistic::new(); | ||
stat.set_name(String::from("Average cache write")); | ||
if self.cache_writes > 0 { | ||
let avg_write_duration = Duration::new(self.cache_write_duration_s, self.cache_write_duration_ns) / self.cache_writes; | ||
stat.set_str(format!("{}.{:03}s", avg_write_duration.as_secs(), avg_write_duration.subsec_nanos() / 1000)); | ||
} else { | ||
stat.set_str(String::from("0s")); | ||
} | ||
stats_vec.push(stat); | ||
set_duration_stat!(stats_vec, self.cache_write_duration, self.cache_writes, "Average cache write"); | ||
set_duration_stat!(stats_vec, self.cache_read_miss_duration, self.cache_misses, "Average cache read miss"); | ||
set_duration_stat!(stats_vec, self.cache_read_hit_duration, self.cache_hits, "Average cache read hit"); | ||
stats_vec | ||
} | ||
} | ||
|
@@ -450,8 +482,11 @@ impl<C : CommandCreatorSync + 'static> SccacheServer<C> { | |
Some((compiled, out)) => { | ||
match compiled { | ||
CompileResult::Error => self.stats.cache_errors += 1, | ||
CompileResult::CacheHit => self.stats.cache_hits += 1, | ||
CompileResult::CacheMiss(miss_type, future) => { | ||
CompileResult::CacheHit(duration) => { | ||
self.stats.cache_hits += 1; | ||
self.stats.cache_read_hit_duration += duration; | ||
}, | ||
CompileResult::CacheMiss(miss_type, duration, future) => { | ||
match miss_type { | ||
MissType::Normal => self.stats.cache_misses += 1, | ||
MissType::CacheReadError => self.stats.cache_read_errors += 1, | ||
|
@@ -460,6 +495,7 @@ impl<C : CommandCreatorSync + 'static> SccacheServer<C> { | |
self.stats.forced_recaches += 1; | ||
} | ||
} | ||
self.stats.cache_read_miss_duration += duration; | ||
self.await_cache_write(&mut event_loop, future) | ||
} | ||
CompileResult::NotCacheable => { | ||
|
@@ -727,10 +763,9 @@ impl<C : CommandCreatorSync + 'static> Handler for SccacheServer<C> { | |
} | ||
//TODO: save cache stats! | ||
Ok(info) => { | ||
debug!("[{}]: Cache write finished in {}.{:03}s", info.object_file, info.duration.as_secs(), info.duration.subsec_nanos() / 1000); | ||
debug!("[{}]: Cache write finished in {}.{:03}s", info.object_file, info.duration.as_secs(), info.duration.subsec_nanos() / 1000_000); | ||
self.stats.cache_writes += 1; | ||
self.stats.cache_write_duration_s += info.duration.as_secs(); | ||
self.stats.cache_write_duration_ns += info.duration.subsec_nanos(); | ||
self.stats.cache_write_duration += info.duration; | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason you're changing this to
u64
? You're just doing a conversion in theset_duration_stat
macro below anyway...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it to
u64
because all other counters areu64
and it looked odd. That's it.I thought you just use
u32
because of the division for the time calculation.Shall I revert that one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't say I have strong feelings either way. I was mostly just curious to make sure I wasn't missing something important about the patch.