|
| 1 | +/* eslint-disable node-core/require-common-first, node-core/required-modules */ |
| 2 | + |
| 3 | +'use strict'; |
| 4 | + |
| 5 | +constcommon=require('./'); |
| 6 | +constfs=require('fs'); |
| 7 | +constpath=require('path'); |
| 8 | +constassert=require('assert'); |
| 9 | + |
| 10 | +functiongetCpuProfiles(dir){ |
| 11 | +constlist=fs.readdirSync(dir); |
| 12 | +returnlist |
| 13 | +.filter((file)=>file.endsWith('.cpuprofile')) |
| 14 | +.map((file)=>path.join(dir,file)); |
| 15 | +} |
| 16 | + |
| 17 | +functiongetFrames(output,file,suffix){ |
| 18 | +constdata=fs.readFileSync(file,'utf8'); |
| 19 | +constprofile=JSON.parse(data); |
| 20 | +constframes=profile.nodes.filter((i)=>{ |
| 21 | +constframe=i.callFrame; |
| 22 | +returnframe.url.endsWith(suffix); |
| 23 | +}); |
| 24 | +return{ frames,nodes: profile.nodes}; |
| 25 | +} |
| 26 | + |
| 27 | +functionverifyFrames(output,file,suffix){ |
| 28 | +const{ frames, nodes }=getFrames(output,file,suffix); |
| 29 | +if(frames.length===0){ |
| 30 | +// Show native debug output and the profile for debugging. |
| 31 | +console.log(output.stderr.toString()); |
| 32 | +console.log(nodes); |
| 33 | +} |
| 34 | +assert.notDeepStrictEqual(frames,[]); |
| 35 | +} |
| 36 | + |
| 37 | +letFIB=30; |
| 38 | +// This is based on emperial values - in the CI, on Windows the program |
| 39 | +// tend to finish too fast then we won't be able to see the profiled script |
| 40 | +// in the samples, so we need to bump the values a bit. On slower platforms |
| 41 | +// like the Pis it could take more time to complete, we need to use a |
| 42 | +// smaller value so the test would not time out. |
| 43 | +if(common.isWindows){ |
| 44 | +FIB=40; |
| 45 | +} |
| 46 | + |
| 47 | +// We need to set --cpu-interval to a smaller value to make sure we can |
| 48 | +// find our workload in the samples. 50us should be a small enough sampling |
| 49 | +// interval for this. |
| 50 | +constkCpuProfInterval=50; |
| 51 | +constenv={ |
| 52 | + ...process.env, |
| 53 | +FIB, |
| 54 | +NODE_DEBUG_NATIVE: 'INSPECTOR_PROFILER' |
| 55 | +}; |
| 56 | + |
| 57 | +module.exports={ |
| 58 | + getCpuProfiles, |
| 59 | + kCpuProfInterval, |
| 60 | + env, |
| 61 | + getFrames, |
| 62 | + verifyFrames |
| 63 | +}; |
0 commit comments