2020-01-27 21:12:25 -05:00
|
|
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
|
|
use super::dispatch_json::{JsonOp, Value};
|
|
|
|
use crate::colors;
|
2020-02-23 14:51:29 -05:00
|
|
|
use crate::op_error::OpError;
|
2020-02-08 14:34:31 -05:00
|
|
|
use crate::state::State;
|
2020-01-27 21:12:25 -05:00
|
|
|
use crate::version;
|
2020-02-04 14:24:33 -05:00
|
|
|
use crate::DenoSubcommand;
|
2020-04-23 05:51:07 -04:00
|
|
|
use deno_core::CoreIsolate;
|
|
|
|
use deno_core::ZeroCopyBuf;
|
2020-01-27 21:12:25 -05:00
|
|
|
use std::env;
|
|
|
|
|
2020-04-23 05:51:07 -04:00
|
|
|
pub fn init(i: &mut CoreIsolate, s: &State) {
|
2020-02-25 09:14:27 -05:00
|
|
|
i.register_op("op_start", s.stateful_json_op(op_start));
|
|
|
|
i.register_op("op_metrics", s.stateful_json_op(op_metrics));
|
2020-01-27 21:12:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn op_start(
|
2020-02-08 14:34:31 -05:00
|
|
|
state: &State,
|
2020-01-27 21:12:25 -05:00
|
|
|
_args: Value,
|
|
|
|
_zero_copy: Option<ZeroCopyBuf>,
|
2020-02-23 14:51:29 -05:00
|
|
|
) -> Result<JsonOp, OpError> {
|
2020-02-08 14:34:31 -05:00
|
|
|
let state = state.borrow();
|
2020-01-27 21:12:25 -05:00
|
|
|
let gs = &state.global_state;
|
2020-02-04 14:24:33 -05:00
|
|
|
|
2020-01-27 21:12:25 -05:00
|
|
|
Ok(JsonOp::Sync(json!({
|
2020-02-26 16:11:52 -05:00
|
|
|
// TODO(bartlomieju): `cwd` field is not used in JS, remove?
|
|
|
|
"cwd": &env::current_dir().unwrap(),
|
2020-01-27 21:12:25 -05:00
|
|
|
"pid": std::process::id(),
|
2020-02-04 14:24:33 -05:00
|
|
|
"args": gs.flags.argv.clone(),
|
|
|
|
"repl": gs.flags.subcommand == DenoSubcommand::Repl,
|
|
|
|
"location": state.main_module.to_string(),
|
2020-01-27 21:12:25 -05:00
|
|
|
"debugFlag": gs.flags.log_level.map_or(false, |l| l == log::Level::Debug),
|
|
|
|
"versionFlag": gs.flags.version,
|
|
|
|
"v8Version": version::v8(),
|
|
|
|
"denoVersion": version::DENO,
|
|
|
|
"tsVersion": version::TYPESCRIPT,
|
|
|
|
"noColor": !colors::use_color(),
|
2020-04-28 12:35:23 -04:00
|
|
|
"target": env!("TARGET"),
|
2020-01-27 21:12:25 -05:00
|
|
|
})))
|
|
|
|
}
|
2020-02-11 04:04:59 -05:00
|
|
|
|
|
|
|
fn op_metrics(
|
|
|
|
state: &State,
|
|
|
|
_args: Value,
|
|
|
|
_zero_copy: Option<ZeroCopyBuf>,
|
2020-02-23 14:51:29 -05:00
|
|
|
) -> Result<JsonOp, OpError> {
|
2020-02-11 04:04:59 -05:00
|
|
|
let state = state.borrow();
|
|
|
|
let m = &state.metrics;
|
|
|
|
|
|
|
|
Ok(JsonOp::Sync(json!({
|
2020-02-11 11:23:40 -05:00
|
|
|
"opsDispatched": m.ops_dispatched,
|
2020-03-02 13:13:36 -05:00
|
|
|
"opsDispatchedSync": m.ops_dispatched_sync,
|
|
|
|
"opsDispatchedAsync": m.ops_dispatched_async,
|
|
|
|
"opsDispatchedAsyncUnref": m.ops_dispatched_async_unref,
|
2020-02-11 11:23:40 -05:00
|
|
|
"opsCompleted": m.ops_completed,
|
2020-03-02 13:13:36 -05:00
|
|
|
"opsCompletedSync": m.ops_completed_sync,
|
|
|
|
"opsCompletedAsync": m.ops_completed_async,
|
|
|
|
"opsCompletedAsyncUnref": m.ops_completed_async_unref,
|
2020-02-11 11:23:40 -05:00
|
|
|
"bytesSentControl": m.bytes_sent_control,
|
|
|
|
"bytesSentData": m.bytes_sent_data,
|
|
|
|
"bytesReceived": m.bytes_received
|
2020-02-11 04:04:59 -05:00
|
|
|
})))
|
|
|
|
}
|