2020-04-02 09:36:50 +08:00
|
|
|
import { ComponentInternalInstance, formatComponentName } from './component'
|
|
|
|
|
|
|
|
let supported: boolean
|
|
|
|
let perf: any
|
|
|
|
|
|
|
|
export function startMeasure(
|
|
|
|
instance: ComponentInternalInstance,
|
|
|
|
type: string
|
|
|
|
) {
|
|
|
|
if (instance.appContext.config.performance && isSupported()) {
|
|
|
|
perf.mark(`vue-${type}-${instance.uid}`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function endMeasure(instance: ComponentInternalInstance, type: string) {
|
|
|
|
if (instance.appContext.config.performance && isSupported()) {
|
|
|
|
const startTag = `vue-${type}-${instance.uid}`
|
|
|
|
const endTag = startTag + `:end`
|
|
|
|
perf.mark(endTag)
|
2020-06-26 21:28:15 +08:00
|
|
|
perf.measure(`<${formatComponentName(instance)}> ${type}`, startTag, endTag)
|
2020-04-02 09:36:50 +08:00
|
|
|
perf.clearMarks(startTag)
|
|
|
|
perf.clearMarks(endTag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function isSupported() {
|
|
|
|
if (supported !== undefined) {
|
|
|
|
return supported
|
|
|
|
}
|
2020-06-11 04:54:23 +08:00
|
|
|
/* eslint-disable no-restricted-globals */
|
2020-04-02 09:36:50 +08:00
|
|
|
if (typeof window !== 'undefined' && window.performance) {
|
|
|
|
supported = true
|
|
|
|
perf = window.performance
|
|
|
|
} else {
|
|
|
|
supported = false
|
|
|
|
}
|
2020-06-11 04:54:23 +08:00
|
|
|
/* eslint-enable no-restricted-globals */
|
2020-04-02 09:36:50 +08:00
|
|
|
return supported
|
|
|
|
}
|