summaryrefslogtreecommitdiff
path: root/cli/lsp/performance.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/lsp/performance.rs')
-rw-r--r--cli/lsp/performance.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/cli/lsp/performance.rs b/cli/lsp/performance.rs
index ffb6ed217..610e18067 100644
--- a/cli/lsp/performance.rs
+++ b/cli/lsp/performance.rs
@@ -51,7 +51,12 @@ pub struct PerformanceMeasure {
impl fmt::Display for PerformanceMeasure {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write!(f, "{} ({}ms)", self.name, self.duration.as_millis())
+ write!(
+ f,
+ "{} ({}ms)",
+ self.name,
+ self.duration.as_micros() as f64 / 1000.0
+ )
}
}
@@ -132,6 +137,24 @@ impl Performance {
.collect()
}
+ pub fn averages_as_f64(&self) -> Vec<(String, u32, f64)> {
+ let mut averages: HashMap<String, Vec<Duration>> = HashMap::new();
+ for measure in self.measures.lock().iter() {
+ averages
+ .entry(measure.name.clone())
+ .or_default()
+ .push(measure.duration);
+ }
+ averages
+ .into_iter()
+ .map(|(k, d)| {
+ let count = d.len() as u32;
+ let a = d.into_iter().sum::<Duration>() / count;
+ (k, count, a.as_micros() as f64 / 1000.0)
+ })
+ .collect()
+ }
+
fn mark_inner<S: AsRef<str>, V: Serialize>(
&self,
name: S,