-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(ext/node): perf_hooks.monitorEventLoopDelay() #26905
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
45dfac9
ELDHistogram API
littledivy 92ddddb
accessors
littledivy b72c29b
deps
littledivy 45cdc14
Add error
littledivy 2b64393
Add test
littledivy 9123d74
x
littledivy dedb047
rc
littledivy a7e527d
casing
littledivy 0b4cc09
update deno_core
littledivy 8d10eee
Merge branch 'main' into eld_histogram
littledivy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. | ||
|
||
use deno_core::op2; | ||
use deno_core::GarbageCollected; | ||
|
||
use std::cell::Cell; | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
pub enum PerfHooksError { | ||
#[error(transparent)] | ||
TokioEld(#[from] tokio_eld::Error), | ||
} | ||
|
||
pub struct EldHistogram { | ||
eld: tokio_eld::EldHistogram<u64>, | ||
started: Cell<bool>, | ||
} | ||
|
||
impl GarbageCollected for EldHistogram {} | ||
|
||
#[op2] | ||
impl EldHistogram { | ||
// Creates an interval EldHistogram object that samples and reports the event | ||
// loop delay over time. | ||
// | ||
// The delays will be reported in nanoseconds. | ||
#[constructor] | ||
#[cppgc] | ||
pub fn new(#[smi] resolution: u32) -> Result<EldHistogram, PerfHooksError> { | ||
Ok(EldHistogram { | ||
eld: tokio_eld::EldHistogram::new(resolution as usize)?, | ||
started: Cell::new(false), | ||
}) | ||
} | ||
|
||
// Disables the update interval timer. | ||
// | ||
// Returns true if the timer was stopped, false if it was already stopped. | ||
#[fast] | ||
fn enable(&self) -> bool { | ||
if self.started.get() { | ||
return false; | ||
} | ||
|
||
self.eld.start(); | ||
self.started.set(true); | ||
|
||
true | ||
} | ||
|
||
// Enables the update interval timer. | ||
// | ||
// Returns true if the timer was started, false if it was already started. | ||
#[fast] | ||
fn disable(&self) -> bool { | ||
if !self.started.get() { | ||
return false; | ||
} | ||
|
||
self.eld.stop(); | ||
self.started.set(false); | ||
|
||
true | ||
} | ||
|
||
// Returns the value at the given percentile. | ||
// | ||
// `percentile` ∈ (0, 100] | ||
#[fast] | ||
#[number] | ||
fn percentile(&self, percentile: f64) -> u64 { | ||
self.eld.value_at_percentile(percentile) | ||
} | ||
|
||
// Returns the value at the given percentile as a bigint. | ||
#[fast] | ||
#[bigint] | ||
fn percentile_big_int(&self, percentile: f64) -> u64 { | ||
self.eld.value_at_percentile(percentile) | ||
} | ||
|
||
// The number of samples recorded by the histogram. | ||
#[getter] | ||
#[number] | ||
fn count(&self) -> u64 { | ||
self.eld.len() | ||
} | ||
|
||
// The number of samples recorded by the histogram as a bigint. | ||
#[getter] | ||
#[bigint] | ||
fn count_big_int(&self) -> u64 { | ||
self.eld.len() | ||
} | ||
|
||
// The maximum recorded event loop delay. | ||
#[getter] | ||
#[number] | ||
fn max(&self) -> u64 { | ||
self.eld.max() | ||
} | ||
|
||
// The maximum recorded event loop delay as a bigint. | ||
#[getter] | ||
#[bigint] | ||
fn max_big_int(&self) -> u64 { | ||
self.eld.max() | ||
} | ||
|
||
// The mean of the recorded event loop delays. | ||
#[getter] | ||
fn mean(&self) -> f64 { | ||
self.eld.mean() | ||
} | ||
|
||
// The minimum recorded event loop delay. | ||
#[getter] | ||
#[number] | ||
fn min(&self) -> u64 { | ||
self.eld.min() | ||
} | ||
|
||
// The minimum recorded event loop delay as a bigint. | ||
#[getter] | ||
#[bigint] | ||
fn min_big_int(&self) -> u64 { | ||
self.eld.min() | ||
} | ||
|
||
// The standard deviation of the recorded event loop delays. | ||
#[getter] | ||
fn stddev(&self) -> f64 { | ||
self.eld.stdev() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was holding a mutable OpState borrow across the
make_cppgc_object
call which borrows again. It panics with latest deno_core version.