diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2023-12-12 08:18:10 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-12 08:18:10 +0100 |
commit | 49a6daaa8386f321d23f57fb5f3ae365abf82a80 (patch) | |
tree | 4b5cbcb9c225d18fabe567dc0dcca8a8b5bbdb8f /cli/lsp/performance.rs | |
parent | 8ea35de158834fc70453d37f23094ef327879e76 (diff) |
perf(lsp): collect counts and durations of all requests (#21540)
In addition to collecting details per-request metrics of the last 3000
request this commit adds aggregate metrics for all requests.
Diffstat (limited to 'cli/lsp/performance.rs')
-rw-r--r-- | cli/lsp/performance.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/cli/lsp/performance.rs b/cli/lsp/performance.rs index 610e18067..abcba8c4c 100644 --- a/cli/lsp/performance.rs +++ b/cli/lsp/performance.rs @@ -79,6 +79,8 @@ impl From<PerformanceMark> for PerformanceMeasure { #[derive(Debug)] pub struct Performance { counts: Mutex<HashMap<String, u32>>, + measurements_by_type: + Mutex<HashMap<String, (/* count */ u32, /* duration */ f64)>>, max_size: usize, measures: Mutex<VecDeque<PerformanceMeasure>>, } @@ -87,6 +89,7 @@ impl Default for Performance { fn default() -> Self { Self { counts: Default::default(), + measurements_by_type: Default::default(), max_size: 3_000, measures: Default::default(), } @@ -137,6 +140,14 @@ impl Performance { .collect() } + pub fn measurements_by_type(&self) -> Vec<(String, u32, f64)> { + let measurements_by_type = self.measurements_by_type.lock(); + measurements_by_type + .iter() + .map(|(name, (count, duration))| (name.to_string(), *count, *duration)) + .collect::<Vec<_>>() + } + 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() { @@ -164,6 +175,13 @@ impl Performance { let mut counts = self.counts.lock(); let count = counts.entry(name.to_string()).or_insert(0); *count += 1; + { + let mut measurements_by_type = self.measurements_by_type.lock(); + let measurement = measurements_by_type + .entry(name.to_string()) + .or_insert((0, 0.0)); + measurement.0 += 1; + } let msg = if let Some(args) = maybe_args { json!({ "type": "mark", @@ -218,6 +236,13 @@ impl Performance { }) ); let duration = measure.duration; + { + let mut measurements_by_type = self.measurements_by_type.lock(); + let measurement = measurements_by_type + .entry(measure.name.to_string()) + .or_insert((0, 0.0)); + measurement.1 += duration.as_micros() as f64 / 1000.0; + } let mut measures = self.measures.lock(); measures.push_front(measure); while measures.len() > self.max_size { |