summaryrefslogtreecommitdiff
path: root/js/trace.ts
diff options
context:
space:
mode:
Diffstat (limited to 'js/trace.ts')
-rw-r--r--js/trace.ts80
1 files changed, 0 insertions, 80 deletions
diff --git a/js/trace.ts b/js/trace.ts
deleted file mode 100644
index 104d048de..000000000
--- a/js/trace.ts
+++ /dev/null
@@ -1,80 +0,0 @@
-// Copyright 2018 the Deno authors. All rights reserved. MIT license.
-import * as msg from "gen/msg_generated";
-
-export interface TraceInfo {
- sync: boolean; // is synchronous call
- name: string; // name of operation
-}
-
-interface TraceStackNode {
- list: TraceInfo[];
- prev: TraceStackNode | null;
-}
-
-let current: TraceStackNode | null = null;
-
-// Push a new list to trace stack
-function pushStack(): void {
- if (current === null) {
- current = { list: [], prev: null };
- } else {
- const newStack = { list: [], prev: current };
- current = newStack;
- }
-}
-
-// Pop from trace stack and (if possible) concat to parent trace stack node
-function popStack(): TraceInfo[] {
- if (current === null) {
- throw new Error("trace list stack should not be empty");
- }
- const resultList = current!.list;
- if (!!current!.prev) {
- const prev = current!.prev!;
- // concat inner results to outer stack
- prev.list = prev.list.concat(resultList);
- current = prev;
- } else {
- current = null;
- }
- return resultList;
-}
-
-// Push to trace stack if we are tracing
-// @internal
-export function maybePushTrace(op: msg.Any, sync: boolean): void {
- if (current === null) {
- return; // no trace requested
- }
- // Freeze the object, avoid tampering
- current!.list.push(
- Object.freeze({
- sync,
- name: msg.Any[op] // convert to enum names
- })
- );
-}
-
-/** Trace privileged operations executed inside a given function or promise.
- *
- * _Notice:_ To capture every operation in asynchronous `deno.*` calls,
- * you might want to put them in functions instead of directly invoking.
- *
- * import { trace, mkdir } from "deno";
- *
- * const ops = await trace(async () => {
- * await mkdir("my_dir");
- * });
- */
-export async function trace(
- // tslint:disable-next-line:no-any
- fnOrPromise: Function | Promise<any>
-): Promise<TraceInfo[]> {
- pushStack();
- if (typeof fnOrPromise === "function") {
- await fnOrPromise();
- } else {
- await fnOrPromise;
- }
- return popStack();
-}