diff options
author | Michael Larabel <michael@phx-laptop.(none)> | 2008-10-02 09:51:54 -0400 |
---|---|---|
committer | Michael Larabel <michael@phx-laptop.(none)> | 2008-10-02 09:51:54 -0400 |
commit | 29ce4d74394a0646a4edfbe7b33d97f37fd6e952 (patch) | |
tree | db3d6a1c6e1bcf2aa8e21d6d11dd1b04474af8a1 /pts-core/functions/pts-functions_system.php | |
parent | e183e7477d45c29032e320f9fd4284d4e8562e96 (diff) | |
download | phoronix-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.php')
-rw-r--r-- | pts-core/functions/pts-functions_system.php | 441 |
1 files changed, 5 insertions, 436 deletions
diff --git a/pts-core/functions/pts-functions_system.php b/pts-core/functions/pts-functions_system.php index 2df6417..892e169 100644 --- a/pts-core/functions/pts-functions_system.php +++ b/pts-core/functions/pts-functions_system.php @@ -5,7 +5,7 @@ URLs: http://www.phoronix.com, http://www.phoronix-test-suite.com/ Copyright (C) 2008, Phoronix Media Copyright (C) 2008, Michael Larabel - pts-functions_system.php: System-level (Linux) functions, includes the parsing of the installed system hardware/software. + pts-functions_system.php: Include system functions. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,445 +21,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ +require_once("pts-core/functions/pts-functions_system_software.php"); +require_once("pts-core/functions/pts-functions_system_hardware.php"); + require_once("pts-core/functions/pts-functions_system_parsing.php"); require_once("pts-core/functions/pts-functions_system_cpu.php"); require_once("pts-core/functions/pts-functions_system_graphics.php"); -function pts_process_running_string($process_arr) -{ - // Format a nice string that shows processes running - $p = array(); - $p_string = ""; - - if(!is_array($process_arr)) - $process_arr = array($process_arr); - - foreach($process_arr as $p_name => $p_process) - { - if(!is_array($p_process)) - $p_process = array($p_process); - - foreach($p_process as $process) - if(pts_process_running_bool($process)) - array_push($p, $p_name); - } - - $p = array_keys(array_flip($p)); - - if(($p_count = count($p)) > 0) - { - for($i = 0; $i < $p_count; $i++) - { - $p_string .= $p[$i]; - - if($i != ($p_count - 1) && $p_count > 2) - $p_string .= ","; - $p_string .= " "; - - if($i == ($p_count - 2)) - $p_string .= "and "; - } - - if($p_count == 1) - $p_string .= "was"; - else - $p_string .= "were"; - - $p_string .= " running on this system. "; - } - - return $p_string; -} -function pts_process_running_bool($process) -{ - // Checks if process is running on the system - $running = shell_exec("ps -C " . strtolower($process) . " 2>&1"); - $running = trim(str_replace(array("PID", "TTY", "TIME", "CMD"), "", $running)); - - if(!empty($running)) - $running = true; - else - $running = false; - - return $running; -} -function pts_user_name() -{ - // Gets the system user's name - if(function_exists("posix_getpwuid") && function_exists("posix_getuid")) - { - $userinfo = posix_getpwuid(posix_getuid()); - $username = $userinfo["name"]; - } - else - { - $username = trim(getenv("USERNAME")); - } - - return $username; -} -function pts_disk_total() -{ - // Returns amoung of disk space - return ceil(disk_total_space("/") / 1073741824); -} -function memory_mb_capacity() -{ - // Returns physical memory capacity - if(is_file("/proc/meminfo")) - { - $info = file_get_contents("/proc/meminfo"); - $info = substr($info, strpos($info, "MemTotal:") + 9); - $info = intval(trim(substr($info, 0, strpos($info, "kB")))); - $info = floor($info / 1024); - } - else if(IS_SOLARIS) - { - $info = shell_exec("prtconf | grep Memory"); - $info = substr($info, strpos($info, ":") + 2); - $info = substr($info, 0, strpos($info, "Megabytes")); - } - else if(IS_BSD) - { - $info = floor(read_sysctl("hw.realmem") / 1048576); - } - else - $info = "Unknown"; - - return $info; -} -function os_vendor() -{ - // Returns OS vendor - return read_lsb("Distributor ID"); -} -function os_version() -{ - // Returns OS version - return read_lsb("Release"); -} -function kernel_string() -{ - // Returns kernel - return trim(shell_exec("uname -r 2>&1")); -} -function kernel_arch() -{ - // Find out the kernel archiecture - $kernel_arch = trim(shell_exec("uname -m 2>&1")); - - if($kernel_arch == "X86-64") - $kernel_arch = "x86_64"; - else if($kernel_arch == "i86pc") - $kernel_arch = "i686"; - - return $kernel_arch; -} -function motherboard_chipset_string() -{ - // Returns motherboard chipset - $info = read_pci("Host bridge"); - - if(count(explode(" ", $info)) == 1) - { - $bridge = read_pci(array("Bridge", "PCI bridge")); - - if($bridge != "Unknown") - { - $match = false; - $break_words = array("Ethernet", "PCI", "High", "USB"); - - for($i = 0; $i < count($break_words) && !$match; $i++) - { - if(($pos = strpos($bridge, $break_words[$i])) > 0) - { - $bridge = trim(substr($bridge, 0, $pos)); - $info = $bridge; - $match = true; - } - } - } - } - - if(isset($bridge) && $bridge != "Unknown") - { - // Attempt to detect Southbridge (if applicable) - $southbridge = read_pci(array("ISA bridge", "SATA controller"), FALSE); - - if(($start_cut = strpos($southbridge, "(")) > 0 && ($end_cut = strpos($southbridge, ")", $start_cut + 1)) > 0) - { - $southbridge_extract = substr($southbridge, $start_cut + 1, $end_cut - $start_cut - 1); - - if(strpos($southbridge_extract, "rev") === FALSE) - { - $southbridge_extract = explode(" ", $southbridge_extract); - $southbridge_clean = $southbridge_extract[0]; - - $info .= " + " . $southbridge_clean; - } - } - else if(($start_cut = strpos($southbridge, "SB")) > 0) - { - $southbridge_extract = substr($southbridge, $start_cut); - $southbridge_extract = substr($southbridge_extract, 0, strpos($southbridge_extract, " ")); - - $info .= " + " . $southbridge_extract; - } - } - - return $info; -} -function compiler_version() -{ - // Returns version of the compiler (if present) - $info = shell_exec("gcc -dumpversion 2>&1"); - $gcc_info = "N/A"; - - if(strpos($info, '.') !== FALSE) - $gcc_info = "GCC " . trim($info); - - return $gcc_info; -} -function operating_system_release() -{ - // Determine the operating system release - $vendor = os_vendor(); - $version = os_version(); - - if($vendor == "Unknown" && $version == "Unknown") - { - $os = "Unknown"; - - // Try to detect distro for those not supplying lsb_release - $files = glob("/etc/*-version"); - if(count($files) > 0) - { - $file = file_get_contents($files[0]); - $os = substr($file, 0, strpos($file, "\n")); - } - - if($os == "Unknown") - { - $files = glob("/etc/*-release"); - if(count($files) > 0) - { - $file = file_get_contents($files[0]); - $os = substr($file, 0, strpos($file, "\n")); - } - else - { - if(is_file("/etc/release")) - { - $file = file_get_contents("/etc/release"); - $os = substr($file, 0, strpos($file, "\n")); - } - } - } - - if($os == "Unknown") - $os = shell_exec("uname -s 2>&1"); - } - else - $os = $vendor . " " . $version; - - if(($break_point = strpos($os, ":")) > 0) - $os = substr($os, $break_point + 1); - - $os = trim($os); - - return $os; -} -function pts_vendor_identifier() -{ - // Returns the vendor identifier used with the External Dependencies and other distro-specific features - $vendor = os_vendor(); - - if($vendor == "Unknown") - { - $vendor = operating_system_release(); - - if(($spos = strpos($vendor, " ")) > 1) - $vendor = substr($vendor, 0, $spos); - } - - return strtolower($vendor); -} -function system_temperature() -{ - // Reads the system's temperature - $temp_c = read_sensors(array("Sys Temp", "Board Temp")); - - if(empty($temp_c)) - { - $temp_c = read_acpi("/thermal_zone/THM1/temperature", "temperature"); // if it is THM1 that is for the system, in most cases it should be - - if(($end = strpos($temp_c, ' ')) > 0) - $temp_c = substr($temp_c, 0, $end); - } - - if(empty($temp_c)) - $temp_c = -1; - - return $temp_c; -} -function system_line_voltage($type) -{ - // Reads the system's line voltages - if($type == "CPU") - $voltage = read_sensors("VCore"); - else if($type == "V3") - $voltage = read_sensors(array("V3.3", "+3.3V")); - else if($type == "V5") - $voltage = read_sensors(array("V5", "+5V")); - else if($type == "V12") - $voltage = read_sensors(array("V12", "+12V")); - else - $voltage = ""; - - if(empty($voltage)) - $voltage = -1; - - return $voltage; -} -function main_system_hardware_string() -{ - // Returns the motherboard - $vendor = read_system_hal(array("system.hardware.vendor", "system.board.vendor", "pci.subsys_vendor")); - $product = read_system_hal(array("system.hardware.product", "system.board.product")); - $version = read_system_hal("system.hardware.version"); - - if($vendor != "Unknown") - $info = $vendor; - else - $info = ""; - - if($product == "Unknown" || empty($product) || (strpos($version, ".") === FALSE && $version != "Unknown")) - { - $product = $version; - } - - if(!empty($product) && $product != "Unknown") - { - $info .= " " . $product; - } - - if(empty($info)) - { - $fw_version = explode(" ", read_system_hal("system.firmware.version")); - - if(count($fw_version) > 1) - $info = $fw_version[0] . " " . $fw_version[1]; - } - - if(empty($info)) - { - $info = read_hal("pci.subsys_vendor"); - } - - return pts_clean_information_string($info); -} -function pts_report_power_mode() -{ - // Returns the power mode - $power_state = read_acpi("/ac_adapter/AC/state", "state"); - $return_status = ""; - - if($power_state == "off-line") - $return_status = "This computer was running on battery power."; - - return $return_status; -} -function pts_report_virtualized_mode() -{ - // Reports if system is running virtualized - $virtualized = ""; - $gpu = graphics_processor_string(); - - if(strpos(processor_string(), "QEMU") !== FALSE) - $virtualized = "QEMU"; - else if(strpos($gpu, "VMware") !== FALSE) - $virtualized = "VMware"; - else if(strpos($gpu, "VirtualBox") !== FALSE || strpos(main_system_hardware_string(), "VirtualBox") !== FALSE) - $virtualized = "VirtualBox"; - - if(!empty($virtualized)) - $virtualized = "This system was using " . $virtualized . " virtualization."; - - return $virtualized; -} -function filesystem_type() -{ - // Determine file-system type - $fs = shell_exec("stat " . TEST_ENV_DIR . " -L -f -c %T 2> /dev/null"); - - if(empty($fs) || IS_BSD) - return "Unknown"; - - return $fs; -} -function read_physical_memory_usage() -{ - // Amount of physical memory being used - return read_system_memory_usage("MEMORY"); -} -function read_total_memory_usage() -{ - // Amount of total (physical + SWAP) memory being used - return read_system_memory_usage("TOTAL"); -} -function read_swap_usage() -{ - // Amount of SWAP memory being used - return read_system_memory_usage("SWAP"); -} -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; -} function pts_hw_string() { // Returns string of hardware information @@ -485,4 +53,5 @@ function pts_sw_string() return $sw_string; } + ?> |