Profiler
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.
TheProfiler interface of theJS Self-Profiling API enables you to create aprofile of some part of your web application's execution.
In this article
Constructor
Profiler()ExperimentalCreates a new
Profilerobject, and starts collecting samples.
Instance methods
Profiler.stop()ExperimentalStops the profiler, returning a
Promisethat resolves to theprofile.
Events
samplebufferfullFired when the profile has recorded enough samples to fill its internal buffer.
Examples
>Recording a profile
The following code profiles thedoWork() operation, and logs the result.
js
const profiler = new Profiler({ sampleInterval: 10, maxBufferSize: 10000 });doWork();const profile = await profiler.stop();console.log(JSON.stringify(profile));Profiling page load
The following code profiles the time between the script first running and the window'sload event firing.
js
const profiler = new Profiler({ sampleInterval: 10, maxBufferSize: 10000 });window.addEventListener("load", async () => { const profile = await profiler.stop(); console.log(JSON.stringify(profile));});Specifications
| Specification |
|---|
| JS Self-Profiling API> # the-profiler-interface> |