Tracing out loops in battery-powered devices