diff options
Diffstat (limited to 'cli/ops/runtime.rs')
| -rw-r--r-- | cli/ops/runtime.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/cli/ops/runtime.rs b/cli/ops/runtime.rs index a962f4e83..7773e461c 100644 --- a/cli/ops/runtime.rs +++ b/cli/ops/runtime.rs @@ -8,6 +8,7 @@ use crate::version; use crate::DenoSubcommand; use deno_core::*; use std::env; +use std::sync::atomic::Ordering; /// BUILD_OS and BUILD_ARCH match the values in Deno.build. See js/build.ts. #[cfg(target_os = "macos")] @@ -21,6 +22,7 @@ static BUILD_ARCH: &str = "x64"; pub fn init(i: &mut Isolate, s: &State) { i.register_op("start", s.core_op(json_op(s.stateful_op(op_start)))); + i.register_op("metrics", s.core_op(json_op(s.stateful_op(op_metrics)))); } fn op_start( @@ -47,3 +49,20 @@ fn op_start( "arch": BUILD_ARCH, }))) } + +fn op_metrics( + state: &State, + _args: Value, + _zero_copy: Option<ZeroCopyBuf>, +) -> Result<JsonOp, ErrBox> { + let state = state.borrow(); + let m = &state.metrics; + + Ok(JsonOp::Sync(json!({ + "opsDispatched": m.ops_dispatched.load(Ordering::SeqCst) as u64, + "opsCompleted": m.ops_completed.load(Ordering::SeqCst) as u64, + "bytesSentControl": m.bytes_sent_control.load(Ordering::SeqCst) as u64, + "bytesSentData": m.bytes_sent_data.load(Ordering::SeqCst) as u64, + "bytesReceived": m.bytes_received.load(Ordering::SeqCst) as u64 + }))) +} |
