Add throttling status tracking
This commit is contained in:
+38
-19
@@ -117,23 +117,12 @@ function dmesg_log(): array
|
||||
];
|
||||
}
|
||||
|
||||
function low_voltage_status(): array
|
||||
function throttled_event_status(?int $flags, string $raw, int $activeBit, int $seenBit, string $statePath): array
|
||||
{
|
||||
$result = sh(['/usr/bin/vcgencmd', 'get_throttled'], false, 3);
|
||||
$raw = trim((string)$result['out']);
|
||||
$flags = null;
|
||||
|
||||
if ((int)$result['code'] === 0 && preg_match('/throttled=0x([0-9a-f]+)/i', $raw, $m)) {
|
||||
$flags = hexdec($m[1]);
|
||||
}
|
||||
|
||||
$now = time();
|
||||
$active = $flags !== null && (bool)($flags & 0x1);
|
||||
$seen = $flags !== null && (bool)($flags & 0x10000);
|
||||
$freqCapped = $flags !== null && (bool)($flags & 0x2);
|
||||
$throttled = $flags !== null && (bool)($flags & 0x4);
|
||||
$softTempLimit = $flags !== null && (bool)($flags & 0x8);
|
||||
$statePath = '/tmp/control-low-voltage-state.json';
|
||||
$active = $flags !== null && (bool)($flags & $activeBit);
|
||||
$seen = $flags !== null && (bool)($flags & $seenBit);
|
||||
|
||||
if (is_file($statePath) && !is_writable($statePath)) {
|
||||
@chmod($statePath, 0666);
|
||||
}
|
||||
@@ -206,9 +195,6 @@ function low_voltage_status(): array
|
||||
'flags' => $flags,
|
||||
'active' => $active,
|
||||
'seen_since_boot' => $seen,
|
||||
'freq_capped' => $freqCapped,
|
||||
'throttled' => $throttled,
|
||||
'soft_temp_limit' => $softTempLimit,
|
||||
'active_since' => $dateValue($state['active_since'] ?? null),
|
||||
'last_detected_at' => $dateValue($state['last_detected_at'] ?? null),
|
||||
'last_cleared_at' => $dateValue($state['last_cleared_at'] ?? null),
|
||||
@@ -218,6 +204,37 @@ function low_voltage_status(): array
|
||||
];
|
||||
}
|
||||
|
||||
function throttled_statuses(): array
|
||||
{
|
||||
$result = sh(['/usr/bin/vcgencmd', 'get_throttled'], false, 3);
|
||||
$raw = trim((string)$result['out']);
|
||||
$flags = null;
|
||||
|
||||
if ((int)$result['code'] === 0 && preg_match('/throttled=0x([0-9a-f]+)/i', $raw, $m)) {
|
||||
$flags = hexdec($m[1]);
|
||||
}
|
||||
|
||||
$lowVoltage = throttled_event_status($flags, $raw, 0x1, 0x10000, '/tmp/control-low-voltage-state.json');
|
||||
$throttling = throttled_event_status($flags, $raw, 0x4, 0x40000, '/tmp/control-throttling-state.json');
|
||||
|
||||
$lowVoltage['freq_capped'] = $flags !== null && (bool)($flags & 0x2);
|
||||
$lowVoltage['throttled'] = $flags !== null && (bool)($flags & 0x4);
|
||||
$lowVoltage['soft_temp_limit'] = $flags !== null && (bool)($flags & 0x8);
|
||||
$throttling['low_voltage'] = $flags !== null && (bool)($flags & 0x1);
|
||||
$throttling['freq_capped'] = $flags !== null && (bool)($flags & 0x2);
|
||||
$throttling['soft_temp_limit'] = $flags !== null && (bool)($flags & 0x8);
|
||||
|
||||
return [
|
||||
'low_voltage' => $lowVoltage,
|
||||
'throttling' => $throttling,
|
||||
];
|
||||
}
|
||||
|
||||
function low_voltage_status(): array
|
||||
{
|
||||
return throttled_statuses()['low_voltage'];
|
||||
}
|
||||
|
||||
function fan_paths(): array
|
||||
{
|
||||
$candidates = glob('/sys/devices/platform/cooling_fan/hwmon/hwmon*/pwm1') ?: [];
|
||||
@@ -1792,6 +1809,7 @@ function collect_snapshot(bool $applyFan = true): array
|
||||
$mem = mem_info();
|
||||
$disk = disk_info('/');
|
||||
$os = os_info();
|
||||
$throttledStatuses = throttled_statuses();
|
||||
$cpuPower = $applyFan ? cpu_power_status() : [
|
||||
'voltage' => isset($latest['cpu_voltage']) ? (float)$latest['cpu_voltage'] : null,
|
||||
'watts' => isset($latest['cpu_watts']) ? (float)$latest['cpu_watts'] : null,
|
||||
@@ -1849,7 +1867,8 @@ function collect_snapshot(bool $applyFan = true): array
|
||||
'active_users' => active_user_info(),
|
||||
'memory' => $mem,
|
||||
'disk' => $disk,
|
||||
'low_voltage' => low_voltage_status(),
|
||||
'low_voltage' => $throttledStatuses['low_voltage'],
|
||||
'throttling' => $throttledStatuses['throttling'],
|
||||
]);
|
||||
|
||||
$history = add_battery_remaining_history(sensor_history(240));
|
||||
|
||||
Reference in New Issue
Block a user