mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 12:35:42 +00:00
perf(hud): read thermal zone types once instead of on every refresh (#3304)
* Read thermal zone types once for the HUD Every HUD refresh listed /sys/class/thermal and opened every zone's type file three or four times (CPU temperature, GPU temperature and the replaced-zone check). Zone types do not change while the device runs, so the sorted map is read once and reused. * Cache thermal zone types only after a scan with no read failures
This commit is contained in:
1 parent
ffb2a3d6e6
commit
25923966eb
1 file changed
+14
-6
@@ -512,7 +512,7 @@ public final class LinuxRuntime {
|
||||
public static List<File> cpuTempZones() {
|
||||
java.util.Map<String, String> replaced = replacedZoneTypes();
|
||||
List<File> zones = new ArrayList<>();
|
||||
for (java.util.Map.Entry<String, File> zone : new java.util.TreeMap<>(thermalZones()).entrySet()) {
|
||||
for (java.util.Map.Entry<String, File> zone : thermalZones().entrySet()) {
|
||||
String type = zone.getKey();
|
||||
if (type.contains("cpu") && !type.contains("gpu") && !replaced.containsKey(zone.getValue().getName())) {
|
||||
zones.add(zone.getValue());
|
||||
@@ -555,23 +555,31 @@ public final class LinuxRuntime {
|
||||
private static String thermalZone(String sensor) {
|
||||
java.util.Map<String, File> zones = thermalZones();
|
||||
File zone = zones.get(sensor);
|
||||
for (java.util.Map.Entry<String, File> e : new java.util.TreeMap<>(zones).entrySet()) {
|
||||
for (java.util.Map.Entry<String, File> e : zones.entrySet()) {
|
||||
if (zone == null && e.getKey().contains(sensor)) zone = e.getValue();
|
||||
}
|
||||
return zone != null ? new File(zone, "temp").getPath() : null;
|
||||
}
|
||||
|
||||
private static java.util.Map<String, File> thermalZones() {
|
||||
private static volatile java.util.SortedMap<String, File> thermalZoneTypes;
|
||||
|
||||
private static java.util.SortedMap<String, File> thermalZones() {
|
||||
java.util.SortedMap<String, File> known = thermalZoneTypes;
|
||||
if (known != null) return known;
|
||||
java.util.Map<String, File> byType = new java.util.HashMap<>();
|
||||
File[] zones = new File("/sys/class/thermal").listFiles((dir, n) -> n.startsWith("thermal_zone"));
|
||||
if (zones == null) return byType;
|
||||
if (zones == null) return java.util.Collections.emptySortedMap();
|
||||
boolean complete = true;
|
||||
for (File zone : zones) {
|
||||
try (java.io.BufferedReader r = new java.io.BufferedReader(new java.io.FileReader(new File(zone, "type")))) {
|
||||
byType.putIfAbsent(String.valueOf(r.readLine()).trim().toLowerCase(java.util.Locale.ROOT), zone);
|
||||
} catch (IOException ignored) {
|
||||
} catch (IOException e) {
|
||||
complete = false;
|
||||
}
|
||||
}
|
||||
return byType;
|
||||
java.util.SortedMap<String, File> sorted = java.util.Collections.unmodifiableSortedMap(new java.util.TreeMap<>(byType));
|
||||
if (complete && !sorted.isEmpty()) thermalZoneTypes = sorted;
|
||||
return sorted;
|
||||
}
|
||||
|
||||
private static void bindSystemFonts(List<String> cmd, File root) {
|
||||
|
||||
Reference in new issue
Block a user