diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2021-05-11 14:54:10 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-11 14:54:10 +1000 |
commit | 81f8585643faf42edab45f9e8604a0c1d9c7486a (patch) | |
tree | 5c54fa0ac866786cabf83be34f49b96038b88e25 /cli/lsp/performance.rs | |
parent | 2b8bac3c85d90de44c00677b015f69fd445c1489 (diff) |
feat(lsp): add internal debugging logging (#10438)
Ref: #10368
Diffstat (limited to 'cli/lsp/performance.rs')
-rw-r--r-- | cli/lsp/performance.rs | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/cli/lsp/performance.rs b/cli/lsp/performance.rs index 9a2ac24ab..87e29f3db 100644 --- a/cli/lsp/performance.rs +++ b/cli/lsp/performance.rs @@ -2,6 +2,8 @@ use deno_core::serde::Deserialize; use deno_core::serde::Serialize; +use deno_core::serde_json::json; +use log::debug; use std::cmp; use std::collections::HashMap; use std::collections::VecDeque; @@ -132,11 +134,29 @@ impl Performance { /// Marks the start of a measurement which returns a performance mark /// structure, which is then passed to `.measure()` to finalize the duration /// and add it to the internal buffer. - pub fn mark<S: AsRef<str>>(&self, name: S) -> PerformanceMark { + pub fn mark<S: AsRef<str>, V: Serialize>( + &self, + name: S, + maybe_args: Option<V>, + ) -> PerformanceMark { let name = name.as_ref(); let mut counts = self.counts.lock().unwrap(); let count = counts.entry(name.to_string()).or_insert(0); *count += 1; + let msg = if let Some(args) = maybe_args { + json!({ + "type": "mark", + "name": name, + "count": count, + "args": args, + }) + } else { + json!({ + "type": "mark", + "name": name, + }) + }; + debug!("{},", msg); PerformanceMark { name: name.to_string(), count: *count, @@ -149,6 +169,15 @@ impl Performance { /// measurement to the internal buffer. pub fn measure(&self, mark: PerformanceMark) -> Duration { let measure = PerformanceMeasure::from(mark); + debug!( + "{},", + json!({ + "type": "measure", + "name": measure.name, + "count": measure.count, + "duration": measure.duration.as_millis() as u32, + }) + ); let duration = measure.duration; let mut measures = self.measures.lock().unwrap(); measures.push_front(measure); @@ -171,9 +200,9 @@ mod tests { #[test] fn test_average() { let performance = Performance::default(); - let mark1 = performance.mark("a"); - let mark2 = performance.mark("a"); - let mark3 = performance.mark("b"); + let mark1 = performance.mark("a", None::<()>); + let mark2 = performance.mark("a", None::<()>); + let mark3 = performance.mark("b", None::<()>); performance.measure(mark2); performance.measure(mark1); performance.measure(mark3); @@ -187,8 +216,8 @@ mod tests { #[test] fn test_averages() { let performance = Performance::default(); - let mark1 = performance.mark("a"); - let mark2 = performance.mark("a"); + let mark1 = performance.mark("a", None::<()>); + let mark2 = performance.mark("a", None::<()>); performance.measure(mark2); performance.measure(mark1); let averages = performance.averages(); |