feat(lsp): improve diagnostic status page (#10253)

This commit is contained in:
Kitson Kelly 2021-04-20 07:10:43 +10:00 committed by GitHub
parent d6233100bd
commit 65f7a021f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 83 additions and 16 deletions

View file

@ -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)]