-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
93 lines (81 loc) · 1.98 KB
/
index.js
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import {Tracker} from "./src/tracker.js"
import {BrowserFlags, OsFlags} from "./src/flags.js"
import {PerfHelper} from "./src/helper.js"
class TrackerManager {
constructor() {
this.trackers = {};
this.perfHelper = new PerfHelper(this.perfPtr);
this.setPerfPtr(window.performance);
this.enabled = true;
}
get BrowserFlags() {
return BrowserFlags;
}
get OsFlags() {
return OsFlags;
}
set buffersize(value) {
this._perfPtr.setResourceTimingBufferSize(value);
}
setPerfPtr(object) {
if (object.mark && object.measure && object.getEntriesByType) {
this._perfPtr = object;
this.perfHelper._set(object);
if (object.onresourcetimingbufferfull) {
object.onresourcetimingbufferfull = function() {
console.error('You cannot make more marks and measures try upping your buffersize');
}
}
}
}
start(name) {
if (!this.enabled) {
return;
}
this.trackers[name] = new Tracker(this.perfPtr, name);
},
end(name) {
if (!this.enabled) {
return;
}
if (this.trackers[name]) {
this.trackers[name].end();
}
},
endnmeas(name) {
if (!this.enabled) {
return;
}
if (this.trackers[name]) {
return this.trackers[name].endnmeas();
}
},
meas(name) {
if (!this.enabled) {
return;
}
if (this.trackers[name]) {
return this.trackers[name].meas();
}
},
specificMeas(name, startMarkName, endMarkName) {
this.perfPtr.measure(name, startMarkName, endMarkName);
var meass = this.perfPtr.getEntriesByType('measure');
return meass.filter(function(m) {
return m.name === name;
});
},
withMeas(name, callback) {
try {
this.start(name);
callback();
} finally {
this.end(name);
}
},
enable(enabled) {
this.enabled = enabled;
}
}
const meas = new TrackerManager();
export { meas };