| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- 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, instance.type)}> ${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
- }
|