Commit 4f5cdcf5 authored by Alexei Filippov's avatar Alexei Filippov Committed by Commit Bot

DevTools: Do not poll memory usage when there are no observers.

BUG=967516

Change-Id: Ia459566db46fdde003c03ef9b14739ab739cb5b3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1636280
Commit-Queue: Alexei Filippov <alph@chromium.org>
Reviewed-by: default avatarJoel Einbinder <einbinder@chromium.org>
Cr-Commit-Position: refs/heads/master@{#667282}
parent c67ace4a
...@@ -17,7 +17,7 @@ SDK.IsolateManager = class extends Common.Object { ...@@ -17,7 +17,7 @@ SDK.IsolateManager = class extends Common.Object {
/** @type {!Set<!SDK.IsolateManager.Observer>} */ /** @type {!Set<!SDK.IsolateManager.Observer>} */
this._observers = new Set(); this._observers = new Set();
SDK.targetManager.observeModels(SDK.RuntimeModel, this); SDK.targetManager.observeModels(SDK.RuntimeModel, this);
this._poll(); this._pollId = 0;
} }
/** /**
...@@ -26,6 +26,8 @@ SDK.IsolateManager = class extends Common.Object { ...@@ -26,6 +26,8 @@ SDK.IsolateManager = class extends Common.Object {
observeIsolates(observer) { observeIsolates(observer) {
if (this._observers.has(observer)) if (this._observers.has(observer))
throw new Error('Observer can only be registered once'); throw new Error('Observer can only be registered once');
if (!this._observers.size)
this._poll();
this._observers.add(observer); this._observers.add(observer);
for (const isolate of this._isolates.values()) for (const isolate of this._isolates.values())
observer.isolateAdded(isolate); observer.isolateAdded(isolate);
...@@ -36,6 +38,8 @@ SDK.IsolateManager = class extends Common.Object { ...@@ -36,6 +38,8 @@ SDK.IsolateManager = class extends Common.Object {
*/ */
unobserveIsolates(observer) { unobserveIsolates(observer) {
this._observers.delete(observer); this._observers.delete(observer);
if (!this._observers.size)
++this._pollId; // Stops the current polling loop.
} }
/** /**
...@@ -113,7 +117,8 @@ SDK.IsolateManager = class extends Common.Object { ...@@ -113,7 +117,8 @@ SDK.IsolateManager = class extends Common.Object {
} }
async _poll() { async _poll() {
while (true) { const pollId = this._pollId;
while (pollId === this._pollId) {
await Promise.all(Array.from(this.isolates(), isolate => isolate._update())); await Promise.all(Array.from(this.isolates(), isolate => isolate._update()));
await new Promise(r => setTimeout(r, SDK.IsolateManager.PollIntervalMs)); await new Promise(r => setTimeout(r, SDK.IsolateManager.PollIntervalMs));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment