From 61859e8fc94159a6d894f988a30e8868748ca2e4 Mon Sep 17 00:00:00 2001 From: Gemorroj Date: Mon, 19 Mar 2018 18:50:41 +0300 Subject: [PATCH] reworked windows cpu info --- bin/windows/NetworkAdapter.ps1 | 2 +- .../PerfFormattedData_PerfOS_Processor.ps1 | 1 + bin/windows/Processor.ps1 | 2 +- src/OS/Linux.php | 2 +- src/OS/Windows.php | 34 +++++-------------- 5 files changed, 13 insertions(+), 28 deletions(-) create mode 100644 bin/windows/PerfFormattedData_PerfOS_Processor.ps1 diff --git a/bin/windows/NetworkAdapter.ps1 b/bin/windows/NetworkAdapter.ps1 index c5cec4cf..810616d2 100644 --- a/bin/windows/NetworkAdapter.ps1 +++ b/bin/windows/NetworkAdapter.ps1 @@ -1 +1 @@ -return Get-WmiObject -Class Win32_NetworkAdapter Name, AdapterType, NetConnectionStatus, GUID, PhysicalAdapter | ConvertTo-Json -Compress +return Get-WmiObject -Class Win32_NetworkAdapter Name, AdapterType, NetConnectionStatus, GUID, PhysicalAdapter | Where-Object {$_.PhysicalAdapter -eq 'True'} | ConvertTo-Json -Compress diff --git a/bin/windows/PerfFormattedData_PerfOS_Processor.ps1 b/bin/windows/PerfFormattedData_PerfOS_Processor.ps1 new file mode 100644 index 00000000..d26272b3 --- /dev/null +++ b/bin/windows/PerfFormattedData_PerfOS_Processor.ps1 @@ -0,0 +1 @@ +return Get-WmiObject -Class Win32_PerfFormattedData_PerfOS_Processor Name, Caption, PercentProcessorTime | Where-Object {$_.Name -ne '_Total'} | ConvertTo-Json -Compress diff --git a/bin/windows/Processor.ps1 b/bin/windows/Processor.ps1 index 5db77ddb..b71fe4fd 100644 --- a/bin/windows/Processor.ps1 +++ b/bin/windows/Processor.ps1 @@ -1 +1 @@ -return Get-WmiObject -Class Win32_Processor LoadPercentage, Caption, Name, Manufacturer, CurrentClockSpeed, LoadPercentage, NumberOfCores, Architecture | ConvertTo-Json -Compress +return Get-WmiObject -Class Win32_Processor LoadPercentage, Caption, Name, SystemName, Manufacturer, CurrentClockSpeed, LoadPercentage, NumberOfCores, Architecture | ConvertTo-Json -Compress diff --git a/src/OS/Linux.php b/src/OS/Linux.php index 22fc98c4..70e873a4 100644 --- a/src/OS/Linux.php +++ b/src/OS/Linux.php @@ -308,7 +308,7 @@ public function getCPU() // ID. Corresponds to percentage if enabled below case 'processor': if (isset($this->cpu_percent['cpus'][$value])) { - $cur_cpu['usage_percentage'] = $this->cpu_percent['cpus'][$value]; + $cur_cpu['LoadPercentage'] = $this->cpu_percent['cpus'][$value]; } break; } diff --git a/src/OS/Windows.php b/src/OS/Windows.php index f0dade28..49b5862b 100644 --- a/src/OS/Windows.php +++ b/src/OS/Windows.php @@ -126,20 +126,16 @@ public function getRam() public function getCPU() { $cpus = []; - $info = $this->getInfo('Processor'); - if (!isset($info[0])) { - $info = [$info]; // if one processor convert to many processors - } + $cpuInfo = $this->getInfo('Processor'); + $cpuDatas = $this->getInfo('PerfFormattedData_PerfOS_Processor'); - foreach ($info as $cpuInfo) { + foreach ($cpuDatas as $cpuData) { $cpus[] = array( 'Caption' => $cpuInfo['Caption'], 'Model' => $cpuInfo['Name'], 'Vendor' => $cpuInfo['Manufacturer'], 'MHz' => $cpuInfo['CurrentClockSpeed'], - 'LoadPercentage' => $cpuInfo['LoadPercentage'], - 'Cores' => $cpuInfo['NumberOfCores'], - //'Threads' => $cpuInfo['ThreadCount'], // Windows 7 - not exists, Windows 10 - exists + 'LoadPercentage' => $cpuData['PercentProcessorTime'], ); } @@ -311,22 +307,13 @@ public function getDevs() /** * getLoad. * - * @return array of current system load values + * @return int */ - public function getLoad() + public function getCPUUsage() { - $cpus = []; - - $info = $this->getInfo('Processor'); - if (!isset($info[0])) { - $info = [$info]; // if one processor convert to many processors - } - - foreach ($info as $cpuInfo) { - $cpus[] = $cpuInfo['LoadPercentage']; - } + $cpuInfo = $this->getInfo('Processor'); - return array(round(array_sum($cpus) / count($cpus), 2)); + return $cpuInfo['LoadPercentage']; } /** @@ -499,11 +486,8 @@ public function getServices() public function getCPUArchitecture() { $info = $this->getInfo('Processor'); - if (!isset($info[0])) { - $info = [$info]; // if one processor convert to many processors - } - switch ($info[0]['Architecture']) { + switch ($info['Architecture']) { case '0': return 'x86'; case '1':