UNPKG

ddl-manager

Version:

store postgres procedures and triggers in files

62 lines 1.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseCalls = void 0; const Call_1 = require("./Call"); class Coach { constructor(rows) { this.rows = rows; } parseCalls() { const rootCalls = []; const parents = []; for (let i = 0, n = this.rows.length; i < n; i++) { let row = this.rows[i]; if (isStart(row)) { const call = new Call_1.Call(row); let parent = parents[parents.length - 1]; if (parent) { parent.addChild(call); } if (parents.length === 0) { rootCalls.push(call); } parents.push(call); } else { const lastCall = parents.pop(); if (!lastCall) { throw new Error("unexpected end " + JSON.stringify(row)); } if (row.end_id !== lastCall.id) { throw new Error("wrong end id " + JSON.stringify({ lastCall: { id: lastCall.id, func: lastCall.func }, end: row })); } lastCall.setEnd(row); } } return rootCalls; } } function isStart(row) { return row.func_name !== null; } function parseCalls(logs) { console.log("parsing logs"); const coach = new Coach(logs); const rootCalls = coach.parseCalls(); const slowCalls = rootCalls.slice().sort((callA, callB) => callB.total_time - callA.total_time).slice(0, 10); console.log("top 10 slow calls: \n" + slowCalls.map(call => call.func + " " + call.total_time + "ms").join("\n")); return rootCalls; } exports.parseCalls = parseCalls; module.exports = { Coach, parseCalls }; //# sourceMappingURL=Coach.js.map