Skip to content

Commit

Permalink
battery test fixed high cpu usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Moris-Shalon committed Nov 23, 2020
1 parent 2cf52d4 commit 084f155
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions battery_test_log.ps1
@@ -1,26 +1,25 @@
function WriteBatteryPercent ([int]$Append, [int]$Sleep) {
function WriteBatteryPercent ([int]$Append) {
if ($Append -ne 0) {
Write-Output (([string](Get-WmiObject Win32_Battery).EstimatedChargeRemaining) + ';' + (Get-Date -Format "%H:%m:s")) `
| Tee-Object -Filepath "battery_test_log.txt" -Append;
} else {
Write-Output (([string](Get-WmiObject Win32_Battery).EstimatedChargeRemaining) + ';' + (Get-Date -Format "%H:%m:s")) `
| Tee-Object -Filepath "battery_test_log.txt";
}
if ($Sleep -ne 0) {
Start-Sleep -s $Sleep
}
}

Write-Output "battery percentage;time" | Tee-Object -Filepath "battery_test_log.txt";
$BatteryPercent = (Get-WmiObject Win32_Battery).EstimatedChargeRemaining;
WriteBatteryPercent -Append 0 -Sleep 10;
if (-not (Test-Path -LiteralPath "battery_test_log.txt" -PathType Leaf)) {
Write-Output "battery percentage;time" | Tee-Object -Filepath "battery_test_log.txt";
WriteBatteryPercent -Append 0 -Sleep 10;
}


while ($true) { `
if ($BatteryPercent -ne (Get-WmiObject Win32_Battery).EstimatedChargeRemaining) {
$BatteryPercent = (Get-WmiObject Win32_Battery).EstimatedChargeRemaining;
WriteBatteryPercent -Append 1 -Sleep 10;
WriteBatteryPercent -Append 1;
}
Start-Sleep -s 10;
}

pause;

0 comments on commit 084f155

Please sign in to comment.