Lightweight Android telemetry library for high-load sessions such as media processing, streaming, exports, archiving, and long-running background work.
DeviceMonitor tracks:
- CPU usage and per-core usage
- CPU frequencies
- RAM and storage pressure
- Battery temperature, level, voltage, charge source, and health
- Thermal status and thermal zones
- Network type and traffic deltas
- Frame metrics (duration/jank)
- Battery power and battery drain estimation
- Thermal headroom snapshots
Data streams:
SharedFlow<DeviceSnapshot>
SharedFlow<DeviceWarningEvent>
SharedFlow<DeviceRecommendation>dependencies {
implementation("io.github.0dimidrol0:DeviceMonitor:0.4.0")
}dependencies {
implementation 'io.github.0dimidrol0:DeviceMonitor:0.4.0'
}DeviceMonitor.init(applicationContext)
val monitor = DeviceMonitor.getInstance()
monitor.start()
val snapshot = monitor.snapshotNow()
monitor.stop()Custom configuration:
DeviceMonitor.init(
appContext,
DeviceMonitorConfig.builder()
.samplePeriodMs(5_000L)
.memoryThresholdMb(512)
.batteryTemperatureThresholdC(48f)
.enableRecommendations(true)
.recommendationCooldownMs(15_000L)
.enableThermalHeadroom(true)
.enableBatteryDrain(true)
.thermalHeadroomForecastSeconds(10)
.batteryDrainHighThresholdPercentPerHour(20f)
.build()
)Recommendations are emitted from monitor.recommendations and can be applied directly to bitrate/FPS/concurrency controls.
lifecycleScope.launch {
monitor.recommendations.collect { recommendation ->
when (recommendation) {
is DeviceRecommendation.ReduceWorkload -> {
encoder.setBitrate((baseBitrate * recommendation.suggestedScale).toInt())
camera.setTargetFps((baseFps * recommendation.suggestedScale).toInt())
workerPool.setMaxConcurrency(
(baseConcurrency * recommendation.suggestedScale).toInt().coerceAtLeast(1)
)
}
is DeviceRecommendation.PauseWorkload -> encoder.pause()
is DeviceRecommendation.ResumeWorkload -> encoder.resume()
is DeviceRecommendation.DelayHeavyTask -> scheduler.retryAfter(recommendation.retryAfterMs)
}
}
}Built-in behavior:
WARMhealth ->ReduceWorkload(..., suggestedScale = 0.8f)DEGRADEDhealth ->ReduceWorkload(..., suggestedScale = 0.55f)CRITICALhealth ->PauseWorkload(...)- return from
DEGRADED/CRITICALtoNORMAL->ResumeWorkload(...)
Recommendation duplicates are throttled using recommendationCooldownMs.
sealed class DeviceWarningEvent {
data class ThermalChanged(...)
data class MemoryLow(...)
data class StorageLow(...)
data class BatteryLow(...)
data class BatteryTemperatureHigh(...)
data class CpuOverload(...)
data class ThermalHeadroomLow(...)
data class BatteryDrainHigh(...)
}DeviceSnapshot includes:
thermalZones: List<ThermalZoneReading>networkTraffic: NetworkTrafficSnapshot?batteryPower: BatteryPowerSnapshot?thermalHeadroom: ThermalHeadroomSnapshot?batteryDrain: BatteryDrainSnapshot?
thermalHeadroom and batteryDrain fields are nullable to stay safe on unsupported Android/OEM implementations.
Track a workload execution and receive a summarized report:
val session = monitor.createWorkloadSession(
name = "video-export",
type = WorkloadType.MEDIA_PROCESSING
)
session.start()
// run heavy operation
val report = session.stop()WorkloadReport includes:
durationMsstartSnapshotendSnapshotmaxRiskScorewarningCountrecommendations
./gradlew :device_monitor:testCoverage includes:
- recommendation generation and throttling
- battery drain math
- thermal headroom null safety
- config builder limits/defaults
- workload session report aggregation
- CPU throttling detection
- GPU monitoring
- per-device recommendation tuning profiles
- recommendation policy plug-ins
- richer workload session analytics
- Added Adaptive Workload Guard with
DeviceRecommendationflow. - Added
ThermalHeadroomSnapshotandBatteryDrainSnapshot. - Added warning events
ThermalHeadroomLowandBatteryDrainHigh. - Added workload APIs:
createWorkloadSession,WorkloadSession,WorkloadReport,WorkloadType. - Extended
DeviceMonitorConfigwith recommendation/headroom/drain controls.
- Added extended telemetry (
thermalZones,networkTraffic,batteryPower, frame metrics support). - Added
riskScore()/health()helpers and warning transition throttling.
Apache License 2.0
Eric Shvets
https://github.com/0dimidrol0