Skip to content

Commit

Permalink
reworked windows cpu info
Browse files Browse the repository at this point in the history
  • Loading branch information
Gemorroj committed Mar 19, 2018
1 parent d8b8ad9 commit 61859e8
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 28 deletions.
2 changes: 1 addition & 1 deletion bin/windows/NetworkAdapter.ps1
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions bin/windows/PerfFormattedData_PerfOS_Processor.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
return Get-WmiObject -Class Win32_PerfFormattedData_PerfOS_Processor Name, Caption, PercentProcessorTime | Where-Object {$_.Name -ne '_Total'} | ConvertTo-Json -Compress
2 changes: 1 addition & 1 deletion bin/windows/Processor.ps1
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/OS/Linux.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
34 changes: 9 additions & 25 deletions src/OS/Windows.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
);
}

Expand Down Expand Up @@ -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'];
}

/**
Expand Down Expand Up @@ -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':
Expand Down

0 comments on commit 61859e8

Please sign in to comment.