import { Plugin } from "@webiny/plugins"; import type { Benchmark } from "~/types.js"; /** * This plugin should be initialized only once per context, hence the name of the plugin. */ export class BenchmarkPlugin extends Plugin { public static override readonly type: string = "context.benchmark"; public override name = "context.benchmark"; public readonly benchmark: Benchmark; public constructor(benchmark: Benchmark) { super(); this.benchmark = benchmark; } public enable(): void { this.benchmark.enable(); } public disable(): void { this.benchmark.disable(); } public async measure(name: string, cb: () => Promise): Promise { return this.benchmark.measure(name, cb); } }