egg-core
Advanced tools
Comparing version 5.2.0 to 5.3.0
'use strict'; | ||
const { EOL } = require('os'); | ||
const assert = require('assert'); | ||
const MAP = Symbol('Timing#map'); | ||
@@ -8,5 +10,5 @@ const LIST = Symbol('Timing#list'); | ||
class Timing { | ||
constructor() { | ||
this._enable = true; | ||
this._start = null; | ||
this[MAP] = new Map(); | ||
@@ -20,3 +22,3 @@ this[LIST] = []; | ||
// process start time | ||
this.start('Process Start', Date.now() - Math.floor((process.uptime() * 1000))); | ||
this.start('Process Start', Date.now() - Math.floor(process.uptime() * 1000)); | ||
this.end('Process Start'); | ||
@@ -37,2 +39,5 @@ | ||
start = start || Date.now(); | ||
if (this._start === null) { | ||
this._start = start; | ||
} | ||
const item = { | ||
@@ -77,4 +82,27 @@ name, | ||
} | ||
itemToString(timelineEnd, item, times) { | ||
const isEnd = typeof item.duration === 'number'; | ||
const duration = isEnd ? item.duration : timelineEnd - item.start; | ||
const offset = item.start - this._start; | ||
const status = `${duration}ms${isEnd ? '' : ' NOT_END'}`; | ||
const timespan = Math.floor((offset * times).toFixed(6)); | ||
let timeline = Math.floor((duration * times).toFixed(6)); | ||
timeline = timeline > 0 ? timeline : 1; // make sure there is at least one unit | ||
const message = `#${item.index} ${item.name}`; | ||
return ' '.repeat(timespan) + '▇'.repeat(timeline) + ` [${status}] - ${message}`; | ||
} | ||
toString(prefix = 'egg start timeline:', width = 50) { | ||
const timelineEnd = Date.now(); | ||
const timelineDuration = timelineEnd - this._start; | ||
let times = 1; | ||
if (timelineDuration > width) { | ||
times = width / timelineDuration; | ||
} | ||
// follow https://github.com/node-modules/time-profile/blob/master/lib/profiler.js#L88 | ||
return prefix + EOL + this[LIST].map(item => this.itemToString(timelineEnd, item, times)).join(EOL); | ||
} | ||
} | ||
module.exports = Timing; |
{ | ||
"name": "egg-core", | ||
"version": "5.2.0", | ||
"version": "5.3.0", | ||
"description": "A core Pluggable framework based on koa", | ||
@@ -16,2 +16,3 @@ "main": "index.js", | ||
"test-local": "egg-bin test -p", | ||
"test-single": "egg-bin test", | ||
"cov": "egg-bin cov -p", | ||
@@ -62,3 +63,3 @@ "ci": "npm run lint && npm run cov", | ||
"depd": "^2.0.0", | ||
"egg-logger": "^2.4.1", | ||
"egg-logger": "^3.1.0", | ||
"egg-path-matching": "^1.0.1", | ||
@@ -65,0 +66,0 @@ "extend2": "^1.0.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
113043
3041
+ Addedansi-styles@4.3.0(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedegg-logger@3.5.0(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addediconv-lite@0.6.3(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedutility@2.1.0(transitive)
- Removedansi-styles@3.2.1(transitive)
- Removedchalk@2.4.2(transitive)
- Removedcolor-convert@1.9.3(transitive)
- Removedcolor-name@1.1.3(transitive)
- Removeddebug@2.6.9(transitive)
- Removedegg-logger@2.9.1(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedhas-flag@3.0.0(transitive)
- Removediconv-lite@0.4.24(transitive)
- Removedms@2.0.0(transitive)
- Removedsupports-color@5.5.0(transitive)
Updatedegg-logger@^3.1.0