#!/usr/bin/env bash # MobileGL - tools/device_bench/disagg/devstate.sh # Copyright (c) 2025-2026 MobileGL-Dev # Licensed under the GNU Lesser General Public License v3.0: # https://www.gnu.org/licenses/gpl-3.0.txt # https://www.gnu.org/licenses/lgpl-3.0.txt # SPDX-License-Identifier: LGPL-3.0-only # End of Source File Header # devstate.sh : the one-line device state every reported number carries (P15 measurement rules). # Needs /freq.txt + pin.txt (freq_sampler / pin_clocks show). Writes /profile.txt, # /valid.txt and /state.txt, and prints the state line: # STATE profile=(cpu/little/gpu MHz) daemons=<..> swap=<..> anland= set -u export MSYS_NO_PATHCONV=1 out="$1"; kind="${2:-fcl}"; SER="${SER:-HA27Q3LQ}"; HERE="$(cd "$(dirname "$0")" && pwd)" FCL=com.tungsten.fcl.mgdebug.debug su_sh() { adb -s "$SER" shell "su -c '$1'"; } su_sh "cat /data/local/tmp/p15-bench-profile 2>/dev/null || echo profile=unpinned" | tr -d '\r' > "$out/profile.txt" python "$(cygpath -w "$HERE/freqcheck.py" 2>/dev/null || echo "$HERE/freqcheck.py")" "$(cygpath -w "$out/freq.txt")" "$(cygpath -w "$out/pin.txt")" > "$out/valid.txt" 2>&1 daemons=$(su_sh "test -f /data/local/tmp/p15-bench-session && echo stopped\(\$(grep -c \"^svc \" /data/local/tmp/p15-bench-session)\) || echo running" | tr -d '\r') ver=$(adb -s "$SER" exec-out "su -c 'cat /data/data/$FCL/files/config.json'" 2>/dev/null | grep -o '"selectedMinecraftVersion": *"[^"][^"]*"' | head -1 | sed 's/.*: *"//; s/"$//') swap=$(su_sh "grep -h enableVsync /sdcard/FCL/.minecraft/versions/$ver/options.txt 2>/dev/null" | tr -d '\r' | sed 's/enableVsync://') anland=$(adb -s "$SER" shell pidof com.anland.consumer.mobilegl | tr -dc '0-9' | head -c 8) p=$(cat "$out/profile.txt") pn=$(echo "$p" | sed -n 's/.*profile=\([^ ]*\).*/\1/p'); pc=$(echo "$p" | sed -n 's/.*cpu=\([0-9]*\).*/\1/p'); pl=$(echo "$p" | sed -n 's/.*little=\([0-9]*\).*/\1/p'); pg=$(echo "$p" | sed -n 's/.*gpu=\([0-9]*\).*/\1/p') [ "$kind" = trace ] && { ver=-; swap=pbuffer; } line="STATE profile=${pn:-unpinned}(${pc:+$((pc/1000))/$((pl/1000))/$((pg/1000000))MHz}) $(head -1 "$out/valid.txt") daemons=$daemons mc=$ver swap=${swap:-?} anland=$([ -n "$anland" ] && echo on || echo off) $(cat "$out/env.txt" 2>/dev/null)" echo "$line" > "$out/state.txt"; echo "$line"