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