summaryrefslogtreecommitdiff
path: root/cli/lsp/performance.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/lsp/performance.rs')
-rw-r--r--cli/lsp/performance.rs41
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();