--- title: PerformanceEntry slug: Web/API/PerformanceEntry tags: - API - Interface - NeedsTranslation - Reference - TopicStub - Web Performance translation_of: Web/API/PerformanceEntry ---
PerformanceEntry
对象代表了 performance 时间列表中的单个 metric 数据. 每一个 performance entry 都可以在应用运行过程中通过手动构建 {{domxref("PerformanceMark","mark")}} 或者 {{domxref("PerformanceMeasure","measure")}} (例如调用 {{domxref("Performance.mark","mark()")}} 方法) 生成. 此外, Performance entries 在资源加载的时候,也会被动生成(例如图片、script、css等资源加载)
Note: Performance 对象暴露给了 {{domxref("Window")}} 和 {{domxref("Worker")}}. 同时该对象扩展了几个其他对象的属性,包括 {{domxref("PerformanceMark")}}, {{domxref("PerformanceMeasure")}}, {{domxref("PerformanceFrameTiming")}}, {{domxref("PerformanceNavigationTiming")}} 以及 {{domxref("PerformanceResourceTiming")}}.
PerformanceEntry
对象的 JSON 格式数据以下例子检查了当前浏览器所支持的所有 PerformanceEntry
属性,每个属性的检查结果都会通过 console 打印出来
function print_PerformanceEntries() { // Use getEntries() to get a list of all performance entries var p = performance.getEntries(); for (var i=0; i < p.length; i++) { console.log("PerformanceEntry[" + i + "]"); print_PerformanceEntry(p[i]); } } function print_PerformanceEntry(perfEntry) { var properties = ["name", "entryType", "startTime", "duration"]; for (var i=0; i < properties.length; i++) { // check each property var supported = properties[i] in perfEntry; if (supported) { var value = perfEntry[properties[i]]; console.log("... " + properties[i] + " = " + value); } else { console.log("... " + properties[i] + " = NOT supported"); } } }
Specification | Status | Comment |
---|---|---|
{{SpecName('Performance Timeline Level 2', '#dom-performanceentry', 'PerformanceEntry')}} | {{Spec2('Performance Timeline Level 2')}} | Added toJSON() serializer method. |
{{SpecName('Performance Timeline', '#dom-performanceentry', 'PerformanceEntry')}} | {{Spec2('Performance Timeline')}} | Initial definition. |
{{Compat("api.PerformanceEntry")}}