Skip to content
Snippets Groups Projects
Commit 419cb6a5 authored by Cédric Moreau's avatar Cédric Moreau
Browse files

[enh] pilot Monitoring annotations using constants

parent 31b62d6a
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment