1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16/** 17 * @file 18 * @kit PerformanceAnalysisKit 19 */ 20 21/** 22 * This module provides the capability to monitor leakage of JS objects. 23 * 24 * @namespace jsLeakWatcher 25 * @syscap SystemCapability.HiviewDFX.HiChecker 26 * @since 12 27 */ 28declare namespace jsLeakWatcher { 29 /** 30 * Enable or disable jsLeakWatcher. 31 * 32 * @param { boolean } isEnable - True is enable jsLeakWatcher, false is disable jsLeakWatcher. 33 * @syscap SystemCapability.HiviewDFX.HiChecker 34 * @since 12 35 */ 36 function enable(isEnable: boolean): void; 37 38 /** 39 * Register an object that needs to be monitored. 40 * 41 * @param { object } obj - Object being monitored. 42 * @param { string } msg - Customized object information. 43 * @syscap SystemCapability.HiviewDFX.HiChecker 44 * @since 12 45 */ 46 function watch(obj: object, msg: string): void; 47 48 /** 49 * Check suspected leaked objects. 50 * 51 * @returns { string } List of suspected leaked objects in JSON format. 52 * @syscap SystemCapability.HiviewDFX.HiChecker 53 * @since 12 54 */ 55 function check(): string; 56 57 /** 58 * Dump leak list and heap snapshot. 59 * 60 * @param { string } filePath - Directory for exporting files. 61 * @returns { Array<string> } The array of exported results, index 0 is leakListFileName, index 1 is heapSnapShotFileName. 62 * @throws { BusinessError } 401 - Parameter error. The filepath is invalid. 63 * @syscap SystemCapability.HiviewDFX.HiChecker 64 * @since 12 65 */ 66 function dump(filePath: string): Array<string>; 67 68 /** 69 * Enables or disables jsLeakWatcher. 70 * 71 * This interface can detect js object memory leaks in a single call, which is more concise than the previous method 72 * requiring four function (enable,watch,check dump) calls.If there is a memory leak, the leak file will be 73 * returned to the developer through the callback function. 74 * 75 * @param { boolean } isEnabled - Whether to enable or disable jsLeankWatcher. The value true means to enable the feature, and false means the opposite. 76 * @param { Array<string> } configs - Array of types of objects to watch. 77 * @param { Callback<Array<string>> } callback - Callback invoked when an object-related memory leak is detected. 78 * @throws { BusinessError } 10801001 - The parameter isEnabled is invalid. 79 * @throws { BusinessError } 10801002 - The parameter config is invalid. 80 * @throws { BusinessError } 10801003 - The parameter callback is invalid. 81 * Input parameter error. Possible causes: 82 * 1.Mandatory parameters are left unspecified; 83 * 2.Incorrect parameter types; 84 * 3.Parameter verification failed. 85 * @syscap SystemCapability.HiviewDFX.HiChecker 86 * @since 20 87 */ 88 function enableLeakWatcher(isEnabled: boolean, configs: Array<string>, callback: Callback<Array<string>>): void 89} 90export default jsLeakWatcher; 91