Profiler

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Giao diện Profiler của JS Self-Profiling API cho phép bạn tạo một profile cho một phần thực thi ứng dụng web của bạn.

Hàm khởi tạo

Profiler() Experimental

Tạo một đối tượng Profiler mới và bắt đầu thu thập các mẫu.

Phương thức phiên bản

Profiler.stop() Experimental

Dừng profiler, trả về một Promise phân giải thành profile.

Sự kiện

samplebufferfull

Kích hoạt khi profile đã ghi đủ mẫu để lấp đầy bộ đệm nội bộ của nó.

Ví dụ

Ghi lại một profile

Code sau đây tạo profile cho thao tác doWork() và ghi log kết quả.

js
const profiler = new Profiler({ sampleInterval: 10, maxBufferSize: 10000 });

doWork();

const profile = await profiler.stop();
console.log(JSON.stringify(profile));

Tạo profile khi tải trang

Code sau đây tạo profile cho khoảng thời gian giữa khi script chạy lần đầu và sự kiện load của window kích hoạt.

js
const profiler = new Profiler({ sampleInterval: 10, maxBufferSize: 10000 });

window.addEventListener("load", async () => {
  const profile = await profiler.stop();
  console.log(JSON.stringify(profile));
});

Thông số kỹ thuật

Specification
JS Self-Profiling API
# the-profiler-interface

Tương thích trình duyệt