browser_memory_distribution_telemetry.js (2563B)
1 "use strict"; 2 3 const { TelemetrySession } = ChromeUtils.importESModule( 4 "resource://gre/modules/TelemetrySession.sys.mjs" 5 ); 6 7 const DUMMY_PAGE_DATA_URI = `data:text/html, 8 <html> 9 <head> 10 <meta charset="utf-8"/> 11 <title>Dummy</title> 12 </head> 13 <body> 14 <h1 id='header'>Just a regular everyday normal page.</h1> 15 </body> 16 </html>`; 17 18 /** 19 * Tests the MEMORY_DISTRIBUTION_AMONG_CONTENT probe by opening a few tabs, then triggering 20 * the memory probes and waiting for the "gather-memory-telemetry-finished" notification. 21 */ 22 add_task(async function test_memory_distribution() { 23 waitForExplicitFinish(); 24 25 if (SpecialPowers.getIntPref("dom.ipc.processCount", 1) < 2) { 26 ok(true, "Skip this test if e10s-multi is disabled."); 27 finish(); 28 return; 29 } 30 31 Services.telemetry.canRecordExtended = true; 32 33 let histogram = Services.telemetry.getKeyedHistogramById( 34 "MEMORY_DISTRIBUTION_AMONG_CONTENT" 35 ); 36 histogram.clear(); 37 38 let tab1 = await BrowserTestUtils.openNewForegroundTab( 39 gBrowser, 40 DUMMY_PAGE_DATA_URI 41 ); 42 let tab2 = await BrowserTestUtils.openNewForegroundTab( 43 gBrowser, 44 DUMMY_PAGE_DATA_URI 45 ); 46 let tab3 = await BrowserTestUtils.openNewForegroundTab( 47 gBrowser, 48 DUMMY_PAGE_DATA_URI 49 ); 50 51 let finishedGathering = new Promise(resolve => { 52 let obs = function () { 53 Services.obs.removeObserver(obs, "gather-memory-telemetry-finished"); 54 resolve(); 55 }; 56 Services.obs.addObserver(obs, "gather-memory-telemetry-finished"); 57 }); 58 59 TelemetrySession.getPayload(); 60 61 await finishedGathering; 62 63 let s = histogram.snapshot(); 64 ok("0 - 10 tabs" in s, "We should have some samples by now in this bucket."); 65 for (var key in s) { 66 is(key, "0 - 10 tabs"); 67 let fewTabsSnapshot = s[key]; 68 Assert.greater( 69 fewTabsSnapshot.sum, 70 0, 71 "Zero difference between all the content processes is unlikely, what happened?" 72 ); 73 Assert.less( 74 fewTabsSnapshot.sum, 75 80, 76 "20 percentage difference on average is unlikely, what happened?" 77 ); 78 let values = fewTabsSnapshot.values; 79 for (let [bucket, value] of Object.entries(values)) { 80 if (bucket >= 10) { 81 // If this check fails it means that one of the content processes uses at least 20% more or 20% less than the mean. 82 is(value, 0, "All the buckets above 10 should be empty"); 83 } 84 } 85 } 86 87 histogram.clear(); 88 89 BrowserTestUtils.removeTab(tab3); 90 BrowserTestUtils.removeTab(tab2); 91 BrowserTestUtils.removeTab(tab1); 92 finish(); 93 });