diff --git a/zh-cn/application-dev/reference/apis/js-apis-hidebug.md b/zh-cn/application-dev/reference/apis/js-apis-hidebug.md index 0a32b4464ab06f177c195a68b21b10fd3af841d5..beda73a15b7392155a2c505a5680bfc77ffa21b2 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-hidebug.md +++ b/zh-cn/application-dev/reference/apis/js-apis-hidebug.md @@ -175,23 +175,30 @@ getServiceDump(serviceid : number, fd : number, args : Array\) : void ```js import fs from '@ohos.file.fs' import hidebug from '@ohos.hidebug' -import featureAbility from '@ohos.ability.featureAbility' - -let context = featureAbility.getContext(); -context.getFilesDir().then((data) => { - var path = data + "/serviceInfo.txt"; - console.info("output path: " + path); - let file = fs.openSync(path, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); - var serviceId = 10; - var args = new Array("allInfo"); - try { - hidebug.getServiceDump(serviceId, file.fd, args); - } catch (error) { - console.info(error.code); - console.info(error.message); - } - fs.closeSync(file); -}) +import common from '@ohos.app.ability.common' + +let applicationContext: common.Context; +try { + applicationContext = this.context.getApplicationContext(); +} catch (error) { + console.info(error.code); + console.info(error.message); +} + +var filesDir = applicationContext.filesDir; +var path = filesDir + "/serviceInfo.txt"; +console.info("output path: " + path); +let file = fs.openSync(path, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); +var serviceId = 10; +var args = new Array("allInfo"); + +try { + hidebug.getServiceDump(serviceId, file.fd, args); +} catch (error) { + console.info(error.code); + console.info(error.message); +} +fs.closeSync(file); ``` ## hidebug.startJsCpuProfiling9+