1# @ohos.resourceschedule.systemload (System Load Level Management) 2 3The **systemload** module allows the system to determine the system load level based on the current temperature, load, and scenario, and notifies registered applications of level changes, if any. 4 5> **NOTE** 6> 7> - The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8 9## Modules to Import 10 11``` 12import { systemLoad } from '@kit.BasicServicesKit'; 13``` 14 15## systemLoad.on('systemLoadChange') 16 17on(type: 'systemLoadChange', callback: Callback\<SystemLoadLevel>): void 18 19Enables listening for system load level changes. This API uses an asynchronous callback to return the result. 20 21**System capability**: SystemCapability.ResourceSchedule.SystemLoad 22 23**Parameters** 24 25| Name | Type | Mandatory | Description | 26| --------- | --------------------------- | ---- | ---------------------------------------- | 27| type | string | Yes | Change type. This parameter has a fixed value of **systemLoadChange**. | 28| callback | AsyncCallback<[SystemLoadLevel](#systemloadlevel)> | Yes | Callback used to return the system load level.| 29 30**Error codes** 31 32For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 33 34| ID | Error Message | 35| ---- | --------------------- | 36| 401 | Parameter error. Possible cause: 1. Callback parameter error; 2. Register a exist callback type; 3. Parameter verification failed. | 37 38**Example** 39 40```ts 41import { systemLoad } from '@kit.BasicServicesKit'; 42 43function onSystemLoadChange(res: systemLoad.SystemLoadLevel) { 44 console.log(`system load changed, current level ` + res); 45} 46 47try { 48 systemLoad.on('systemLoadChange', onSystemLoadChange); 49 console.log(`register systemload callback succeeded. `); 50} catch (err) { 51 console.error(`register systemload callback failed: ` + JSON.stringify(err)); 52} 53``` 54 55## systemLoad.off('systemLoadChange') 56 57off(type: 'systemLoadChange', callback?: Callback\<SystemLoadLevel>): void 58 59Disables listening for system load level changes. This API uses an asynchronous callback to return the result. 60 61**System capability**: SystemCapability.ResourceSchedule.SystemLoad 62 63**Parameters** 64 65| Name | Type | Mandatory | Description | 66| --------- | --------------------------- | ---- | ---------------------------------------- | 67| type | string | Yes | Change type. This parameter has a fixed value of **systemLoadChange**. | 68| callback | AsyncCallback<[SystemLoadLevel](#systemloadlevel)> | No | Callback used to return the system load level.| 69**Error codes** 70 71For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 72 73| ID | Error Message | 74| ---- | --------------------- | 75| 401 | Parameter error. Possible cause: 1. Callback parameter error; 2. Register a exist callback type; 3. Parameter verification failed. | 76 77**Example** 78 79```ts 80import { systemLoad } from '@kit.BasicServicesKit'; 81 82function onSystemLoadChange(res: systemLoad.SystemLoadLevel) { 83 console.log(`system load changed, current level ` + res); 84} 85 86try { 87 systemLoad.off('systemLoadChange', onSystemLoadChange); 88 console.log(`unregister systemload callback succeeded:. `); 89} catch (err) { 90 console.error(`unregister systemload callback failed: ` + JSON.stringify(err)); 91} 92``` 93 94## systemLoad.getLevel 95 96getLevel(): Promise<[SystemLoadLevel](#systemloadlevel)> 97 98Obtains the system load level. This API uses a promise to return the result. 99 100**System capability**: SystemCapability.ResourceSchedule.SystemLoad 101 102**Return value** 103 104| Type | Description | 105| --------------------- | ---------------------------------------- | 106| Promise<[SystemLoadLevel](#systemloadlevel)> | Promise used to return the system load level.| 107 108**Example** 109 110```ts 111import { BusinessError } from '@kit.BasicServicesKit'; 112import { systemLoad } from '@kit.BasicServicesKit'; 113 114systemLoad.getLevel().then((res: systemLoad.SystemLoadLevel) => { 115 console.log(`getLevel promise succeeded. result: ` + JSON.stringify(res)); 116}).catch((err: BusinessError) => { 117 console.error(`getLevel promise failed. code is ${err.code} message is ${err.message}`); 118}) 119``` 120 121## SystemLoadLevel 122 123Enumerates system load levels. 124 125**System capability**: SystemCapability.ResourceSchedule.SystemLoad 126 127| Name | Value | Description | 128| ----------------------- | ---- | --------------------- | 129| LOW | 0 | The device temperature and load are low. | 130| NORMAL | 1 | The device temperature and load are normal but are approaching the medium range. You need to downgrade or reduce the load of imperceptible services. | 131| MEDIUM | 2 | One or more device temperature or load items are slightly high, or the device temperature is in the medium range but the load is high. You need to stop or delay some imperceptible services. | 132| HIGH | 3 | The device temperature and load are relatively high. You need to stop all imperceptible services and downgrade or reduce the load of non-critical services. | 133| OVERHEATED | 4 | The device temperature and load are high, and the device is overheated. You need to stop all imperceptible services and downgrade or reduce the load of major foreground services. | 134| WARNING | 5 | The device is overheated or heavily loaded and is about to enter the Warning state. You need to stop all imperceptible services and downgrade major foreground services to the maximum extent. | 135| EMERGENCY | 6 | The device is overheated or significantly heavy loaded and is about to enter the Emergency state. You need to stop all services except those for fundamental use. | 136| ESCAPE | 7 | The device is overheated or extremely heavy loaded and is about to enter the Escape state. You need to stop all services and take necessary emergency measures such as data backup. | 137