uncle_fungus
06-09-2008, 10:34 AM
Adds ability to monitor current CPU speed.
MONITOR=cpu.speed
This will become more useful as the monitoring code becomes threaded allowing in-run probing.
diff --git a/pts-core/functions/pts-functions.php b/pts-core/functions/pts-functions.php
index 71f7a85..5510b74 100644
--- a/pts-core/functions/pts-functions.php
+++ b/pts-core/functions/pts-functions.php
@@ -33,7 +33,7 @@ function pts_directory()
if(substr($dir, -1) != '/')
$dir .= '/';
}
-
+
return $dir;
}
@@ -112,6 +112,7 @@ if(($to_show = getenv("MONITOR")))
$monitor_temp = in_array("all.temp", $to_show) || $monitor_all;
$monitor_power = in_array("all.power", $to_show) || $monitor_all;
$monitor_voltage = in_array("all.voltage", $to_show) || $monitor_all;
+ $monitor_speed = in_array("all.speed", $to_show) || $monitor_all;
define("PTS_START_TIME", time());
if(in_array("gpu.temp", $to_show) || $monitor_temp)
@@ -120,22 +121,22 @@ if(($to_show = getenv("MONITOR")))
$GPU_TEMPERATURE = array();
}
if(in_array("cpu.temp", $to_show) || $monitor_temp)
- {
+ {
define("MONITOR_CPU_TEMP", 1);
$CPU_TEMPERATURE = array();
}
if(in_array("sys.temp", $to_show) || $monitor_temp)
- {
+ {
define("MONITOR_SYS_TEMP", 1);
$SYS_TEMPERATURE = array();
}
if(in_array("battery.power", $to_show) || $monitor_power)
- {
+ {
define("MONITOR_BATTERY_POWER", 1);
$BATTERY_POWER = array();
}
if(in_array("cpu.voltage", $to_show) || $monitor_voltage)
- {
+ {
define("MONITOR_CPU_VOLTAGE", 1);
$CPU_VOLTAGE = array();
}
@@ -146,16 +147,22 @@ if(($to_show = getenv("MONITOR")))
}
if(in_array("v5.voltage", $to_show) || $monitor_voltage)
{
-
+
define("MONITOR_V5_VOLTAGE", 1);
$V5_VOLTAGE = array();
}
if(in_array("v12.voltage", $to_show) || $monitor_voltage)
{
-
+
define("MONITOR_V12_VOLTAGE", 1);
$V12_VOLTAGE = array();
}
+ if(in_array("cpu.speed", $to_show) || $monitor_speed)
+ {
+
+ define("MONITOR_CPU_SPEED", 1);
+ $CPU_SPEED = array();
+ }
register_shutdown_function("pts_monitor_statistics");
}
@@ -294,7 +301,7 @@ function pts_save_result($save_to = null, $save_results = null)
if(!is_file($save_to_dir . "/pts-results-viewer.xsl") && !is_link($save_to_dir . "/pts-results-viewer.xsl"))
link(SAVE_RESULTS_DIR . "pts-results-viewer/pts-results-viewer.xsl", $save_to_dir . "/pts-results-viewer.xsl");
-
+
if($save_to == null || $save_results == null)
$bool = true;
else
@@ -600,7 +607,7 @@ function pts_version_comparable($old, $new)
if($old[0] != $new[0] || $old[1] != $new[1])
$compare = false;
- return $compare;
+ return $compare;
}
function pts_beep($times = 1)
{
diff --git a/pts-core/functions/pts-functions_monitor.php b/pts-core/functions/pts-functions_monitor.php
index 5b96546..aa92fbc 100644
--- a/pts-core/functions/pts-functions_monitor.php
+++ b/pts-core/functions/pts-functions_monitor.php
@@ -26,10 +26,12 @@ function pts_monitor_update()
pts_record_v5_voltage();
if(defined("MONITOR_V12_VOLTAGE"))
pts_record_v12_voltage();
+ if(defined("MONITOR_CPU_SPEED"))
+ pts_record_cpu_speed();
}
function pts_monitor_arguments()
{
- return array("all", "all.temp", "all.power", "all.voltage", "gpu.temp", "cpu.temp", "sys.temp", "battery.power", "cpu.voltage", "v3.voltage", "v5.voltage", "v12.voltage");
+ return array("all", "all.temp", "all.power", "all.voltage", "all.speed", "gpu.temp", "cpu.temp", "sys.temp", "battery.power", "cpu.voltage", "v3.voltage", "v5.voltage", "v12.voltage", "cpu.speed");
}
function pts_monitor_statistics()
{
@@ -46,6 +48,7 @@ function pts_monitor_statistics()
$type_index["THERMAL"] = array();
$type_index["POWER"] = array();
$type_index["VOLTAGE"] = array();
+ $type_index["SPEED"] = array();
if(isset($GLOBALS["GPU_TEMPERATURE"]))
{
@@ -151,6 +154,19 @@ function pts_monitor_statistics()
array_push($type_index["VOLTAGE"], count($m_array) - 1);
}
}
+ if(isset($GLOBALS["CPU_SPEED"]))
+ {
+ $this_array = $GLOBALS["CPU_SPEED"];
+
+ if(is_array($this_array) && !empty($this_array[0]))
+ {
+ array_push($device, "CPU");
+ array_push($type, "Speed");
+ array_push($unit, "MHz");
+ array_push($m_array, $this_array);
+ array_push($type_index["SPEED"], count($m_array) - 1);
+ }
+ }
$info_report = "";
diff --git a/pts-core/functions/pts-functions_system_cpu.php b/pts-core/functions/pts-functions_system_cpu.php
index 263f2f6..ff33a45 100644
--- a/pts-core/functions/pts-functions_system_cpu.php
+++ b/pts-core/functions/pts-functions_system_cpu.php
@@ -125,6 +125,30 @@ function processor_temperature()
return $temp_c;
}
+function current_processor_frequency($cpu_core = 0)
+{
+
+ if(is_file("/sys/devices/system/cpu/cpu" . $cpu_core . "/cpufreq/scaling_max_freq")) // The ideal way, with modern CPUs using CnQ or EIST and cpuinfo reporting the current
+{
+ $info = trim(file_get_contents("/sys/devices/system/cpu/cpu" . $cpu_core . "/cpufreq/scaling_cur_freq"));
+ $info = pts_trim_double(intval($info) / 1000, 2);
+}
+ else if(is_file("/proc/cpuinfo")) // fall back for those without cpufreq
+{
+ $cpu_speeds = read_cpuinfo("cpu MHz");
+
+ if(count($cpu_speeds) > $cpu_core)
+ $info = $cpu_speeds[$cpu_core];
+ else
+ $info = $cpu_speeds[0];
+
+ $info = pts_trim_double(intval($info), 2);
+}
+ else
+ $info = 0;
+
+ return $info;
+}
function pts_record_cpu_temperature()
{
global $CPU_TEMPERATURE;
@@ -133,6 +157,14 @@ function pts_record_cpu_temperature()
if($temp != -1)
array_push($CPU_TEMPERATURE, $temp);
}
+function pts_record_cpu_speed()
+{
+ global $CPU_SPEED;
+ $speed = current_processor_frequency();
+
+ if($speed != -1)
+ array_push($CPU_SPEED, $speed);
+}
function pts_processor_power_savings_enabled()
{
$return_string = "";
http://fire-salamander.co.uk/temp/pts/1213021039-1.png
MONITOR=cpu.speed
This will become more useful as the monitoring code becomes threaded allowing in-run probing.
diff --git a/pts-core/functions/pts-functions.php b/pts-core/functions/pts-functions.php
index 71f7a85..5510b74 100644
--- a/pts-core/functions/pts-functions.php
+++ b/pts-core/functions/pts-functions.php
@@ -33,7 +33,7 @@ function pts_directory()
if(substr($dir, -1) != '/')
$dir .= '/';
}
-
+
return $dir;
}
@@ -112,6 +112,7 @@ if(($to_show = getenv("MONITOR")))
$monitor_temp = in_array("all.temp", $to_show) || $monitor_all;
$monitor_power = in_array("all.power", $to_show) || $monitor_all;
$monitor_voltage = in_array("all.voltage", $to_show) || $monitor_all;
+ $monitor_speed = in_array("all.speed", $to_show) || $monitor_all;
define("PTS_START_TIME", time());
if(in_array("gpu.temp", $to_show) || $monitor_temp)
@@ -120,22 +121,22 @@ if(($to_show = getenv("MONITOR")))
$GPU_TEMPERATURE = array();
}
if(in_array("cpu.temp", $to_show) || $monitor_temp)
- {
+ {
define("MONITOR_CPU_TEMP", 1);
$CPU_TEMPERATURE = array();
}
if(in_array("sys.temp", $to_show) || $monitor_temp)
- {
+ {
define("MONITOR_SYS_TEMP", 1);
$SYS_TEMPERATURE = array();
}
if(in_array("battery.power", $to_show) || $monitor_power)
- {
+ {
define("MONITOR_BATTERY_POWER", 1);
$BATTERY_POWER = array();
}
if(in_array("cpu.voltage", $to_show) || $monitor_voltage)
- {
+ {
define("MONITOR_CPU_VOLTAGE", 1);
$CPU_VOLTAGE = array();
}
@@ -146,16 +147,22 @@ if(($to_show = getenv("MONITOR")))
}
if(in_array("v5.voltage", $to_show) || $monitor_voltage)
{
-
+
define("MONITOR_V5_VOLTAGE", 1);
$V5_VOLTAGE = array();
}
if(in_array("v12.voltage", $to_show) || $monitor_voltage)
{
-
+
define("MONITOR_V12_VOLTAGE", 1);
$V12_VOLTAGE = array();
}
+ if(in_array("cpu.speed", $to_show) || $monitor_speed)
+ {
+
+ define("MONITOR_CPU_SPEED", 1);
+ $CPU_SPEED = array();
+ }
register_shutdown_function("pts_monitor_statistics");
}
@@ -294,7 +301,7 @@ function pts_save_result($save_to = null, $save_results = null)
if(!is_file($save_to_dir . "/pts-results-viewer.xsl") && !is_link($save_to_dir . "/pts-results-viewer.xsl"))
link(SAVE_RESULTS_DIR . "pts-results-viewer/pts-results-viewer.xsl", $save_to_dir . "/pts-results-viewer.xsl");
-
+
if($save_to == null || $save_results == null)
$bool = true;
else
@@ -600,7 +607,7 @@ function pts_version_comparable($old, $new)
if($old[0] != $new[0] || $old[1] != $new[1])
$compare = false;
- return $compare;
+ return $compare;
}
function pts_beep($times = 1)
{
diff --git a/pts-core/functions/pts-functions_monitor.php b/pts-core/functions/pts-functions_monitor.php
index 5b96546..aa92fbc 100644
--- a/pts-core/functions/pts-functions_monitor.php
+++ b/pts-core/functions/pts-functions_monitor.php
@@ -26,10 +26,12 @@ function pts_monitor_update()
pts_record_v5_voltage();
if(defined("MONITOR_V12_VOLTAGE"))
pts_record_v12_voltage();
+ if(defined("MONITOR_CPU_SPEED"))
+ pts_record_cpu_speed();
}
function pts_monitor_arguments()
{
- return array("all", "all.temp", "all.power", "all.voltage", "gpu.temp", "cpu.temp", "sys.temp", "battery.power", "cpu.voltage", "v3.voltage", "v5.voltage", "v12.voltage");
+ return array("all", "all.temp", "all.power", "all.voltage", "all.speed", "gpu.temp", "cpu.temp", "sys.temp", "battery.power", "cpu.voltage", "v3.voltage", "v5.voltage", "v12.voltage", "cpu.speed");
}
function pts_monitor_statistics()
{
@@ -46,6 +48,7 @@ function pts_monitor_statistics()
$type_index["THERMAL"] = array();
$type_index["POWER"] = array();
$type_index["VOLTAGE"] = array();
+ $type_index["SPEED"] = array();
if(isset($GLOBALS["GPU_TEMPERATURE"]))
{
@@ -151,6 +154,19 @@ function pts_monitor_statistics()
array_push($type_index["VOLTAGE"], count($m_array) - 1);
}
}
+ if(isset($GLOBALS["CPU_SPEED"]))
+ {
+ $this_array = $GLOBALS["CPU_SPEED"];
+
+ if(is_array($this_array) && !empty($this_array[0]))
+ {
+ array_push($device, "CPU");
+ array_push($type, "Speed");
+ array_push($unit, "MHz");
+ array_push($m_array, $this_array);
+ array_push($type_index["SPEED"], count($m_array) - 1);
+ }
+ }
$info_report = "";
diff --git a/pts-core/functions/pts-functions_system_cpu.php b/pts-core/functions/pts-functions_system_cpu.php
index 263f2f6..ff33a45 100644
--- a/pts-core/functions/pts-functions_system_cpu.php
+++ b/pts-core/functions/pts-functions_system_cpu.php
@@ -125,6 +125,30 @@ function processor_temperature()
return $temp_c;
}
+function current_processor_frequency($cpu_core = 0)
+{
+
+ if(is_file("/sys/devices/system/cpu/cpu" . $cpu_core . "/cpufreq/scaling_max_freq")) // The ideal way, with modern CPUs using CnQ or EIST and cpuinfo reporting the current
+{
+ $info = trim(file_get_contents("/sys/devices/system/cpu/cpu" . $cpu_core . "/cpufreq/scaling_cur_freq"));
+ $info = pts_trim_double(intval($info) / 1000, 2);
+}
+ else if(is_file("/proc/cpuinfo")) // fall back for those without cpufreq
+{
+ $cpu_speeds = read_cpuinfo("cpu MHz");
+
+ if(count($cpu_speeds) > $cpu_core)
+ $info = $cpu_speeds[$cpu_core];
+ else
+ $info = $cpu_speeds[0];
+
+ $info = pts_trim_double(intval($info), 2);
+}
+ else
+ $info = 0;
+
+ return $info;
+}
function pts_record_cpu_temperature()
{
global $CPU_TEMPERATURE;
@@ -133,6 +157,14 @@ function pts_record_cpu_temperature()
if($temp != -1)
array_push($CPU_TEMPERATURE, $temp);
}
+function pts_record_cpu_speed()
+{
+ global $CPU_SPEED;
+ $speed = current_processor_frequency();
+
+ if($speed != -1)
+ array_push($CPU_SPEED, $speed);
+}
function pts_processor_power_savings_enabled()
{
$return_string = "";
http://fire-salamander.co.uk/temp/pts/1213021039-1.png