Skip to content
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 4 commits into from
Nov 10, 2023

Conversation

mmastrac
Copy link
Contributor

@mmastrac mmastrac commented Nov 9, 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

Blocked on denoland/deno_core#320

@mmastrac mmastrac changed the title WIP: strace mode for ops tool(cli): strace mode for ops (undocumented) [WIP] Nov 9, 2023
@mmastrac mmastrac changed the title tool(cli): strace mode for ops (undocumented) [WIP] perf(cli): strace mode for ops (undocumented) [WIP] Nov 9, 2023
mmastrac added a commit to denoland/deno_core that referenced this pull request Nov 9, 2023
@mmastrac mmastrac changed the title perf(cli): strace mode for ops (undocumented) [WIP] perf(cli): strace mode for ops (undocumented) Nov 9, 2023
Copy link
Member

@bartlomieju bartlomieju left a 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

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);
}
Copy link
Member

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?

@mmastrac mmastrac merged commit 68607b5 into denoland:main Nov 10, 2023
13 checks passed
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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants