vue3-yuanma/packages/runtime-core/src/profiling.ts
Evan You e765d81404 fix(runtime-core): fix component name inference in warnings
Should not pollute component definition name property
fix #1418
2020-06-26 09:28:15 -04:00

40 lines
1.0 KiB
TypeScript

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)
perf.measure(`<${formatComponentName(instance)}> ${type}`, startTag, endTag)
perf.clearMarks(startTag)
perf.clearMarks(endTag)
}
}
function isSupported() {
if (supported !== undefined) {
return supported
}
/* eslint-disable no-restricted-globals */
if (typeof window !== 'undefined' && window.performance) {
supported = true
perf = window.performance
} else {
supported = false
}
/* eslint-enable no-restricted-globals */
return supported
}