summaryrefslogtreecommitdiff
path: root/cli/lsp/performance.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-12-11 17:33:56 +0100
committerGitHub <noreply@github.com>2023-12-11 17:33:56 +0100
commit88566cee72b4762e0742fdde3f2c56b8a4d0bf03 (patch)
tree954112b236bb57b9e0a9303e301c56695a2fd1d9 /cli/lsp/performance.rs
parent98121de5be6f948740c5869095381d6e7a18b9ea (diff)
perf(lsp): instrument all ops with performance marks (#21536)
Adds performance measurements for all ops used by the LSP. Also changes output of "Language server status" page to include more precise information. Current suspicion is that computing "script version" takes a long time for some users.
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,