You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
title: Android Device Performance Framework extension for Defold
6
+
brief: This manual covers how to use the Android Device Performance Framework in Defold
7
+
---
8
+
9
+
# Android Device Performance Framework extension for Defold
10
+
11
+
Android Dynamic Performance Framework (ADPF) is a set of APIs that allow games and to interact more directly with power and thermal systems of Android devices. It is possible to monitor the dynamic behavior on Android systems and optimize game performance at a sustainable level that doesn't overheat devices.
12
+
13
+
This extension currently support the following ADPF features:
14
+
15
+
*[Performance Hint API](https://developer.android.com/games/optimize/adpf/performance-hint-api)
To use ADPF in your Defold project, add a version of the ADPF extension to your `game.project` dependencies from the list of available [Releases](https://github.com/defold/extension-adpf/releases). Find the version you want, copy the URL to ZIP archive of the release and add it to the project dependencies.
21
+
22
+

23
+
24
+
Select `Project->Fetch Libraries` once you have added the version to `game.project` to download the version and make it available in your project.
25
+
26
+
27
+
## Usage
28
+
29
+
### Performance Hint API
30
+
31
+
With CPU performance hints, a game can influence dynamic CPU performance behavior to better match its needs. On most devices, Android dynamically adjusts the CPU clock speed and core type for a workload based on the previous demands. If a workload uses more CPU resources, the clock speed is increased and the workload is eventually moved to a larger core. If the workload uses less resources, then Android lowers resource allocation. With ADPF, the application or game can send an additional signal about its performance and deadlines. This helps the system ramp up more aggressively (improving performance) and lower the clocks quickly when the workload is complete (saving power usage).
32
+
33
+
The extension will create a `PerformanceHintManager` instance and a `PerformanceHintManager.Session` instance for the main thread only. The Defold extension system currently doesn't allow extensions to list and measure threads which the engine creates, for instance the audio and network threads.
34
+
35
+
```lua
36
+
37
+
-- initialize performance hint manager with a target FPS in nanosecond (60 fps)
38
+
localavailable=adpf.hint.init((1/60) *1000*1000)
39
+
40
+
-- update target FPS for the performance hint manager (30 fps)
41
+
adpf.hint.update_target_fps((1/30) *1000*1000)
42
+
43
+
-- the extension will automatically report actual work duration each frame
44
+
```
45
+
46
+
47
+
### Thermal API
48
+
49
+
The potential performance of your app is limited by the thermal state of the device, which can vary based on characteristics such as weather, recent usage, and the device's thermal design. Devices can only maintain a high level of performance for a limited amount of time before being thermally throttled. A key goal of your implementation should be to achieve performance goals without exceeding thermal limitations. Thermal API makes it possible without the need for device specific optimizations. Furthermore, when debugging performance issues, knowing if the thermal state of your device is limiting performance is important.
50
+
51
+
You can monitor the thermal state of the device by polling the `adpf.thermal.get_headroom()` function. This function predicts how long the device can maintain the current performance level without overheating. If the time is less than the amount needed to run the workload, then your game should decrease the workload to a sustainable level. For example, the game can reduce the frame rate using `adpf.hint.update_target_fps()`, or lower graphics fidelity.
52
+
53
+
54
+
```lua
55
+
-- initialize the extension to use the Thermal API
56
+
localavailable=adp.thermal.init()
57
+
ifnotavailablethen
58
+
print("Thermal API is not available")
59
+
return
60
+
end
61
+
62
+
-- get thermal status
63
+
localstatus=adpf.thermal.get_status()
64
+
65
+
-- get thermal headroom forecast for 3 seconds ahead
66
+
localheadroom=adpf.thermal.get_headroom(3)
67
+
```
68
+
69
+
70
+
71
+
## Example
72
+
73
+
[Refer to the example project](https://github.com/defold/extension-adpf/blob/master/example/example.script) to see a complete example of how the intergation works.
74
+
75
+
76
+
## Source code
77
+
78
+
The source code is available on [GitHub](https://github.com/defold/extension-adpf)
0 commit comments