Lightweight API that allows integrate Profiler functionality into your application. Library mediates communication with the Profiler application.
- Real-time component monitoring in floating window.
- Allows to monitor following components (depends on data provided by a device). Check compatibility list here.
- CPU load and frequency
- GPU load
- RAM usage
- Network traffic
- Temperature
- Battery voltage, temperature and current
- built custom layout with
AbsoluteLayout
orFloatingLayout
- set window anchor for transitions and specific location for portrait and landscape
- set labels, formats and colors
- set window and background alpha
- set chart size
The sample application uses all features allowed by the API.
Screenshots from performance intensive applications.
1) Add snippet below to your root build.gradle file.
buildscript {
repositories {
mavenCentral()
}
}
2) Add the library as a dependency in your application's build.gradle file.
dependencies {
implementation 'app.chladek:profiler-api:1.2.4'
}
3) Initialize Profiler, create layout and show window.
final ProfilerAPI profiler = new ProfilerAPI(context);
profiler.setListener(new ProfilerEventListenerAdapter() {
@Override
public void onConnected() {
DeviceConfig[] devices = profiler.getSupportedDevices();
FloatingLayout layout = new FloatingLayout();
CPUDeviceConfig[] cpuLoad = DeviceConfigHelper.findDevices(devices, CPUDeviceConfig.class, device -> device.getMode() == Mode.LOAD);
GPUDeviceConfig gpu = DeviceConfigHelper.findDevice(devices, GPUDeviceConfig.class);
RAMDeviceConfig ram = DeviceConfigHelper.findDevice(devices, RAMDeviceConfig.class);
for (CPUDeviceConfig cpu : cpuLoad)
layout.addDevice(cpu);
if (gpu != null)
layout.addDevice(gpu);
if (ram != null)
layout.addDevice(ram);
layout.pack(Direction.RIGHT, 4, 3);
profiler.setLayout(layout);
profiler.setChartScale(0.75f);
profiler.setWindowAnchor(Orientation.LANDSCAPE, Anchor.TOP_LEFT);
profiler.setLocation(Orientation.LANDSCAPE, 50, 50);
profiler.setBackgroundAlpha(0.4f);
profiler.setVisible(true, true);
}
});
profiler.connect();
4) Handle Activity or Fragment lifecycle. See the sample application sources for more details.
@Override
protected void onResume() {
super.onResume();
profiler.getLifecycleHelper().onResume();
}
...
Library is fully compatible with Kotlin programming language, but written in Java to keep minimum library size.
operator fun FloatingLayout.plusAssign(device: DeviceConfig?) {
addDevice(device)
}
operator fun AbsoluteLayout.set(x: Int, y: Int, device: DeviceConfig) {
setDevice(x, y, device)
}
fun <T : DeviceConfig> Array<DeviceConfig>.findDevice(clazz: KClass<T>): T? {
return DeviceConfigHelper.findDevice(this, clazz.java)
}
fun <T : DeviceConfig> Array<DeviceConfig>.findDevices(clazz: KClass<T>, predicate: ((T) -> Boolean)? = null): Array<T> {
return DeviceConfigHelper.findDevices(this, clazz.java, predicate)
}
val cpuLoad = devices.findDevices(CPUDeviceConfig::class) { it.mode == CPUDeviceConfig.Mode.LOAD }
val network = devices.findDevices(NetworkDeviceConfig::class)
val floatingLayout = FloatingLayout()
floatingLayout += devices.findDevice(GPUDeviceConfig::class)
val absoluteLayout = AbsoluteLayout(width, height)
absoluteLayout[0, 0] = devices.findDevice(GPUDeviceConfig::class)
Copyright 2021 Tomas Chladek, licenced under the Apache Licence, Version 2.0.