browser_utility_profiler.js (2066B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 const { ProfilerTestUtils } = ChromeUtils.importESModule( 7 "resource://testing-common/ProfilerTestUtils.sys.mjs" 8 ); 9 10 // When running full suite, previous tests may have left some utility 11 // processes running and this might interfere with our testing. 12 add_setup(async function ensureNoExistingProcess() { 13 await killUtilityProcesses(); 14 }); 15 16 add_task(async () => { 17 const utilityPid = await startUtilityProcess(); 18 19 info("Start the profiler"); 20 await ProfilerTestUtils.startProfiler(); 21 22 let profile; 23 await TestUtils.waitForCondition(async () => { 24 profile = await Services.profiler.getProfileDataAsync(); 25 return ( 26 // Search for process name to not be disturbed by other types of utility 27 // e.g. Utility AudioDecoder 28 profile.processes.filter( 29 ps => ps.threads[0].processName === "Utility Process" 30 ).length === 1 31 ); 32 }, "Give time for the profiler to start and collect some samples"); 33 34 info(`Check that the utility process ${utilityPid} is present.`); 35 let utilityProcessIndex = profile.processes.findIndex( 36 p => p.threads[0].pid == utilityPid 37 ); 38 Assert.notEqual(utilityProcessIndex, -1, "Could find index of utility"); 39 40 Assert.equal( 41 profile.processes[utilityProcessIndex].threads[0].processType, 42 "utility", 43 "Profile has processType utility" 44 ); 45 46 Assert.equal( 47 profile.processes[utilityProcessIndex].threads[0].name, 48 "GeckoMain", 49 "Profile has correct main thread name" 50 ); 51 52 Assert.equal( 53 profile.processes[utilityProcessIndex].threads[0].processName, 54 "Utility Process", 55 "Profile has correct process name" 56 ); 57 58 Assert.greater( 59 profile.processes[utilityProcessIndex].threads.length, 60 0, 61 "The utility process should have threads" 62 ); 63 64 Assert.equal( 65 profile.threads.length, 66 1, 67 "The parent process should have only one thread" 68 ); 69 70 Services.profiler.StopProfiler(); 71 72 await cleanUtilityProcessShutdown(); 73 });