To access the functions provided, a reader must first be created. When creating the reader, it is possible to specify where the adb
application is located.
reader := CreateReader("C:/Users/Test/AppData/Local/Android/Sdk/platform-tools/adb")
If adb
is accessible via the PATH
variable using adb
, the path specification adbpath
can be left empty:
reader := CreateReader("")
The 'Reader' interface now provides the following functions:
- Read and parse memory info by using
adb shell dumpsys meminfo
- Read and parse running processes by using
adb shell ps
- Get rough trend information
This is the core functionality of the application. It first determines the process ID of the provided packagename
with the help of the adb shell pidof
call. Using the process ID and the adb shell dumpsys meminfo
command, the memory information is retrieved and parsed. For common information groups, the essential information is converted to a key-value pair.
Scan(packagename string) (map[string]int, string, error)
The endpoint uses the adb shell ps -A -o NAME
command to determine all active processes. It ignores process information enclosed by [
and ]
.
Packages() []string
For the evaluation of the storage behavior, an initial indication of the trend of storage usage is required. For performance reasons, no complete history of all measured values is kept. Instead, a low-pass filter is used to determine trends.
Trend(key string, value int) (float64, float64, float64, float64)
The method is given a key
and a current value
. For the provided key it calculates four trends:
- result #1: The change of the low-pass filter affected by the new
value
as follows:filtervalue = filtervalue * 0.999 + value * 0.001
(0.1%) - result #2: The change of the low-pass filter affected by the new
value
as follows:filtervalue = filtervalue * 0.99 + value * 0.01
(1%) - result #3: The change of the low-pass filter affected by the new
value
as follows:filtervalue = filtervalue * 0.9 + value * 0.1
(10%) - result #4: The change of the
value
, compared to the last measured one
This is not an exact trend calculation, especially since the trend information is lower the "slower" a low-pass filter reacts. Nevertheless, rough trends allow an overview of the memory behavior.