UNPKG

@deepkit/framework

Version:

137 lines 6.7 kB
"use strict"; 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); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DebugProfileFramesCommand = void 0; const __ΩPick = ['T', 'K', 'Pick', 'l+e#!e"!fRb!b"Pde""N#!w#y']; /*@ts-ignore*/ const { __ΩLoggerInterface } = require('@deepkit/logger'); /*@ts-ignore*/ const { __ΩFlag } = require('@deepkit/app'); /*@ts-ignore*/ const { __ΩCommand } = require('@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. */ const app_1 = require("@deepkit/app"); const module_config_js_1 = require("../module.config.js"); const stopwatch_1 = require("@deepkit/stopwatch"); const path_1 = require("path"); const fs_1 = require("fs"); const framework_debug_api_1 = require("@deepkit/framework-debug-api"); const core_1 = require("@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', stopwatch_1.FrameCategory.http, true); await frame.run(async () => { for (let i = 0; i < 2; i++) { const frame = this.stopwatch.start('Sub ' + i, stopwatch_1.FrameCategory.function); if (i === 0) { await (0, core_1.sleep)(0.1); } else { for (let i = 0; i < 2; i++) { const frame = this.stopwatch.start('Sub sub ' + i, stopwatch_1.FrameCategory.function); if (i === 0) { await (0, core_1.sleep)(0.1); } else { for (let i = 0; i < 2; i++) { const frame = this.stopwatch.start('Sub sub sub ' + i, stopwatch_1.FrameCategory.function); await (0, core_1.sleep)(0.1); frame.end(); } } frame.end(); } } frame.end(); } }); frame.end(); }; const wait = createScenario(); await (0, core_1.sleep)(0.05); await createScenario(); await wait; console.log('end'); // // console.log('bye'); // await this.stopwatchStore.close(); const path = (0, path_1.join)(this.config.varPath, this.config.debugStorePath); const framesPath = (0, path_1.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 ((0, fs_1.existsSync)(framesPath)) { (0, framework_debug_api_1.decodeFrames)((0, fs_1.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; // }); } }; exports.DebugProfileFramesCommand = DebugProfileFramesCommand; DebugProfileFramesCommand.__type = [() => __ΩPick, () => module_config_js_1.FrameworkConfig, "varPath", "debugStorePath", 'config', () => __ΩLoggerInterface, 'logger', () => stopwatch_1.StopwatchStore, 'stopwatchStore', () => stopwatch_1.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']; exports.DebugProfileFramesCommand = DebugProfileFramesCommand = __decorate([ app_1.cli.controller('debug:profile-frames'), __metadata("design:paramtypes", [Object, Object, stopwatch_1.StopwatchStore, stopwatch_1.Stopwatch]) ], DebugProfileFramesCommand); //# sourceMappingURL=debug-debug-frames.js.map