-
-
Notifications
You must be signed in to change notification settings - Fork 8.6k
/
Copy pathprofiling.ts
57 lines (51 loc) · 1.38 KB
/
profiling.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* eslint-disable no-restricted-globals */
import {
type ComponentInternalInstance,
formatComponentName,
} from './component'
import { devtoolsPerfEnd, devtoolsPerfStart } from './devtools'
let supported: boolean
let perf: Performance
export function startMeasure(
instance: ComponentInternalInstance,
type: string,
): void {
if (instance.appContext.config.performance && isSupported()) {
perf.mark(`vue-${type}-${instance.uid}`)
}
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
devtoolsPerfStart(instance, type, isSupported() ? perf.now() : Date.now())
}
}
export function endMeasure(
instance: ComponentInternalInstance,
type: string,
): void {
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)
}
if (__DEV__ || __FEATURE_PROD_DEVTOOLS__) {
devtoolsPerfEnd(instance, type, isSupported() ? perf.now() : Date.now())
}
}
function isSupported() {
if (supported !== undefined) {
return supported
}
if (typeof window !== 'undefined' && window.performance) {
supported = true
perf = window.performance
} else {
supported = false
}
return supported
}