0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-31 09:14:20 -04:00
denoland-deno/js/metrics.ts
Ryan Dahl 2235dd795d
Revert json ops (#2814)
* Revert "port more ops to JSON (#2809)"

This reverts commit 137f33733d.

* Revert "port ops to JSON: compiler, errors, fetch, files (#2804)"

This reverts commit 79f82cf10e.

* Revert "Port rest of os ops to JSON (#2802)"

This reverts commit 5b2baa5c99.
2019-08-24 13:20:48 -07:00

49 lines
1.7 KiB
TypeScript

// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import { assert } from "./util";
import { sendSync, msg, flatbuffers } from "./dispatch_flatbuffers";
export interface Metrics {
opsDispatched: number;
opsCompleted: number;
bytesSentControl: number;
bytesSentData: number;
bytesReceived: number;
}
function req(): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
const builder = flatbuffers.createBuilder();
const inner = msg.Metrics.createMetrics(builder);
return [builder, msg.Any.Metrics, inner];
}
function res(baseRes: null | msg.Base): Metrics {
assert(baseRes !== null);
assert(msg.Any.MetricsRes === baseRes!.innerType());
const res = new msg.MetricsRes();
assert(baseRes!.inner(res) !== null);
return {
opsDispatched: res.opsDispatched().toFloat64(),
opsCompleted: res.opsCompleted().toFloat64(),
bytesSentControl: res.bytesSentControl().toFloat64(),
bytesSentData: res.bytesSentData().toFloat64(),
bytesReceived: res.bytesReceived().toFloat64()
};
}
/** Receive metrics from the privileged side of Deno.
*
* > console.table(Deno.metrics())
* ┌──────────────────┬────────┐
* │ (index) │ Values │
* ├──────────────────┼────────┤
* │ opsDispatched │ 9 │
* │ opsCompleted │ 9 │
* │ bytesSentControl │ 504 │
* │ bytesSentData │ 0 │
* │ bytesReceived │ 856 │
* └──────────────────┴────────┘
*/
export function metrics(): Metrics {
return res(sendSync(...req()));
}