From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../api/performanceobserver/disconnect/index.html | 60 +++++++++ files/zh-cn/web/api/performanceobserver/index.html | 70 +++++++++++ .../web/api/performanceobserver/observe/index.html | 134 +++++++++++++++++++++ .../performanceobserver/index.html | 66 ++++++++++ .../api/performanceobserver/takerecords/index.html | 63 ++++++++++ 5 files changed, 393 insertions(+) create mode 100644 files/zh-cn/web/api/performanceobserver/disconnect/index.html create mode 100644 files/zh-cn/web/api/performanceobserver/index.html create mode 100644 files/zh-cn/web/api/performanceobserver/observe/index.html create mode 100644 files/zh-cn/web/api/performanceobserver/performanceobserver/index.html create mode 100644 files/zh-cn/web/api/performanceobserver/takerecords/index.html (limited to 'files/zh-cn/web/api/performanceobserver') diff --git a/files/zh-cn/web/api/performanceobserver/disconnect/index.html b/files/zh-cn/web/api/performanceobserver/disconnect/index.html new file mode 100644 index 0000000000..d0942be4b8 --- /dev/null +++ b/files/zh-cn/web/api/performanceobserver/disconnect/index.html @@ -0,0 +1,60 @@ +--- +title: PeformanceObserver.disconnect() +slug: Web/API/PerformanceObserver/disconnect +translation_of: Web/API/PerformanceObserver/disconnect +--- +
{{APIRef("Performance Timeline API")}}
+ +
 
+ +

{{domxref('PerformanceObserver')}} 接口的 disconnect() 方法用于阻止性能观察者接收任何 {{domxref("PerformanceEntry","性能条目", '', 'true')}} 事件。

+ +

语法

+ +
performanceObserver.disconnect();
+
+ +

例子

+ +
var observer = new PerformanceObserver(function(list, obj) {
+  var entries = list.getEntries();
+  for (var i=0; i < entries.length; i++) {
+    // Process "mark" and "frame" events
+  }
+});
+observer.observe({entryTypes: ["mark", "frame"]});
+
+function perf_observer(list, observer) {
+  // Process the "measure" event
+  // ...
+  // Disable additional performance events
+  observer.disconnect();
+}
+var observer2 = new PerformanceObserver(perf_observer);
+observer2.observe({entryTypes: ["measure"]});
+
+ +

规范

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Performance Timeline Level 2', '#dom-performanceobserver-disconnect', 'disconnect()')}}{{Spec2('Performance Timeline Level 2')}}disconnect() 方法的初始定义。
+ +

浏览器兼容性

+ +
+ + +

{{Compat("api.PerformanceObserver.disconnect")}}

+
diff --git a/files/zh-cn/web/api/performanceobserver/index.html b/files/zh-cn/web/api/performanceobserver/index.html new file mode 100644 index 0000000000..ca70398a68 --- /dev/null +++ b/files/zh-cn/web/api/performanceobserver/index.html @@ -0,0 +1,70 @@ +--- +title: 性能监测对象 +slug: Web/API/PerformanceObserver +tags: + - API + - 性能 + - 性能记录 + - 接口 +translation_of: Web/API/PerformanceObserver +--- +
{{APIRef("Performance Timeline API")}}
+ +
PerformanceObserver 用于监测性能度量事件,在浏览器的性能时间轴记录下一个新的 {{domxref("PerformanceEntry","performance entries", '', 'true')}}  的时候将会被通知 。
+ +
+ +
{{AvailableInWorkers}}
+ +

构造函数

+ +
+
{{domxref("PerformanceObserver.PerformanceObserver","PerformanceObserver()")}}
+
创建并返回一个新的 PerformanceObserver 对象。
+
+ +

方法

+ +
+
{{domxref("PerformanceObserver.observe","PerformanceObserver.observe()")}}
+
指定监测的 {{domxref("PerformanceEntry.entryType","entry types")}} 的集合。 当 {{domxref("PerformanceEntry","performance entry")}} 被记录并且是指定的 entryTypes 之一的时候,性能观察者对象的回调函数会被调用。
+
{{domxref("PerformanceObserver.disconnect","PerformanceObserver.disconnect()")}}
+
性能监测回调停止接收 {{domxref("PerformanceEntry","性能条目", '', 'true')}}。
+
+ +
+
+ +

