Skip to content

Commit

Permalink
remove hooks capture
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardoventurini committed May 16, 2023
1 parent 6a213de commit 37ab823
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 138 deletions.
51 changes: 0 additions & 51 deletions lib/als.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs from 'fs';
import util from 'util';
import asyncHooks from 'async_hooks';
import { AsyncLocalStorage } from 'node:async_hooks';
import crypto from 'crypto';

Expand All @@ -23,58 +22,8 @@ export const debug = label => (...args) => {
fs.writeFileSync(1, `${util.format(label, ...args)}\n`, { flag: 'a' });
};

const getInfo = () => MontiAsyncStorage.getStore()?.get('info');

const captureEndTime = (asyncId) => {
const info = getInfo();

if (!info) return;

const trace = info._traces.get(asyncId);

if (!trace) return;

trace.endTime = Date.now();
};

export const ASYNC_RESOURCE_TYPE = {
TICKOBJECT: 'TickObject',
ZLIB: 'ZLIB',
PROMISE: 'PROMISE',
};

const hook = asyncHooks.createHook({
init (asyncId, type, triggerAsyncId) {
const info = getInfo();

if (!info) return;
if (type !== ASYNC_RESOURCE_TYPE.PROMISE) return;

info._traces = info._traces || new Map();

info._traces.set(asyncId, {
asyncId,
type,
startTime: Date.now(),
endTime: null,
// frames: stackTrace(2)
});

const trigger = info._traces.get(triggerAsyncId);

if (trigger) {
trigger.children = trigger.children || [];
trigger.children.push(asyncId);
}
},

after: captureEndTime,
promiseResolve: captureEndTime,
});

hook.enable();

process.once('beforeExit', function () {
hook.disable();
});

81 changes: 0 additions & 81 deletions lib/collect.js

This file was deleted.

6 changes: 0 additions & 6 deletions tests/hijack/base.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
import { TestData } from '../_helpers/globals';
import { addAsyncTest, callAsync, getLastMethodEvents, registerMethod } from '../_helpers/helpers';
import { prettyLog } from '../_helpers/pretty-log';


addAsyncTest(
'Base - method params',
async function (test) {
let info;

let methodId = registerMethod(async function () {
await TestData.insertAsync({aa: 10});
info = Kadira._getInfo();
});

await callAsync(methodId, 10, 'abc');

prettyLog(info);

let events = getLastMethodEvents([0, 2]);

let expected = [
Expand Down

0 comments on commit 37ab823

Please sign in to comment.