debug: Convert IterationProfiler to an ES6 class.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2020-07-22 15:13:13 -07:00
committed by Tim Abbott
parent ec9c272165
commit c4024e30c2

View File

@@ -98,15 +98,13 @@ export function check_duplicate_ids() {
* The _rest_of_iteration section is the region of the iteration body
* after section b.
*/
export function IterationProfiler() {
this.sections = new Map();
this.last_time = window.performance.now();
}
export class IterationProfiler {
sections = new Map();
last_time = window.performance.now();
IterationProfiler.prototype = {
iteration_start() {
this.section("_iteration_overhead");
},
}
iteration_stop() {
const now = window.performance.now();
@@ -118,13 +116,13 @@ IterationProfiler.prototype = {
);
}
this.last_time = now;
},
}
section(label) {
const now = window.performance.now();
this.sections.set(label, (this.sections.get(label) || 0) + (now - this.last_time));
this.last_time = now;
},
}
done() {
this.section("_iteration_overhead");
@@ -132,5 +130,5 @@ IterationProfiler.prototype = {
for (const [prop, cost] of this.sections) {
console.log(prop, cost);
}
},
};
}
}