diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/js/30_metrics.js | 18 | ||||
-rw-r--r-- | runtime/js/40_testing.js | 2 | ||||
-rw-r--r-- | runtime/js/90_deno_ns.js | 3 | ||||
-rw-r--r-- | runtime/lib.rs | 1 | ||||
-rw-r--r-- | runtime/metrics.rs | 210 | ||||
-rw-r--r-- | runtime/ops/mod.rs | 5 | ||||
-rw-r--r-- | runtime/web_worker.rs | 3 | ||||
-rw-r--r-- | runtime/worker.rs | 3 |
8 files changed, 5 insertions, 240 deletions
diff --git a/runtime/js/30_metrics.js b/runtime/js/30_metrics.js deleted file mode 100644 index ecc1cfc64..000000000 --- a/runtime/js/30_metrics.js +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -"use strict"; - -((window) => { - const core = window.Deno.core; - - function metrics() { - const { combined, ops } = core.opSync("op_metrics"); - if (ops) { - combined.ops = ops; - } - return combined; - } - - window.__bootstrap.metrics = { - metrics, - }; -})(this); diff --git a/runtime/js/40_testing.js b/runtime/js/40_testing.js index f4f5373c6..92181cae1 100644 --- a/runtime/js/40_testing.js +++ b/runtime/js/40_testing.js @@ -6,7 +6,7 @@ const { parsePermissions } = window.__bootstrap.worker; const { setExitHandler } = window.__bootstrap.os; const { Console, inspectArgs } = window.__bootstrap.console; - const { metrics } = window.__bootstrap.metrics; + const { metrics } = core; const { assert } = window.__bootstrap.util; const { ArrayPrototypeFilter, diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js index 28c7c48f5..897705f84 100644 --- a/runtime/js/90_deno_ns.js +++ b/runtime/js/90_deno_ns.js @@ -2,10 +2,11 @@ "use strict"; ((window) => { + const core = window.Deno.core; const __bootstrap = window.__bootstrap; __bootstrap.denoNs = { + metrics: core.metrics, test: __bootstrap.testing.test, - metrics: __bootstrap.metrics.metrics, Process: __bootstrap.process.Process, run: __bootstrap.process.run, isatty: __bootstrap.tty.isatty, diff --git a/runtime/lib.rs b/runtime/lib.rs index e89e4a27b..fb6159dd9 100644 --- a/runtime/lib.rs +++ b/runtime/lib.rs @@ -21,7 +21,6 @@ pub mod errors; pub mod fs_util; pub mod inspector_server; pub mod js; -pub mod metrics; pub mod ops; pub mod permissions; pub mod tokio_util; diff --git a/runtime/metrics.rs b/runtime/metrics.rs deleted file mode 100644 index bdcf2b84e..000000000 --- a/runtime/metrics.rs +++ /dev/null @@ -1,210 +0,0 @@ -// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license. -use crate::ops::UnstableChecker; -use deno_core::error::AnyError; -use deno_core::op_sync; -use deno_core::serde::Serialize; -use deno_core::serde_json::json; -use deno_core::serde_json::Value; -use deno_core::Extension; -use deno_core::OpState; - -pub fn init() -> Extension { - Extension::builder() - .ops(vec![("op_metrics", op_sync(op_metrics))]) - .state(|state| { - state.put(RuntimeMetrics::default()); - Ok(()) - }) - .middleware(metrics_op) - .build() -} - -#[derive(serde::Serialize)] -struct MetricsReturn { - combined: OpMetrics, - ops: Value, -} - -fn op_metrics( - state: &mut OpState, - _: (), - _: (), -) -> Result<MetricsReturn, AnyError> { - let m = state.borrow::<RuntimeMetrics>(); - let combined = m.combined_metrics(); - let unstable_checker = state.borrow::<UnstableChecker>(); - let maybe_ops = if unstable_checker.unstable { - Some(&m.ops) - } else { - None - }; - Ok(MetricsReturn { - combined, - ops: json!(maybe_ops), - }) -} -#[derive(Default, Debug)] -pub struct RuntimeMetrics { - pub ops: HashMap<&'static str, OpMetrics>, -} - -impl RuntimeMetrics { - pub fn combined_metrics(&self) -> OpMetrics { - let mut total = OpMetrics::default(); - - for metrics in self.ops.values() { - total.ops_dispatched += metrics.ops_dispatched; - total.ops_dispatched_sync += metrics.ops_dispatched_sync; - total.ops_dispatched_async += metrics.ops_dispatched_async; - total.ops_dispatched_async_unref += metrics.ops_dispatched_async_unref; - total.ops_completed += metrics.ops_completed; - total.ops_completed_sync += metrics.ops_completed_sync; - total.ops_completed_async += metrics.ops_completed_async; - total.ops_completed_async_unref += metrics.ops_completed_async_unref; - total.bytes_sent_control += metrics.bytes_sent_control; - total.bytes_sent_data += metrics.bytes_sent_data; - total.bytes_received += metrics.bytes_received; - } - - total - } -} - -#[derive(Default, Debug, Serialize)] -#[serde(rename_all = "camelCase")] -pub struct OpMetrics { - pub ops_dispatched: u64, - pub ops_dispatched_sync: u64, - pub ops_dispatched_async: u64, - pub ops_dispatched_async_unref: u64, - pub ops_completed: u64, - pub ops_completed_sync: u64, - pub ops_completed_async: u64, - pub ops_completed_async_unref: u64, - pub bytes_sent_control: u64, - pub bytes_sent_data: u64, - pub bytes_received: u64, -} - -impl OpMetrics { - fn op_dispatched( - &mut self, - bytes_sent_control: usize, - bytes_sent_data: usize, - ) { - self.ops_dispatched += 1; - self.bytes_sent_control += bytes_sent_control as u64; - self.bytes_sent_data += bytes_sent_data as u64; - } - - fn op_completed(&mut self, bytes_received: usize) { - self.ops_completed += 1; - self.bytes_received += bytes_received as u64; - } - - pub fn op_sync( - &mut self, - bytes_sent_control: usize, - bytes_sent_data: usize, - bytes_received: usize, - ) { - self.ops_dispatched_sync += 1; - self.op_dispatched(bytes_sent_control, bytes_sent_data); - self.ops_completed_sync += 1; - self.op_completed(bytes_received); - } - - pub fn op_dispatched_async( - &mut self, - bytes_sent_control: usize, - bytes_sent_data: usize, - ) { - self.ops_dispatched_async += 1; - self.op_dispatched(bytes_sent_control, bytes_sent_data) - } - - pub fn op_dispatched_async_unref( - &mut self, - bytes_sent_control: usize, - bytes_sent_data: usize, - ) { - self.ops_dispatched_async_unref += 1; - self.op_dispatched(bytes_sent_control, bytes_sent_data) - } - - pub fn op_completed_async(&mut self, bytes_received: usize) { - self.ops_completed_async += 1; - self.op_completed(bytes_received); - } - - pub fn op_completed_async_unref(&mut self, bytes_received: usize) { - self.ops_completed_async_unref += 1; - self.op_completed(bytes_received); - } -} - -use deno_core::Op; -use deno_core::OpFn; -use std::collections::HashMap; - -pub fn metrics_op(name: &'static str, op_fn: Box<OpFn>) -> Box<OpFn> { - Box::new(move |op_state, payload| -> Op { - // TODOs: - // * The 'bytes' metrics seem pretty useless, especially now that the - // distinction between 'control' and 'data' buffers has become blurry. - // * Tracking completion of async ops currently makes us put the boxed - // future into _another_ box. Keeping some counters may not be expensive - // in itself, but adding a heap allocation for every metric seems bad. - - // TODO: remove this, doesn't make a ton of sense - let bytes_sent_control = 0; - let bytes_sent_data = 0; - - let op = (op_fn)(op_state.clone(), payload); - - let op_state_ = op_state.clone(); - let mut s = op_state.borrow_mut(); - let runtime_metrics = s.borrow_mut::<RuntimeMetrics>(); - - let metrics = if let Some(metrics) = runtime_metrics.ops.get_mut(name) { - metrics - } else { - runtime_metrics.ops.insert(name, OpMetrics::default()); - runtime_metrics.ops.get_mut(name).unwrap() - }; - - use deno_core::futures::future::FutureExt; - - match op { - Op::Sync(result) => { - metrics.op_sync(bytes_sent_control, bytes_sent_data, 0); - Op::Sync(result) - } - Op::Async(fut) => { - metrics.op_dispatched_async(bytes_sent_control, bytes_sent_data); - let fut = fut - .inspect(move |_resp| { - let mut s = op_state_.borrow_mut(); - let runtime_metrics = s.borrow_mut::<RuntimeMetrics>(); - let metrics = runtime_metrics.ops.get_mut(name).unwrap(); - metrics.op_completed_async(0); - }) - .boxed_local(); - Op::Async(fut) - } - Op::AsyncUnref(fut) => { - metrics.op_dispatched_async_unref(bytes_sent_control, bytes_sent_data); - let fut = fut - .inspect(move |_resp| { - let mut s = op_state_.borrow_mut(); - let runtime_metrics = s.borrow_mut::<RuntimeMetrics>(); - let metrics = runtime_metrics.ops.get_mut(name).unwrap(); - metrics.op_completed_async_unref(0); - }) - .boxed_local(); - Op::AsyncUnref(fut) - } - other => other, - } - }) -} diff --git a/runtime/ops/mod.rs b/runtime/ops/mod.rs index ee2bc0a1e..fa547f2ed 100644 --- a/runtime/ops/mod.rs +++ b/runtime/ops/mod.rs @@ -14,7 +14,6 @@ mod utils; pub mod web_worker; pub mod worker_host; -use crate::metrics::metrics_op; use deno_core::error::AnyError; use deno_core::op_async; use deno_core::op_sync; @@ -37,7 +36,7 @@ pub fn reg_async<F, A, B, R, RV>( R: Future<Output = Result<RV, AnyError>> + 'static, RV: Serialize + 'static, { - rt.register_op(name, metrics_op(name, op_async(op_fn))); + rt.register_op(name, op_async(op_fn)); } pub fn reg_sync<F, A, B, R>(rt: &mut JsRuntime, name: &'static str, op_fn: F) @@ -47,7 +46,7 @@ where B: DeserializeOwned, R: Serialize + 'static, { - rt.register_op(name, metrics_op(name, op_sync(op_fn))); + rt.register_op(name, op_sync(op_fn)); } /// `UnstableChecker` is a struct so it can be placed inside `GothamState`; diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index e269110de..31fc30fbc 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -2,7 +2,6 @@ use crate::colors; use crate::inspector_server::InspectorServer; use crate::js; -use crate::metrics; use crate::ops; use crate::permissions::Permissions; use crate::tokio_util::create_basic_runtime; @@ -337,8 +336,6 @@ impl WebWorker { deno_timers::init::<Permissions>(), // ffi deno_ffi::init::<Permissions>(unstable), - // Metrics - metrics::init(), // Permissions ext (worker specific state) perm_ext, ]; diff --git a/runtime/worker.rs b/runtime/worker.rs index e1b9599a3..af4095b7d 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -2,7 +2,6 @@ use crate::inspector_server::InspectorServer; use crate::js; -use crate::metrics; use crate::ops; use crate::permissions::Permissions; use crate::BootstrapOptions; @@ -122,8 +121,6 @@ impl MainWorker { deno_timers::init::<Permissions>(), // ffi deno_ffi::init::<Permissions>(unstable), - // Metrics - metrics::init(), // Runtime ops ops::runtime::init(main_module.clone()), ops::worker_host::init(options.create_web_worker_cb.clone()), |