示例

+ +
function perf_observer(list, observer) {
+   // Process the "measure" event
+   // 处理 "measure" 事件
+}
+var observer2 = new PerformanceObserver(perf_observer);
+observer2.observe({entryTypes: ["measure"]});
+ +

规范

+ + + + + + + + + + + + + + +
规范草案状态注释
{{SpecName('Performance Timeline Level 2', '#dom-performanceobserver', 'PerformanceObserver')}}{{Spec2('Performance Timeline Level 2')}}PerformanceObserver 接口的初始定义
+ +

浏览器兼容性

+ +
+ + +

{{Compat("api.PerformanceObserver")}}

+
diff --git a/files/zh-cn/web/api/performanceobserver/observe/index.html b/files/zh-cn/web/api/performanceobserver/observe/index.html new file mode 100644 index 0000000000..a397f4dda3 --- /dev/null +++ b/files/zh-cn/web/api/performanceobserver/observe/index.html @@ -0,0 +1,134 @@ +--- +title: PerformanceObserver.observe() +slug: Web/API/PerformanceObserver/observe +tags: + - 性能 + - 性能监测对象 + - 接口 +translation_of: Web/API/PerformanceObserver/observe +--- +
{{APIRef("Performance Timeline API")}}
+ +

{{domxref("PerformanceObserver", "性能监测对象")}} 的 observe() 方法用于观察传入的参数中指定的性能条目类型的集合。当记录一个指定类型的性能条目时,性能监测对象的回调函数将会被调用。

+ +

语法

+ +
observer.observe(options);
+
+ +

参数

+ +

 

+ +
+
options
+
一个只装了单个键值对的对象,该键值对的键名规定为 entryTypesentryTypes 的取值要求如下:
+
+ + + +
+
 
+
+ +

示例

+ +
/* 写法一 */
+
+//直接往PerformanceObserver()入参匿名回调函数,成功new了一个PerformanceObserver类的,名为observer的对象
+var observer = new PerformanceObserver(function(list, obj) {
+  var entries = list.getEntries();
+  for (var i=0; i < entries.length; i++) {
+    //处理 “mark” 和 “frame” 事件
+  }
+});
+//调用observer对象的observe()方法
+observer.observe({entryTypes: ["mark", "frame"]});
+
+/* 写法二 */
+
+//预先声明回调函数perf_observer
+function perf_observer(list, observer) {
+  //处理 “measure” 事件
+}
+//再将其传入PerformanceObserver(),成功new了一个PerformanceObserver类的,名为observer2的对象
+var observer2 = new PerformanceObserver(perf_observer);
+//调用observer2对象的observe()方法
+observer2.observe({entryTypes: ["measure"]});
+
+ +

规范

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Performance Timeline Level 2', '#dom-performanceobserver-observe', 'observe()')}}{{Spec2('Performance Timeline Level 2')}}Initial definition of observe() method.
+ +

浏览器兼容性

+ +
{{CompatibilityTable}}
+ +
+ + + + + + + + + + + + + + + + + + + +
FeatureChromeFirefox (Gecko)Internet ExplorerOperaSafari (WebKit)
Basic support{{CompatChrome(52.0)}}{{CompatGeckoDesktop(57)}}{{CompatNo}}{{CompatOpera("39")}}{{CompatNo}}
+
+ +
+ + + + + + + + + + + + + + + + + + + + + + + +
FeatureAndroidAndroid WebviewFirefox Mobile (Gecko)IE PhoneOpera MobileSafari MobileChrome for Android
Basic support{{CompatNo}}{{CompatNo}}{{CompatGeckoMobile(57)}}{{CompatNo}} +

{{CompatOperaMobile(39)}}

