Bug 1579333 - Replace doAtLeastOnePeriodicSample() with nsIProfiler.waitOnePeriodicSampling() - r=gregtatum

Instead of requesting profiles until it "seems" to have collected something,
use `nsIProfiler.waitOnePeriodicSampling()` to really wait for a sample to be
taken.

Note that this means some test could theoretically fail if they were in fact
waiting for stack samples to appear in the first registered thread. If that
happens, these tests should be udpated to do that extra wait-for-data.

Differential Revision: https://phabricator.services.mozilla.com/D50783

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Gerald Squelart 2019-10-30 21:50:20 +00:00
Родитель 9bcbe1a229
Коммит 9afa65594d
1 изменённых файлов: 1 добавлений и 21 удалений

Просмотреть файл

@ -21,26 +21,6 @@ function startProfiler(callersSettings) {
settings.duration
);
}
/**
* This function spins on a while loop until at least one
* periodic sample is taken. Use this function to ensure
* that markers are properly collected for a test or that
* at least one sample in which we are interested is collected.
*/
async function doAtLeastOnePeriodicSample() {
async function getProfileSampleCount() {
const profile = await Services.profiler.getProfileDataAsync();
return profile.threads[0].samples.data.length;
}
const sampleCount = await getProfileSampleCount();
// Create an infinite loop until a sample has been collected.
while (true) {
if (sampleCount < (await getProfileSampleCount())) {
return;
}
}
}
/**
* This is a helper function that will stop the profiler of the browser running
@ -86,7 +66,7 @@ async function stopProfilerNowAndGetThreads(contentPid) {
* @returns {Promise}
*/
async function stopProfilerAndGetThreads(contentPid) {
await doAtLeastOnePeriodicSample();
await Services.profiler.waitOnePeriodicSampling();
return stopProfilerNowAndGetThreads(contentPid);
}