Skip to content

Commit 85f61d3

Browse files
committed
Bug 1505522: Part 1 - Wait for async reports from gatherMemory() to complete when assembling pings. r=chutten
Several call sites assume that gatherMemory() does all of its work synchronously. This is not true as it is, and will be even less true after my subsequent patches. This patch changes gatherMemory() to return a promise which resolves when all of its in-process work is done, and changes two call sites to wait for it to resolve before continuing. One remaining call site, unfortunately, needs to return ping data synchronously, and therefore cannot wait for async work to complete. Differential Revision: https://phabricator.services.mozilla.com/D13871 --HG-- extra : rebase_source : 8f417bc042b0ca1917e6ef8e396f6cb52d079df4
1 parent 1a44784 commit 85f61d3

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

toolkit/components/telemetry/other/MemoryTelemetry.jsm

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ var Impl = {
130130
getService(Ci.nsIMemoryReporterManager);
131131
} catch (e) {
132132
// OK to skip memory reporters in xpcshell
133-
return;
133+
return Promise.resolve();
134134
}
135135

136136
let histogram = Telemetry.getHistogramById("TELEMETRY_MEMORY_REPORTER_MS");
@@ -176,7 +176,7 @@ var Impl = {
176176
c("GHOST_WINDOWS", "ghostWindows");
177177

178178
if (!Telemetry.canRecordExtended) {
179-
return;
179+
return Promise.resolve();
180180
}
181181

182182
b("MEMORY_VSIZE", "vsize");
@@ -196,14 +196,18 @@ var Impl = {
196196
cc("LOW_MEMORY_EVENTS_PHYSICAL", "lowMemoryEventsPhysical");
197197
cc("PAGE_FAULTS_HARD", "pageFaultsHard");
198198

199-
try {
200-
mgr.getHeapAllocatedAsync(heapAllocated => {
201-
boundHandleMemoryReport("MEMORY_HEAP_ALLOCATED",
202-
Ci.nsIMemoryReporter.UNITS_BYTES,
203-
heapAllocated);
204-
});
205-
} catch (e) {
206-
}
199+
let promise = new Promise(resolve => {
200+
try {
201+
mgr.getHeapAllocatedAsync(heapAllocated => {
202+
boundHandleMemoryReport("MEMORY_HEAP_ALLOCATED",
203+
Ci.nsIMemoryReporter.UNITS_BYTES,
204+
heapAllocated);
205+
resolve();
206+
});
207+
} catch (e) {
208+
resolve();
209+
}
210+
});
207211

208212
if (!Utils.isContentProcess && !this._totalMemoryTimeout) {
209213
// Only the chrome process should gather total memory
@@ -240,6 +244,8 @@ var Impl = {
240244
}
241245

242246
histogram.add(new Date() - startTime);
247+
248+
return promise;
243249
},
244250

245251
handleMemoryReport(id, units, amount, key) {

toolkit/components/telemetry/pings/TelemetrySession.jsm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,10 +1048,10 @@ var Impl = {
10481048
/**
10491049
* Send data to the server. Record success/send-time in histograms
10501050
*/
1051-
send: function send(reason) {
1051+
send: async function send(reason) {
10521052
this._log.trace("send - Reason " + reason);
10531053
// populate histograms one last time
1054-
MemoryTelemetry.gatherMemory();
1054+
await MemoryTelemetry.gatherMemory();
10551055

10561056
const isSubsession = !this._isClassicReason(reason);
10571057
let payload = this.getSessionPayload(reason, isSubsession);
@@ -1138,7 +1138,7 @@ var Impl = {
11381138
await TelemetryStorage.saveSessionData(this._getSessionDataObject());
11391139

11401140
this.addObserver("idle-daily");
1141-
MemoryTelemetry.gatherMemory();
1141+
await MemoryTelemetry.gatherMemory();
11421142

11431143
Telemetry.asyncFetchTelemetryData(function() {});
11441144

0 commit comments

Comments
 (0)