summaryrefslogtreecommitdiff
path: root/js/metrics.ts
diff options
context:
space:
mode:
Diffstat (limited to 'js/metrics.ts')
-rw-r--r--js/metrics.ts27
1 files changed, 24 insertions, 3 deletions
diff --git a/js/metrics.ts b/js/metrics.ts
index 48e3102e5..e93e9528c 100644
--- a/js/metrics.ts
+++ b/js/metrics.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import * as dispatch from "./dispatch";
-import { sendSync } from "./dispatch_json";
+import { assert } from "./util";
+import { sendSync, msg, flatbuffers } from "./dispatch_flatbuffers";
export interface Metrics {
opsDispatched: number;
@@ -10,6 +10,27 @@ export interface Metrics {
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())
@@ -24,5 +45,5 @@ export interface Metrics {
* └──────────────────┴────────┘
*/
export function metrics(): Metrics {
- return sendSync(dispatch.OP_METRICS);
+ return res(sendSync(...req()));
}