diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/api/performanceobserver | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/web/api/performanceobserver')
5 files changed, 393 insertions, 0 deletions
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 +--- +<div>{{APIRef("Performance Timeline API")}}</div> + +<div> </div> + +<p>{{domxref('PerformanceObserver')}} 接口的 <strong><code>disconnect()</code></strong> 方法用于阻止性能观察者接收任何 {{domxref("PerformanceEntry","性能条目", '', 'true')}} 事件。</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox"><em>performanceObserver</em>.disconnect(); +</pre> + +<h2 id="例子">例子</h2> + +<pre class="brush: js">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"]}); +</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Performance Timeline Level 2', '#dom-performanceobserver-disconnect', 'disconnect()')}}</td> + <td>{{Spec2('Performance Timeline Level 2')}}</td> + <td><code>disconnect()</code> 方法的初始定义。</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div> + + +<p>{{Compat("api.PerformanceObserver.disconnect")}}</p> +</div> 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 +--- +<div>{{APIRef("Performance Timeline API")}}</div> + +<div><strong><code>PerformanceObserver</code></strong> 用于监测性能度量事件,在浏览器的性能时间轴记录下一个新的 {{domxref("PerformanceEntry","performance entries", '', 'true')}} 的时候将会被通知 。</div> + +<div></div> + +<div>{{AvailableInWorkers}}</div> + +<h2 id="构造函数">构造函数</h2> + +<dl> + <dt>{{domxref("PerformanceObserver.PerformanceObserver","PerformanceObserver()")}}</dt> + <dd>创建并返回一个新的 <code>PerformanceObserver</code> 对象。</dd> +</dl> + +<h2 id="方法">方法</h2> + +<dl> + <dt>{{domxref("PerformanceObserver.observe","PerformanceObserver.observe()")}}</dt> + <dd>指定监测的 {{domxref("PerformanceEntry.entryType","entry types")}} 的集合。 当 {{domxref("PerformanceEntry","performance entry")}} 被记录并且是指定的 <code>entryTypes</code> 之一的时候,性能观察者对象的回调函数会被调用。</dd> + <dt>{{domxref("PerformanceObserver.disconnect","PerformanceObserver.disconnect()")}}</dt> + <dd>性能监测回调停止接收 {{domxref("PerformanceEntry","性能条目", '', 'true')}}。</dd> +</dl> + +<dl> +</dl> + +<h2 id="示例">示例</h2> + +<pre class="brush: js">function perf_observer(list, observer) { + // Process the "measure" event + // 处理 "measure" 事件 +} +var observer2 = new PerformanceObserver(perf_observer); +observer2.observe({entryTypes: ["measure"]});</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">规范草案</th> + <th scope="col">状态</th> + <th scope="col">注释</th> + </tr> + <tr> + <td>{{SpecName('Performance Timeline Level 2', '#dom-performanceobserver', 'PerformanceObserver')}}</td> + <td>{{Spec2('Performance Timeline Level 2')}}</td> + <td><code>PerformanceObserver</code> 接口的初始定义</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div> +<div class="hidden">此页面上的兼容性表是根据结构化数据生成的。 如果您想为数据做出贡献,请查看https://github.com/mdn/browser-compat-data并向我们发送拉取请求。</div> + +<p>{{Compat("api.PerformanceObserver")}}</p> +</div> 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 +--- +<div>{{APIRef("Performance Timeline API")}}</div> + +<p>{{domxref("PerformanceObserver", "性能监测对象")}} 的 <strong><code>observe()</code></strong> 方法用于观察传入的参数中指定的性能条目类型的集合。当记录一个指定类型的性能条目时,性能监测对象的回调函数将会被调用。</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox"><em>observer</em>.observe(<em>options</em>); +</pre> + +<h3 id="参数">参数</h3> + +<p> </p> + +<dl> + <dt><em>options</em></dt> + <dd>一个只装了单个键值对的对象,该键值对的键名规定为 <code>entryTypes</code>。<code>entryTypes</code> 的取值要求如下:</dd> +</dl> + +<ul> + <li><code>entryTypes</code> 的值:一个放字符串的数组,字符串的有效值取值在{{domxref("PerformanceEntry.entryType", "性能条目类型")}} 中有详细列出。如果其中的某个字符串取的值无效,浏览器会自动忽略它。</li> + <li>另:若未传入 <code>options</code> 实参,或传入的 <code>options</code> 实参为空数组,会抛出 {{jsxref("TypeError")}}。</li> +</ul> + +<dl> + <dt> </dt> +</dl> + +<h2 id="示例">示例</h2> + +<pre class="brush: js">/* 写法一 */ + +//直接往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"]}); +</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Performance Timeline Level 2', '#dom-performanceobserver-observe', 'observe()')}}</td> + <td>{{Spec2('Performance Timeline Level 2')}}</td> + <td>Initial definition of <code>observe()</code> method.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div>{{CompatibilityTable}}</div> + +<div id="compat-desktop"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Chrome</th> + <th>Firefox (Gecko)</th> + <th>Internet Explorer</th> + <th>Opera</th> + <th>Safari (WebKit)</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatChrome(52.0)}}</td> + <td>{{CompatGeckoDesktop(57)}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatOpera("39")}}</td> + <td>{{CompatNo}}</td> + </tr> + </tbody> +</table> +</div> + +<div id="compat-mobile"> +<table class="compat-table"> + <tbody> + <tr> + <th>Feature</th> + <th>Android</th> + <th>Android Webview</th> + <th>Firefox Mobile (Gecko)</th> + <th>IE Phone</th> + <th>Opera Mobile</th> + <th>Safari Mobile</th> + <th>Chrome for Android</th> + </tr> + <tr> + <td>Basic support</td> + <td>{{CompatNo}}</td> + <td>{{CompatNo}}</td> + <td>{{CompatGeckoMobile(57)}}</td> + <td>{{CompatNo}}</td> + <td> + <p>{{CompatOperaMobile(39)}}</p> + </td> + <td>{{CompatNo}}</td> + <td>{{CompatChrome(52.0)}}</td> + </tr> + </tbody> +</table> +</div> 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 +--- +<div>{{APIRef("Performance Timeline API")}}</div> + +<p><strong><code>PerformanceObserver()</code></strong> 构造函数使用给定的观察者 <code>callback</code> 生成一个新的 {{domxref("PerformanceObserver")}} 对象.当通过 {{domxref("PerformanceObserver.observe","observe()")}} 方法注册的 {{domxref("PerformanceEntry.entryType","条目类型",'','true')}} 的 {{domxref("PerformanceEntry","性能条目事件", '', 'true')}} 被记录下来时,调用该观察者回调. </p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox">var observer = new PerformanceObserver(<em>callback</em>); +</pre> + +<h3 id="参数">参数</h3> + +<dl> + <dt><em><code>callback</code></em></dt> + <dd>观察的性能事件被记录时将调用 <code>PerformanceObserverCallback</code> 回调. 调用回调时,其第一个参数是 {{domxref("PerformanceObserverEntryList","性能观察条目列表", '', 'true')}},第二个参数是 {{domxref("PerformanceObserver","观察者")}} 对象。</dd> +</dl> + +<h3 id="返回值">返回值</h3> + +<p>一个在观察的性能事件发生时调用指定的 <code>callback</code> 的新 {{domxref("PerformanceObserver")}} 对象.</p> + +<h2 id="例子">例子</h2> + +<pre class="brush: js">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"]}); +</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Performance Timeline Level 2', '#idl-def-performanceobservercallback', 'PerformanceObserver()')}}</td> + <td>{{Spec2('Performance Timeline Level 2')}}</td> + <td><code>PerformanceObserver()</code> 构造函数的初始定义。</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div> + + +<p>{{Compat("api.PerformanceObserver.PerformanceObserver")}}</p> +</div> 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 +--- +<div>{{APIRef("Performance Timeline API")}}</div> + +<div> </div> + +<p>{{domxref('PerformanceObserver')}} 接口的 <strong><code>takeRecords()</code></strong> 方法返回当前存储在性能观察器中的 {{domxref("PerformanceEntry","性能条目")}} 列表,将其清空。</p> + +<h2 id="Syntax">Syntax</h2> + +<pre class="syntaxbox">var PerformanceEntry[] = <em>performanceObserver</em>.takeRecords(); +</pre> + +<h3 id="参数">参数</h3> + +<p>None.</p> + +<h3 id="返回值">返回值</h3> + +<p>{{domxref("PerformanceEntry")}} 对象列表.</p> + +<h2 id="例子">例子</h2> + +<pre class="brush: js">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); +</pre> + +<h2 id="规范">规范</h2> + +<table class="standard-table"> + <tbody> + <tr> + <th scope="col">Specification</th> + <th scope="col">Status</th> + <th scope="col">Comment</th> + </tr> + <tr> + <td>{{SpecName('Performance Timeline Level 2', '#dom-performanceobserver-takerecords', 'takeRecords()')}}</td> + <td>{{Spec2('Performance Timeline Level 2')}}</td> + <td>Initial definition of <code>takeRecords()</code> method.</td> + </tr> + </tbody> +</table> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div> + + +<p>{{Compat("api.PerformanceObserver.takeRecords")}}</p> +</div> |