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;
|
|
|
|
use crate::fs as deno_fs;
|
|
|
|
use crate::ops::json_op;
|
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-01-27 21:12:25 -05:00
|
|
|
use deno_core::*;
|
|
|
|
use std::env;
|
|
|
|
|
|
|
|
/// BUILD_OS and BUILD_ARCH match the values in Deno.build. See js/build.ts.
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
static BUILD_OS: &str = "mac";
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
static BUILD_OS: &str = "linux";
|
|
|
|
#[cfg(target_os = "windows")]
|
|
|
|
static BUILD_OS: &str = "win";
|
|
|
|
#[cfg(target_arch = "x86_64")]
|
|
|
|
static BUILD_ARCH: &str = "x64";
|
|
|
|
|
2020-02-08 14:34:31 -05:00
|
|
|
pub fn init(i: &mut Isolate, s: &State) {
|
2020-01-27 21:12:25 -05:00
|
|
|
i.register_op("start", s.core_op(json_op(s.stateful_op(op_start))));
|
2020-02-11 04:04:59 -05:00
|
|
|
i.register_op("metrics", s.core_op(json_op(s.stateful_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>,
|
|
|
|
) -> Result<JsonOp, ErrBox> {
|
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!({
|
|
|
|
"cwd": deno_fs::normalize_path(&env::current_dir().unwrap()),
|
|
|
|
"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(),
|
|
|
|
"os": BUILD_OS,
|
|
|
|
"arch": BUILD_ARCH,
|
|
|
|
})))
|
|
|
|
}
|
2020-02-11 04:04:59 -05:00
|
|
|
|
|
|
|
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!({
|
2020-02-11 11:23:40 -05:00
|
|
|
"opsDispatched": m.ops_dispatched,
|
|
|
|
"opsCompleted": m.ops_completed,
|
|
|
|
"bytesSentControl": m.bytes_sent_control,
|
|
|
|
"bytesSentData": m.bytes_sent_data,
|
|
|
|
"bytesReceived": m.bytes_received
|
2020-02-11 04:04:59 -05:00
|
|
|
})))
|
|
|
|
}
|