UNPKG

@deepkit/framework

Version:

134 lines 6.28 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; const __ΩPick = ['T', 'K', 'Pick', 'l+e#!e"!fRb!b"Pde""N#!w#y']; /*@ts-ignore*/ import { __ΩLoggerInterface } from '@deepkit/logger'; /*@ts-ignore*/ import { __ΩFlag } from '@deepkit/app'; /*@ts-ignore*/ import { __ΩCommand } from '@deepkit/app'; function __assignType(fn, args) { fn.__type = args; return fn; } /* * Deepkit Framework * Copyright (C) 2021 Deepkit UG, Marc J. Schmidt * * This program is free software: you can redistribute it and/or modify * it under the terms of the MIT License. * * You should have received a copy of the MIT License along with this program. */ import { cli } from '@deepkit/app'; import { FrameworkConfig } from '../module.config.js'; import { FrameCategory, Stopwatch, StopwatchStore } from '@deepkit/stopwatch'; import { join } from 'path'; import { existsSync, readFileSync } from 'fs'; import { decodeFrames } from '@deepkit/framework-debug-api'; import { sleep } from '@deepkit/core'; /** * @description Prints debugging information about profiler frames. */ let DebugProfileFramesCommand = class DebugProfileFramesCommand { constructor(config, logger, stopwatchStore, stopwatch) { this.config = config; this.logger = logger; this.stopwatchStore = stopwatchStore; this.stopwatch = stopwatch; } async execute(reset = false) { if (reset) this.stopwatchStore.removeAll(); this.stopwatch.enable(); console.log('start'); const createScenario = async () => { const frame = this.stopwatch.start('Test', FrameCategory.http, true); await frame.run(async () => { for (let i = 0; i < 2; i++) { const frame = this.stopwatch.start('Sub ' + i, FrameCategory.function); if (i === 0) { await sleep(0.1); } else { for (let i = 0; i < 2; i++) { const frame = this.stopwatch.start('Sub sub ' + i, FrameCategory.function); if (i === 0) { await sleep(0.1); } else { for (let i = 0; i < 2; i++) { const frame = this.stopwatch.start('Sub sub sub ' + i, FrameCategory.function); await sleep(0.1); frame.end(); } } frame.end(); } } frame.end(); } }); frame.end(); }; const wait = createScenario(); await sleep(0.05); await createScenario(); await wait; console.log('end'); // // console.log('bye'); // await this.stopwatchStore.close(); const path = join(this.config.varPath, this.config.debugStorePath); const framesPath = join(path, 'frames.bin'); // // if (reset) { // // unlinkSync(join(path, 'frames.bin')); // // unlinkSync(join(path, 'frames-data.bin')); // // this.logger.log('Files removed.'); // // return; // // } // // // // const frames: { [cid: number]: Frame } = {}; if (existsSync(framesPath)) { decodeFrames(readFileSync(framesPath), __assignType((frame) => { console.log(frame); // if (frame.type === FrameType.start) { // if (frame.category !== FrameCategory.http) return; // frames[frame.cid] = new Frame(frame.cid, frame.timestamp, frame.context, frame.label, frame.category); // } else if (frame.type === FrameType.end) { // const r = frames[frame.cid]; // if (!r) return; // r.end = frame.timestamp; // } }, ['frame', '', 'P"2!"/"'])); } // for (const frame of Object.values(frames)) { // if (frame.end) continue; // console.log('Open frame', frame.label); // } // decodeFrameData(readFileSync(join(path, 'frames-data.bin')), (frame) => { // const r = requests[frame.cid]; // if (!r) return; // const data = deserializeFrameData(frame) as FrameCategoryData[FrameCategory.http]; // if (data.clientIp) r.clientIp = data.clientIp; // if (data.method) r.method = data.method; // if (data.url) r.url = data.url; // if (data.responseStatus) r.statusCode = data.responseStatus; // }); } }; DebugProfileFramesCommand.__type = [() => __ΩPick, () => FrameworkConfig, "varPath", "debugStorePath", 'config', () => __ΩLoggerInterface, 'logger', () => StopwatchStore, 'stopwatchStore', () => Stopwatch, 'stopwatch', 'constructor', () => __ΩFlag, 'reset', () => false, 'execute', () => __ΩCommand, 'DebugProfileFramesCommand', 'Prints debugging information about profiler frames.', 'PP7"P.#.$Jo!#2%<n&2\'<P7(2)<P7*2+<"0,PP)n-K2.>/$`005n1x"w2?3']; DebugProfileFramesCommand = __decorate([ cli.controller('debug:profile-frames'), __metadata("design:paramtypes", [Object, Object, StopwatchStore, Stopwatch]) ], DebugProfileFramesCommand); export { DebugProfileFramesCommand }; //# sourceMappingURL=debug-debug-frames.js.map