Skip to content

Commit

Permalink
Reduce dmidecode calls
Browse files Browse the repository at this point in the history
  • Loading branch information
realies committed Oct 11, 2017
1 parent 4b48bf7 commit 472d699
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions plugins/dynamix/include/SystemInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,12 @@ function write($number) {
// Physical Memory Array (16) usually one of these for a desktop-class motherboard but higher-end xeon motherboards
// might have two or more of these. The trick is to filter out any Flash/Bios types by matching on GB
// Sum up all the Physical Memory Arrays to get the motherboard's total memory capacity
$memory_maximum = exec("dmidecode -t 16 | awk -F: '/^\tMaximum Capacity: [0-9]+ GB$/{t+=$2} END{print t}'");
// Read the physical memory info again and extract the error correction type. If the type is "None",
// empty the correction type string, otherwise insert a whitespace at the end of it as a hacky separator.
$ecc_support = exec("dmidecode -t 16 | awk -F': ' '/^\tError Correction Type: / {print $2}'");
if($ecc_support == "None") $ecc_support = ""; else $ecc_support = $ecc_support." ";
$star = "";
// Extract error correction type, if none, do not include additional information in the output
list($memory_maximum, $ecc_support) = array_map("trim", explode("#", exec("dmidecode -t16|awk -F: '/^\tMaximum Capacity: [0-9]+ GB$/{t+=$2};/^\tError Correction Type:/{e=$2} END{print t\"#\"e}'")));
// If maximum < installed then roundup maximum to the next power of 2 size of installed. E.g. 6 -> 8 or 12 -> 16
if ($memory_maximum < $memory_installed) {$memory_maximum = pow(2,ceil(log($memory_installed)/log(2))); $star = "*";}
echo "$memory_installed GB $ecc_support(max. installable capacity $memory_maximum GB)$star";
$star = "";
echo "$memory_installed GB ".($ecc_support == "None" ? "" : "$ecc_support ")."(max. installable capacity $memory_maximum GB)$star";
?>
</div>
<div><span class="key">Network:</span>
Expand Down

0 comments on commit 472d699

Please sign in to comment.