+
{{CompatNo}}{{CompatChrome(52.0)}}
+
diff --git a/files/zh-cn/web/api/performanceobserver/performanceobserver/index.html b/files/zh-cn/web/api/performanceobserver/performanceobserver/index.html new file mode 100644 index 0000000000..e8a540202f --- /dev/null +++ b/files/zh-cn/web/api/performanceobserver/performanceobserver/index.html @@ -0,0 +1,66 @@ +--- +title: PerformanceObserver() +slug: Web/API/PerformanceObserver/PerformanceObserver +translation_of: Web/API/PerformanceObserver/PerformanceObserver +--- +
{{APIRef("Performance Timeline API")}}
+ +

PerformanceObserver() 构造函数使用给定的观察者 callback 生成一个新的 {{domxref("PerformanceObserver")}} 对象.当通过 {{domxref("PerformanceObserver.observe","observe()")}} 方法注册的 {{domxref("PerformanceEntry.entryType","条目类型",'','true')}} 的 {{domxref("PerformanceEntry","性能条目事件", '', 'true')}} 被记录下来时,调用该观察者回调. 

+ +

语法

+ +
var observer = new PerformanceObserver(callback);
+
+ +

参数

+ +
+
callback
+
观察的性能事件被记录时将调用 PerformanceObserverCallback 回调. 调用回调时,其第一个参数是 {{domxref("PerformanceObserverEntryList","性能观察条目列表", '', 'true')}},第二个参数是 {{domxref("PerformanceObserver","观察者")}} 对象。
+
+ +

返回值

+ +

一个在观察的性能事件发生时调用指定的 callback 的新 {{domxref("PerformanceObserver")}} 对象.

+ +

例子

+ +
var observer = new PerformanceObserver(function(list, obj) {
+  var entries = list.getEntries();
+  for (var i=0; i < entries.length; i++) {
+    // Process "mark" and "frame" events
+  }
+});
+observer.observe({entryTypes: ["mark", "frame"]});
+
+function perf_observer(list, observer) {
+  // Process the "measure" event
+}
+var observer2 = new PerformanceObserver(perf_observer);
+observer2.observe({entryTypes: ["measure"]});
+
+ +

规范

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Performance Timeline Level 2', '#idl-def-performanceobservercallback', 'PerformanceObserver()')}}{{Spec2('Performance Timeline Level 2')}}PerformanceObserver() 构造函数的初始定义。
+ +

浏览器兼容性

+ +
+ + +

{{Compat("api.PerformanceObserver.PerformanceObserver")}}

+
diff --git a/files/zh-cn/web/api/performanceobserver/takerecords/index.html b/files/zh-cn/web/api/performanceobserver/takerecords/index.html new file mode 100644 index 0000000000..09c83518ea --- /dev/null +++ b/files/zh-cn/web/api/performanceobserver/takerecords/index.html @@ -0,0 +1,63 @@ +--- +title: PerformanceObserver.takeRecords() +slug: Web/API/PerformanceObserver/takeRecords +translation_of: Web/API/PerformanceObserver/takeRecords +--- +
{{APIRef("Performance Timeline API")}}
+ +
 
+ +

{{domxref('PerformanceObserver')}} 接口的 takeRecords() 方法返回当前存储在性能观察器中的 {{domxref("PerformanceEntry","性能条目")}}  列表,将其清空。

+ +

Syntax

+ +
var PerformanceEntry[] = performanceObserver.takeRecords();
+
+ +

参数

+ +

None.

+ +

返回值

+ +

{{domxref("PerformanceEntry")}} 对象列表.

+ +

例子

+ +
var observer = new PerformanceObserver(function(list, obj) {
+  var entries = list.getEntries();
+  for (var i=0; i < entries.length; i++) {
+    // Process "mark" and "frame" events
+  }
+});
+observer.observe({entryTypes: ["mark", "frame"]});
+var records = observer.takeRecords();
+console.log(records[0].name);
+console.log(records[0].startTime);
+console.log(records[0].duration);
+
+ +

规范

+ + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Performance Timeline Level 2', '#dom-performanceobserver-takerecords', 'takeRecords()')}}{{Spec2('Performance Timeline Level 2')}}Initial definition of takeRecords() method.
+ +

浏览器兼容性

+ +
+ + +

{{Compat("api.PerformanceObserver.takeRecords")}}

+
-- cgit v1.2.3-54-g00ecf