diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2021-04-20 07:10:43 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-20 07:10:43 +1000 |
commit | 65f7a021f092f2c475969a6f6762ab5e35d65123 (patch) | |
tree | 008dec74a2d1ac88a59db15e0e8a78ed02ae6011 /cli/lsp/performance.rs | |
parent | d6233100bd6a5c5b2a1c541f580cc47053f6f90d (diff) |
feat(lsp): improve diagnostic status page (#10253)
Diffstat (limited to 'cli/lsp/performance.rs')
-rw-r--r-- | cli/lsp/performance.rs | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/cli/lsp/performance.rs b/cli/lsp/performance.rs index 537583141..9a2ac24ab 100644 --- a/cli/lsp/performance.rs +++ b/cli/lsp/performance.rs @@ -2,14 +2,16 @@ use deno_core::serde::Deserialize; use deno_core::serde::Serialize; +use std::cmp; use std::collections::HashMap; use std::collections::VecDeque; +use std::fmt; use std::sync::Arc; use std::sync::Mutex; use std::time::Duration; use std::time::Instant; -#[derive(Debug, Deserialize, Serialize)] +#[derive(Debug, Deserialize, Serialize, PartialEq, Eq)] #[serde(rename_all = "camelCase")] pub struct PerformanceAverage { pub name: String, @@ -17,6 +19,18 @@ pub struct PerformanceAverage { pub average_duration: u32, } +impl PartialOrd for PerformanceAverage { + fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> { + Some(self.cmp(other)) + } +} + +impl Ord for PerformanceAverage { + fn cmp(&self, other: &Self) -> cmp::Ordering { + self.name.cmp(&other.name) + } +} + /// A structure which serves as a start of a measurement span. #[derive(Debug)] pub struct PerformanceMark { @@ -33,6 +47,12 @@ pub struct PerformanceMeasure { pub duration: Duration, } +impl fmt::Display for PerformanceMeasure { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "{} ({}ms)", self.name, self.duration.as_millis()) + } +} + impl From<PerformanceMark> for PerformanceMeasure { fn from(value: PerformanceMark) -> Self { Self { @@ -131,12 +151,17 @@ impl Performance { let measure = PerformanceMeasure::from(mark); let duration = measure.duration; let mut measures = self.measures.lock().unwrap(); - measures.push_back(measure); + measures.push_front(measure); while measures.len() > self.max_size { - measures.pop_front(); + measures.pop_back(); } duration } + + pub fn to_vec(&self) -> Vec<PerformanceMeasure> { + let measures = self.measures.lock().unwrap(); + measures.iter().cloned().collect() + } } #[cfg(test)] |