From 5a8a989b7815023f33a1e3183a55cc8999af5d98 Mon Sep 17 00:00:00 2001 From: Aaron O'Mullan Date: Sun, 10 Oct 2021 17:20:30 +0200 Subject: refactor(metrics): move to core (#12386) Avoids overhead of wrapping ops (and allocs when inspecting async-op futures) --- core/runtime.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'core/runtime.rs') diff --git a/core/runtime.rs b/core/runtime.rs index 1150746f3..1928ff31c 100644 --- a/core/runtime.rs +++ b/core/runtime.rs @@ -44,7 +44,8 @@ use std::sync::Once; use std::task::Context; use std::task::Poll; -type PendingOpFuture = Pin>>; +type PendingOpFuture = + Pin>>; pub enum Snapshot { Static(&'static [u8]), @@ -1477,7 +1478,9 @@ impl JsRuntime { match pending_r { Poll::Ready(None) => break, Poll::Pending => break, - Poll::Ready(Some((promise_id, resp))) => { + Poll::Ready(Some((promise_id, op_id, resp))) => { + let tracker = &mut state.op_state.borrow_mut().tracker; + tracker.track_async_completed(op_id); async_responses.push((promise_id, resp)); } }; @@ -1488,7 +1491,9 @@ impl JsRuntime { match unref_r { Poll::Ready(None) => break, Poll::Pending => break, - Poll::Ready(Some((promise_id, resp))) => { + Poll::Ready(Some((promise_id, op_id, resp))) => { + let tracker = &mut state.op_state.borrow_mut().tracker; + tracker.track_unref_completed(op_id); async_responses.push((promise_id, resp)); } }; @@ -1639,7 +1644,7 @@ pub mod tests { match test_state.mode { Mode::Async => { assert_eq!(control, 42); - let resp = (0, serialize_op_result(Ok(43), rc_op_state)); + let resp = (0, 1, serialize_op_result(Ok(43), rc_op_state)); Op::Async(Box::pin(futures::future::ready(resp))) } Mode::AsyncZeroCopy(has_buffer) => { @@ -1649,7 +1654,7 @@ pub mod tests { } let resp = serialize_op_result(Ok(43), rc_op_state); - Op::Async(Box::pin(futures::future::ready((0, resp)))) + Op::Async(Box::pin(futures::future::ready((0, 1, resp)))) } } } -- cgit v1.2.3