-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
perf(cli): strace mode for ops (undocumented) #21131
Merged
Merged
Conversation
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
0c0fb1d
to
9b50853
Compare
mmastrac
added a commit
to denoland/deno_core
that referenced
this pull request
Nov 9, 2023
bartlomieju
approved these changes
Nov 10, 2023
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.
LGTM with a nit
runtime/worker.rs
Outdated
Comment on lines
334
to
387
let mut op_summary_metrics = None; | ||
let mut op_metrics_factory_fn: Option<OpMetricsFactoryFn> = None; | ||
let now = Instant::now(); | ||
let max_len: Rc<std::cell::Cell<usize>> = Default::default(); | ||
if let Some(patterns) = options.strace_ops { | ||
/// Match an op name against a list of patterns | ||
fn matches_pattern(patterns: &[String], name: &str) -> bool { | ||
let mut found_match = false; | ||
let mut found_nomatch = false; | ||
for pattern in patterns.iter() { | ||
if let Some(pattern) = pattern.strip_prefix('-') { | ||
if name.contains(pattern) { | ||
return false; | ||
} | ||
} else if name.contains(pattern.as_str()) { | ||
found_match = true; | ||
} else { | ||
found_nomatch = true; | ||
} | ||
} | ||
|
||
found_match || !found_nomatch | ||
} | ||
|
||
op_metrics_factory_fn = Some(Box::new(move |_, _, decl| { | ||
// If we don't match a requested pattern, or we match a negative pattern, bail | ||
if !matches_pattern(&patterns, decl.name) { | ||
return None; | ||
} | ||
|
||
max_len.set(max_len.get().max(decl.name.len())); | ||
let max_len = max_len.clone(); | ||
Some(Rc::new( | ||
move |op: &deno_core::_ops::OpCtx, event, source| { | ||
eprintln!( | ||
"[{: >10.3}] {name:max_len$}: {event:?} {source:?}", | ||
now.elapsed().as_secs_f64(), | ||
name = op.decl().name, | ||
max_len = max_len.get() | ||
); | ||
}, | ||
)) | ||
})); | ||
} | ||
|
||
if options.bootstrap.enable_op_summary_metrics { | ||
let summary = Rc::new(OpMetricsSummaryTracker::default()); | ||
let summary_metrics = summary.clone().op_metrics_factory_fn(|_| true); | ||
op_metrics_factory_fn = Some(match op_metrics_factory_fn { | ||
Some(f) => merge_op_metrics(f, summary_metrics), | ||
None => summary_metrics, | ||
}); | ||
op_summary_metrics = Some(summary); | ||
} |
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.
Nit: could you move this set up code to a helper function and only assign the result to relevant option field?
kt3k
pushed a commit
that referenced
this pull request
Nov 17, 2023
Example usage: ``` # Trace every op except op_*tick* cargo run -- run --unstable -A --strace-ops=-tick '/Users/matt/Documents/github/deno/deno/ext/websocket/autobahn/autobahn_server.js # Trace any op matching op_*http* cargo run -- run --unstable -A --strace-ops=http ... ``` Example output: ``` [ 11.478] op_ws_get_buffer : Dispatched Slow [ 11.478] op_ws_get_buffer : Completed Slow [ 11.478] op_ws_send_binary : Dispatched Fast [ 11.478] op_ws_send_binary : Completed Fast [ 11.478] op_ws_next_event : Dispatched Async [ 11.478] op_try_close : Dispatched Fast [ 11.478] op_try_close : Completed Fast [ 11.478] op_timer_handle : Dispatched Fast [ 11.478] op_timer_handle : Completed Fast [ 11.478] op_sleep : Dispatched Asyn ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Example usage:
Example output:
Blocked on denoland/deno_core#320