diff --git a/app/lib/debug/MonitorLokiExecutionTime.ts b/app/lib/debug/MonitorLokiExecutionTime.ts index ca4f154125275d371848ca5e2c0403dcd965861c..0491951af3e646bba96c9cfcc8ef5f55f0cb2297 100644 --- a/app/lib/debug/MonitorLokiExecutionTime.ts +++ b/app/lib/debug/MonitorLokiExecutionTime.ts @@ -13,26 +13,29 @@ import {NewLogger} from "../logger" import {getMicrosecondsTime} from "../../ProcessCpuProfiler" +import {OtherConstants} from "../other_constants" const theLogger = NewLogger() export const MonitorLokiExecutionTime = function (dumpFirstParam = false) { return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) { - const original = descriptor.value - if (original.__proto__.constructor.name === "AsyncFunction") { - descriptor.value = async function (...args:any[]) { - const that :any = this - const now = getMicrosecondsTime() - const result = await original.apply(this, args) - if (dumpFirstParam) { - theLogger.trace('[loki][%s][%s] => %sµs', that.collectionName, propertyKey, (getMicrosecondsTime() - now), args && args[0]) - } else { - theLogger.trace('[loki][%s][%s] => %sµs', that.collectionName, propertyKey, (getMicrosecondsTime() - now)) + if (OtherConstants.ENABLE_LOKI_MONITORING) { + const original = descriptor.value + if (original.__proto__.constructor.name === "AsyncFunction") { + descriptor.value = async function (...args:any[]) { + const that :any = this + const now = getMicrosecondsTime() + const result = await original.apply(this, args) + if (dumpFirstParam) { + theLogger.trace('[loki][%s][%s] => %sµs', that.collectionName, propertyKey, (getMicrosecondsTime() - now), args && args[0]) + } else { + theLogger.trace('[loki][%s][%s] => %sµs', that.collectionName, propertyKey, (getMicrosecondsTime() - now)) + } + return result } - return result + } else { + throw Error("Monitoring a Loki synchronous function is not allowed.") } - } else { - throw Error("Monitoring a Loki synchronous function is not allowed.") } } } \ No newline at end of file diff --git a/app/lib/debug/MonitorSQLExecutionTime.ts b/app/lib/debug/MonitorSQLExecutionTime.ts index 3f2dff3668f1b19365bddc94d48415ad9bae7278..65724c527347f3df256933cbf1c1dcf582edd44d 100644 --- a/app/lib/debug/MonitorSQLExecutionTime.ts +++ b/app/lib/debug/MonitorSQLExecutionTime.ts @@ -13,24 +13,27 @@ import {getDurationInMicroSeconds, getMicrosecondsTime} from "../../ProcessCpuProfiler" import {NewLogger} from "../logger" +import {OtherConstants} from "../other_constants" const theLogger = NewLogger() export const MonitorSQLExecutionTime = function () { return function (target: any, propertyKey: string, descriptor: PropertyDescriptor) { - const original = descriptor.value - if (original.__proto__.constructor.name === "AsyncFunction") { - descriptor.value = async function (...args:any[]) { - const start = getMicrosecondsTime() - const sql: string = args[0] - const params: any[] = args[1] - const entities: any[] = await original.apply(this, args) - const duration = getDurationInMicroSeconds(start) - theLogger.trace('[sqlite][query] %s %s %sµs', sql, JSON.stringify(params || []), duration) - return entities + if (OtherConstants.ENABLE_SQL_MONITORING) { + const original = descriptor.value + if (original.__proto__.constructor.name === "AsyncFunction") { + descriptor.value = async function (...args: any[]) { + const start = getMicrosecondsTime() + const sql: string = args[0] + const params: any[] = args[1] + const entities: any[] = await original.apply(this, args) + const duration = getDurationInMicroSeconds(start) + theLogger.trace('[sqlite][query] %s %s %sµs', sql, JSON.stringify(params || []), duration) + return entities + } + } else { + throw Error("Monitoring an SQL synchronous function is not allowed.") } - } else { - throw Error("Monitoring an SQL synchronous function is not allowed.") } } } \ No newline at end of file diff --git a/app/lib/other_constants.ts b/app/lib/other_constants.ts index d10528e99d6325e1c5fe5ced474a1164f9795cfc..e7b7b364bf47b06f56e5363574cbc56a3ae02c96 100644 --- a/app/lib/other_constants.ts +++ b/app/lib/other_constants.ts @@ -20,5 +20,8 @@ export const OtherConstants = { SWITCHED: 'switched', HEAD_CHANGED: 'newHEAD', RESOLUTION_DONE: 'resolution_done' - } + }, + + ENABLE_LOKI_MONITORING: false, + ENABLE_SQL_MONITORING: false, } \ No newline at end of file