improve(plugin): add perf info table for loading phase

pull/2714/head
charlie 2021-08-17 12:00:21 +08:00
parent 0a229159f6
commit 0750d0c09a
1 changed files with 31 additions and 4 deletions

View File

@ -567,10 +567,14 @@ class PluginLocal
this._loadErr = e
} finally {
if (!this._loadErr) {
if (this.disabled) {
this._status = PluginLocalLoadStatus.UNLOADED
} else {
this._status = PluginLocalLoadStatus.LOADED
}
}
}
}
async reload () {
debug('TODO: reload plugin', this.id)
@ -790,6 +794,28 @@ class LSPluginCore
return
}
const perfTable = new Map<string, { o: PluginLocal, s: number, e: number }>()
const debugPerfInfo = () => {
const data = Array.from(perfTable.values()).reduce((ac, it) => {
const { options, status, disabled } = it.o
ac [it.o.id] = {
name: options.name,
entry: options.entry,
status: status,
enabled: typeof disabled === 'boolean' ? (!disabled ? '🟢' : '⚫️') : '🔴',
perf: !it.e ? it.o.loadErr : `${(it.e - it.s).toFixed(2)}ms`
}
return ac
}, {})
console.table(data)
}
// @ts-ignore
window.__debugPluginsPerfInfo = debugPerfInfo
try {
this._isRegistering = true
@ -810,8 +836,8 @@ class LSPluginCore
const { url } = pluginOptions as PluginLocalOptions
const pluginLocal = new PluginLocal(pluginOptions as PluginLocalOptions, this, this)
const timeLabel = `[LOAD Plugin] ${pluginLocal.debugTag}`
console.time(timeLabel)
const perfInfo = { o: pluginLocal, s: performance.now(), e: 0 }
perfTable.set(pluginLocal.id, perfInfo)
await pluginLocal.load(readyIndicator)
@ -830,7 +856,7 @@ class LSPluginCore
}
}
console.timeEnd(timeLabel)
perfInfo.e = performance.now()
pluginLocal.settings?.on('change', (a) => {
this.emit('settings-changed', pluginLocal.id, a)
@ -854,6 +880,7 @@ class LSPluginCore
console.error(e)
} finally {
this._isRegistering = false
debugPerfInfo()
}
}