Skip to content

Commit

Permalink
feat(App): Add new function timeEnd for profiling | MP
Browse files Browse the repository at this point in the history
Add new function timeEnd for profiling
  • Loading branch information
Mark Poepping committed Aug 14, 2020
1 parent ab28c29 commit 0450766
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion index.js
Expand Up @@ -12,6 +12,12 @@ module.exports = (config) => {
const padLength = _.get(config, 'padLength', 12)
const customLevels = _.get(config,'customLevels')

const precisionMap = [
{ precision: 1e6, name: 'ms' },
{ precision: 1e3, name: 'µs' },
{ precision: 1, name: 'ns' },
]

const myFormat = format.printf(({ timestamp, level, message, meta, e }) => {
const fileName = _.get(meta, 'fileName') ? _.get(meta, 'fileName') + ' | ' : ''
const functionName = _.get(meta, 'functionName') ? _.get(meta, 'functionName') + ' | ' : ''
Expand Down Expand Up @@ -131,13 +137,22 @@ module.exports = (config) => {
})
}

const timeEnd = (profile, start, precision = 1e6) => {
const end = process.hrtime.bigint()
const div = BigInt(precision)
const sec = _.find(precisionMap, { precision })
const s = (end - start)/div
acLogger.debug(`Profiling | ${profile} | ${s}${sec.name}`)
}

return {
acLogger,
headline,
functionStartLine,
listing,
bootstrapInfo,
serverInfo,
acSESnfo
acSESnfo,
timeEnd
}
}

0 comments on commit 0450766

Please sign in to comment.