11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_cicommon.skipIfInspectorDisabled(); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst { Session } = require('inspector'); 81cb0ef41Sopenharmony_ciconst { promisify } = require('util'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst sleep = promisify(setTimeout); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciasync function test() { 131cb0ef41Sopenharmony_ci const inspector = new Session(); 141cb0ef41Sopenharmony_ci inspector.connect(); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci inspector.post('Profiler.enable'); 171cb0ef41Sopenharmony_ci inspector.post('Profiler.start'); 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci await sleep(1000); 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci const { profile } = await new Promise((resolve, reject) => { 221cb0ef41Sopenharmony_ci inspector.post('Profiler.stop', (err, params) => { 231cb0ef41Sopenharmony_ci if (err) return reject(err); 241cb0ef41Sopenharmony_ci resolve(params); 251cb0ef41Sopenharmony_ci }); 261cb0ef41Sopenharmony_ci }); 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci let hasIdle = false; 291cb0ef41Sopenharmony_ci for (const node of profile.nodes) { 301cb0ef41Sopenharmony_ci if (node.callFrame.functionName === '(idle)') { 311cb0ef41Sopenharmony_ci hasIdle = true; 321cb0ef41Sopenharmony_ci break; 331cb0ef41Sopenharmony_ci } 341cb0ef41Sopenharmony_ci } 351cb0ef41Sopenharmony_ci assert(hasIdle); 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci inspector.post('Profiler.disable'); 381cb0ef41Sopenharmony_ci inspector.disconnect(); 391cb0ef41Sopenharmony_ci} 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_citest().then(common.mustCall(() => { 421cb0ef41Sopenharmony_ci console.log('Done!'); 431cb0ef41Sopenharmony_ci})); 44