11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// Tests multiple profiles generated by --heap-prof-interval are valid. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst common = require('../common'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures'); 81cb0ef41Sopenharmony_cicommon.skipIfInspectorDisabled(); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst assert = require('assert'); 111cb0ef41Sopenharmony_ciconst fs = require('fs'); 121cb0ef41Sopenharmony_ciconst path = require('path'); 131cb0ef41Sopenharmony_ciconst { spawnSync } = require('child_process'); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciconst { 181cb0ef41Sopenharmony_ci getHeapProfiles, 191cb0ef41Sopenharmony_ci findFirstFrame, 201cb0ef41Sopenharmony_ci kHeapProfInterval, 211cb0ef41Sopenharmony_ci env 221cb0ef41Sopenharmony_ci} = require('../common/prof'); 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci{ 251cb0ef41Sopenharmony_ci tmpdir.refresh(); 261cb0ef41Sopenharmony_ci const output = spawnSync(process.execPath, [ 271cb0ef41Sopenharmony_ci '--heap-prof-interval', 281cb0ef41Sopenharmony_ci kHeapProfInterval, 291cb0ef41Sopenharmony_ci '--heap-prof-dir', 301cb0ef41Sopenharmony_ci 'prof', 311cb0ef41Sopenharmony_ci '--heap-prof', 321cb0ef41Sopenharmony_ci fixtures.path('workload', 'allocation-worker.js'), 331cb0ef41Sopenharmony_ci ], { 341cb0ef41Sopenharmony_ci cwd: tmpdir.path, 351cb0ef41Sopenharmony_ci env 361cb0ef41Sopenharmony_ci }); 371cb0ef41Sopenharmony_ci if (output.status !== 0) { 381cb0ef41Sopenharmony_ci console.log(output.stderr.toString()); 391cb0ef41Sopenharmony_ci } 401cb0ef41Sopenharmony_ci assert.strictEqual(output.status, 0); 411cb0ef41Sopenharmony_ci const dir = path.join(tmpdir.path, 'prof'); 421cb0ef41Sopenharmony_ci assert(fs.existsSync(dir)); 431cb0ef41Sopenharmony_ci const profiles = getHeapProfiles(dir); 441cb0ef41Sopenharmony_ci assert.strictEqual(profiles.length, 2); 451cb0ef41Sopenharmony_ci const profile1 = findFirstFrame(profiles[0], 'runAllocation'); 461cb0ef41Sopenharmony_ci const profile2 = findFirstFrame(profiles[1], 'runAllocation'); 471cb0ef41Sopenharmony_ci if (!profile1.frame && !profile2.frame) { 481cb0ef41Sopenharmony_ci // Show native debug output and the profile for debugging. 491cb0ef41Sopenharmony_ci console.log(output.stderr.toString()); 501cb0ef41Sopenharmony_ci console.log('heap path: ', profiles[0]); 511cb0ef41Sopenharmony_ci console.log(profile1.roots); 521cb0ef41Sopenharmony_ci console.log('heap path: ', profiles[1]); 531cb0ef41Sopenharmony_ci console.log(profile2.roots); 541cb0ef41Sopenharmony_ci } 551cb0ef41Sopenharmony_ci assert(profile1.frame || profile2.frame); 561cb0ef41Sopenharmony_ci} 57