summaryrefslogtreecommitdiffstats
path: root/pts-core/functions/pts-functions_system_parsing.php
diff options
context:
space:
mode:
authorMichael Larabel <michael@phx-laptop.(none)>2008-10-02 09:51:54 -0400
committerMichael Larabel <michael@phx-laptop.(none)>2008-10-02 09:51:54 -0400
commit29ce4d74394a0646a4edfbe7b33d97f37fd6e952 (patch)
treedb3d6a1c6e1bcf2aa8e21d6d11dd1b04474af8a1 /pts-core/functions/pts-functions_system_parsing.php
parente183e7477d45c29032e320f9fd4284d4e8562e96 (diff)
downloadphoronix-test-suite-upstream-29ce4d74394a0646a4edfbe7b33d97f37fd6e952.tar.gz
phoronix-test-suite-upstream-29ce4d74394a0646a4edfbe7b33d97f37fd6e952.tar.xz
phoronix-test-suite-upstream-29ce4d74394a0646a4edfbe7b33d97f37fd6e952.zip
pts-core: Cleanup pts-functions_system.php and move most of it to
pts-functions_system_hardware.php and pts-functions_system_software.php
Diffstat (limited to 'pts-core/functions/pts-functions_system_parsing.php')
-rw-r--r--pts-core/functions/pts-functions_system_parsing.php48
1 files changed, 48 insertions, 0 deletions
diff --git a/pts-core/functions/pts-functions_system_parsing.php b/pts-core/functions/pts-functions_system_parsing.php
index 1e76a50..842e5e0 100644
--- a/pts-core/functions/pts-functions_system_parsing.php
+++ b/pts-core/functions/pts-functions_system_parsing.php
@@ -469,5 +469,53 @@ function read_ati_overdrive($attribute, $adapter = 0)
return $value;
}
+function read_system_memory_usage($TYPE = "TOTAL", $READ = "USED")
+{
+ // Reads system memory usage
+ $mem = explode("\n", shell_exec("free -t -m 2>&1"));
+ $grab_line = null;
+ $mem_usage = -1;
+
+ for($i = 0; $i < count($mem) && empty($grab_line); $i++)
+ {
+ $line_parts = explode(":", $mem[$i]);
+
+ if(count($line_parts) == 2)
+ {
+ $line_type = trim($line_parts[0]);
+
+ if($TYPE == "MEMORY" && $line_type == "Mem")
+ $grab_line = $line_parts[1];
+ else if($TYPE == "SWAP" && $line_type == "Swap")
+ $grab_line = $line_parts[1];
+ else if($TYPE == "TOTAL" && $line_type == "Total")
+ $grab_line = $line_parts[1];
+ }
+ }
+
+ if(!empty($grab_line))
+ {
+ $grab_line = trim(preg_replace("/\s+/", " ", $grab_line));
+ $mem_parts = explode(" ", $grab_line);
+
+ if($READ == "USED")
+ {
+ if(count($mem_parts) >= 2 && is_numeric($mem_parts[1]))
+ $mem_usage = $mem_parts[1];
+ }
+ else if($READ == "TOTAL")
+ {
+ if(count($mem_parts) >= 1 && is_numeric($mem_parts[0]))
+ $mem_usage = $mem_parts[0];
+ }
+ else if($READ == "FREE")
+ {
+ if(count($mem_parts) >= 3 && is_numeric($mem_parts[2]))
+ $mem_usage = $mem_parts[2];
+ }
+ }
+
+ return $mem_usage;
+}
?>