-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathprofiler.js
More file actions
48 lines (43 loc) · 1.07 KB
/
profiler.js
File metadata and controls
48 lines (43 loc) · 1.07 KB
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
'use strict';
/**
* Profiler utility for collecting render timing data
*
* Usage:
* var profiler = Profiler.start(gd);
* // ... do work ...
* profiler.mark('phaseName');
* // ... do more work ...
* profiler.end();
*/
exports.isEnabled = function(gd) {
return gd && gd._profileEnabled === true;
};
exports.start = function(gd) {
if(!exports.isEnabled(gd)) {
return {
mark: function() {},
end: function() {}
};
}
var startTime = performance.now();
var lastMark = startTime;
var phases = {};
return {
mark: function(phaseName) {
var now = performance.now();
phases[phaseName] = {
duration: now - lastMark,
timestamp: now - startTime
};
lastMark = now;
},
end: function() {
var endTime = performance.now();
return {
total: endTime - startTime,
phases: phases,
timestamp: new Date().toISOString()
};
}
};
};