本文整理汇总了PHP中pts_math::set_precision方法的典型用法代码示例。如果您正苦于以下问题:PHP pts_math::set_precision方法的具体用法?PHP pts_math::set_precision怎么用?PHP pts_math::set_precision使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pts_math
的用法示例。
在下文中一共展示了pts_math::set_precision方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: read_sensor
public static function read_sensor()
{
// Determine current percentage for processor usage
if (phodevi::is_linux() || phodevi::is_bsd()) {
$start_load = self::cpu_load_array(-1);
sleep(1);
$end_load = self::cpu_load_array(-1);
for ($i = 0; $i < count($end_load); $i++) {
$end_load[$i] -= $start_load[$i];
}
$percent = ($sum = array_sum($end_load)) == 0 ? 0 : 100 - $end_load[count($end_load) - 1] * 100 / $sum;
} else {
if (phodevi::is_solaris()) {
// TODO: Add support for monitoring load on a per-core basis (through mpstat maybe?)
$info = explode(' ', pts_strings::trim_spaces(pts_arrays::last_element(explode("\n", trim(shell_exec('sar -u 1 1 2>&1'))))));
$percent = $info[1] + $info[2];
} else {
if (phodevi::is_macosx()) {
// CPU usage for user
$top = shell_exec('top -n 1 -l 1 2>&1');
$top = substr($top, strpos($top, 'CPU usage: ') + 11);
$percent = substr($top, 0, strpos($top, '%'));
} else {
$percent = null;
}
}
}
if (!is_numeric($percent) || $percent < 0 || $percent > 100) {
$percent = -1;
}
return pts_math::set_precision($percent, 2);
}
示例2: run
public static function run($r)
{
define('PHOROMATIC_PROCESS', true);
$commands = array('detailed_system_info' => null, 'list_available_tests' => null, 'list_available_suites' => null, 'info' => array('pts/all'), 'clone_openbenchmarking_result' => array('1107247-LI-MESACOMMI48', '1509040-HA-GCCINTELS17', '1508201-HA-GTX95073337', '1508233-HA-INTELSKYL16'), 'refresh_graphs' => array('1107247-LI-MESACOMMI48'), 'result_file_to_text' => array('1107247-LI-MESACOMMI48'), 'merge_results' => array('1107247-LI-MESACOMMI48', '1509040-HA-GCCINTELS17', '1508201-HA-GTX95073337', '1508233-HA-INTELSKYL16'), 'diagnostics' => null, 'dump_possible_options' => null, 'debug_render_test' => null);
$individual_times = array();
phodevi::clear_cache();
$start = microtime(true);
foreach ($commands as $command => $args) {
echo PHP_EOL . '### ' . $command . ' ###' . PHP_EOL;
$individual_times[$command] = array();
for ($i = 0; $i < 3; $i++) {
$c_start = microtime(true);
pts_client::execute_command($command, $args);
$c_finish = microtime(true);
$individual_times[$command][] = $c_finish - $c_start;
}
}
$finish = microtime(true);
echo PHP_EOL . PHP_EOL . '### OVERALL DATA ###' . PHP_EOL . PHP_EOL;
echo 'PHP: ' . PTS_PHP_VERSION . PHP_EOL;
$longest_c = max(array_map('strlen', array_keys($individual_times)));
foreach ($individual_times as $component => $times) {
echo strtoupper($component) . ': ' . str_repeat(' ', $longest_c - strlen($component)) . pts_math::set_precision(round(array_sum($times) / count($times), 3), 3) . ' seconds' . PHP_EOL;
}
echo PHP_EOL . 'TOTAL ELAPSED TIME: ' . str_repeat(' ', $longest_c - strlen('ELAPSED TIME')) . round($finish - $start, 3) . ' seconds';
echo PHP_EOL . 'PEAK MEMORY USAGE: ' . str_repeat(' ', $longest_c - strlen('PEAK MEMORY USAGE')) . round(memory_get_peak_usage(true) / 1048576, 3) . ' MB';
echo PHP_EOL . 'PEAK MEMORY USAGE EMALLOC: ' . str_repeat(' ', $longest_c - strlen('PEAK MEMORY USAGE (emalloc)')) . round(memory_get_peak_usage() / 1048576, 3) . ' MB';
echo PHP_EOL;
}
示例3: run
public static function run($r)
{
$commands = array('detailed_system_info' => null, 'list_available_tests' => null, 'list_available_suites' => null, 'info' => array('xonotic'), 'clone_openbenchmarking_result' => array('1107247-LI-MESACOMMI48'), 'result_file_to_text' => array('1107247-LI-MESACOMMI48'), 'diagnostics' => null, 'dump_possible_options' => null);
$individual_times = array();
phodevi::clear_cache();
$start = microtime(true);
foreach ($commands as $command => $args) {
echo PHP_EOL . '### ' . $command . ' ###' . PHP_EOL;
$individual_times[$command] = array();
for ($i = 0; $i < 3; $i++) {
$c_start = microtime(true);
pts_client::execute_command($command, $args);
$c_finish = microtime(true);
array_push($individual_times[$command], $c_finish - $c_start);
}
}
$finish = microtime(true);
echo PHP_EOL . PHP_EOL . '### OVERALL DATA ###' . PHP_EOL . PHP_EOL;
echo 'PHP: ' . PTS_PHP_VERSION . PHP_EOL;
$longest_c = max(array_map('strlen', array_keys($individual_times)));
foreach ($individual_times as $component => $times) {
echo strtoupper($component) . ': ' . str_repeat(' ', $longest_c - strlen($component)) . pts_math::set_precision(round(array_sum($times) / count($times), 3), 3) . ' seconds' . PHP_EOL;
}
echo PHP_EOL . 'ELAPSED TIME: ' . str_repeat(' ', $longest_c - strlen('ELAPSED TIME')) . round($finish - $start, 3) . ' seconds';
echo PHP_EOL . 'PEAK MEMORY USAGE: ' . str_repeat(' ', $longest_c - strlen('PEAK MEMORY USAGE')) . round(memory_get_peak_usage(true) / 1048576, 3) . ' MB';
echo PHP_EOL . 'PEAK MEMORY USAGE (emalloc): ' . str_repeat(' ', $longest_c - strlen('PEAK MEMORY USAGE (emalloc)')) . round(memory_get_peak_usage() / 1048576, 3) . ' MB';
echo PHP_EOL;
}
示例4: mem_usage_bsd
private function mem_usage_bsd($TYPE = 'TOTAL', $READ = 'USED')
{
$vmstats = explode("\n", shell_exec('vm_stat 2>&1'));
// buffers_and_cache
foreach ($vmstats as $vmstat_line) {
$line_parts = pts_strings::colon_explode($vmstat_line);
if (self::$page_size == -1) {
strtok($vmstat_line, ':');
$tok = strtok(' ');
while (self::$page_size == -1) {
if (is_numeric($tok)) {
self::$page_size = $tok;
} else {
$tok = strtok(' ');
}
}
continue;
}
//$line_parts[1] = pts_strings::trim_spaces($line_parts[1]);
$line_type = strtok($vmstat_line, ':');
$line_value = strtok(' .');
if ($TYPE == 'MEMORY') {
if ($line_type == 'Pages active' && $READ == 'USED') {
$mem_usage = $line_value / (1048576 / self::$page_size);
break;
}
if ($line_type == 'Pages free' && $READ == 'FREE') {
$mem_usage = $line_value / (1048576 / self::$page_size);
break;
}
}
}
return pts_math::set_precision($mem_usage);
}
示例5: cpu_temp_linux
private function cpu_temp_linux()
{
$temp_c = -1;
// Try hwmon interface
$raw_temp = phodevi_linux_parser::read_sysfs_node('/sys/class/hwmon/hwmon*/temp2_input', 'POSITIVE_NUMERIC', array('name' => 'coretemp'));
if ($raw_temp == -1) {
$raw_temp = phodevi_linux_parser::read_sysfs_node('/sys/class/hwmon/hwmon*/device/temp1_input', 'POSITIVE_NUMERIC', array('name' => 'k10temp'));
}
if ($raw_temp == -1) {
// Try ACPI thermal
// Assuming the system thermal sensor comes 2nd to the ACPI CPU temperature
// It appears that way on a ThinkPad T60, but TODO find a better way to validate
$raw_temp = phodevi_linux_parser::read_sysfs_node('/sys/class/thermal/thermal_zone*/temp', 'POSITIVE_NUMERIC', null, 2);
}
if ($raw_temp != -1) {
if ($raw_temp > 1000) {
$raw_temp = $raw_temp / 1000;
}
$temp_c = pts_math::set_precision($raw_temp, 2);
}
if ($temp_c == -1) {
// Try LM_Sensors
$sensors = phodevi_linux_parser::read_sensors(array('CPU Temp', 'Core 0', 'Core0 Temp', 'Core1 Temp'));
if ($sensors != false && is_numeric($sensors) && $sensors > 0) {
$temp_c = $sensors;
}
}
if (pts_client::executable_in_path('ipmitool')) {
$ipmi = phodevi_linux_parser::read_ipmitool_sensor('Temp 0');
if ($ipmi > 0 && is_numeric($ipmi)) {
$temp_c = $ipmi;
}
}
return $temp_c;
}
示例6: render_graph_bars
protected function render_graph_bars()
{
$bar_count = count($this->graph_data);
$separator_width = ($a = 8 - floor($bar_count / 2) * 2) > 0 ? $a : 0;
$bar_width = floor(($this->i['identifier_width'] - $separator_width - $bar_count * $separator_width) / $bar_count);
for ($i_o = 0; $i_o < $bar_count; $i_o++) {
$paint_color = $this->get_paint_color(isset($this->graph_data_title[$i_o]) ? $this->graph_data_title[$i_o] : null);
foreach (array_keys($this->graph_data[$i_o]) as $i) {
$value = pts_math::set_precision($this->graph_data[$i_o][$i], 2);
$graph_size = round($value / $this->i['graph_max_value'] * ($this->i['graph_top_end'] - $this->i['top_start']));
$value_plot_top = max($this->i['graph_top_end'] + 1 - $graph_size, 1);
$px_bound_left = $this->i['left_start'] + $this->i['identifier_width'] * $i + $bar_width * $i_o + $separator_width * ($i_o + 1);
$px_bound_right = $px_bound_left + $bar_width;
$title_tooltip = $this->graph_identifiers[$i] . ': ' . $value;
$run_std_deviation = isset($this->graph_data_raw[$i_o][$i]) ? pts_math::standard_deviation(pts_strings::colon_explode($this->graph_data_raw[$i_o][$i])) : 0;
if ($run_std_deviation > 0) {
$title_tooltip .= ' || ' . pts_math::set_precision($run_std_deviation, 1) . ' STD';
}
$this->svg_dom->add_element('rect', array('x' => $px_bound_left + 1, 'y' => $value_plot_top, 'width' => $bar_width, 'height' => $this->i['graph_top_end'] - $value_plot_top, 'fill' => in_array($this->graph_identifiers[$i], $this->value_highlights) ? self::$c['color']['alert'] : $paint_color, 'stroke' => self::$c['color']['body_light'], 'stroke-width' => 1, 'xlink:title' => $title_tooltip));
if ($px_bound_right - $px_bound_left < 15) {
// The bars are too skinny to be able to plot anything on them
continue;
}
$x = $px_bound_left + ($px_bound_right - $px_bound_left) / 2;
if ($graph_size > 18) {
$this->svg_dom->add_text_element($value, array('x' => $x, 'y' => $value_plot_top + 2, 'font-size' => floor(self::$c['size']['bars'] * 0.9), 'fill' => self::$c['color']['body_text'], 'text-anchor' => 'middle', 'dominant-baseline' => 'text-before-edge'));
} else {
// Make things more compact
$this->svg_dom->add_text_element($value, array('x' => $x, 'y' => $value_plot_top + 2, 'font-size' => floor(self::$c['size']['bars'] * 0.6), 'fill' => self::$c['color']['body_text'], 'text-anchor' => 'middle', 'dominant-baseline' => 'text-before-edge'));
}
}
}
// write a new line along the bottom since the draw_rectangle_with_border above had written on top of it
$this->svg_dom->draw_svg_line($this->i['left_start'], $this->i['graph_top_end'], $this->i['graph_left_end'], $this->i['graph_top_end'], self::$c['color']['notches'], 1);
}
示例7: read_sensor
public function read_sensor()
{
$temp = -1;
if (phodevi::is_linux()) {
$temp = $this->hdd_temp_linux();
}
return pts_math::set_precision($temp, 2);
}
示例8: read_sensor
public function read_sensor()
{
$write_speed = -1;
if (phodevi::is_linux()) {
$write_speed = $this->hdd_write_speed_linux();
}
return pts_math::set_precision($write_speed, 2);
}
示例9: bytes_to_download_size
protected function bytes_to_download_size($bytes)
{
$mb = pts_math::set_precision($bytes / 1048576, 2);
if ($mb > 99) {
$mb = ceil($mb);
}
return $mb;
}
示例10: read_sensor
public function read_sensor()
{
$net_speed = -1;
if (phodevi::is_bsd() || phodevi::is_macosx()) {
$net_speed = $this->network_usage_bsd();
}
return pts_math::set_precision($net_speed, 2);
}
示例11: read_sensor
public static function read_sensor()
{
// Read the processor temperature
$temp_c = -1;
if (phodevi::is_bsd()) {
$cpu_temp = phodevi_bsd_parser::read_sysctl(array('hw.sensors.acpi_tz0.temp0', 'dev.cpu.0.temperature', 'hw.sensors.cpu0.temp0'));
if ($cpu_temp != false) {
if (($end = strpos($cpu_temp, 'degC')) || ($end = strpos($cpu_temp, 'C')) > 0) {
$cpu_temp = substr($cpu_temp, 0, $end);
}
if (is_numeric($cpu_temp)) {
$temp_c = $cpu_temp;
}
} else {
$acpi = phodevi_bsd_parser::read_sysctl('hw.acpi.thermal.tz0.temperature');
if (($end = strpos($acpi, 'C')) > 0) {
$acpi = substr($acpi, 0, $end);
}
if (is_numeric($acpi)) {
$temp_c = $acpi;
}
}
} else {
if (phodevi::is_linux()) {
// Try hwmon interface
$raw_temp = phodevi_linux_parser::read_sysfs_node('/sys/class/hwmon/hwmon*/device/temp1_input', 'POSITIVE_NUMERIC', array('name' => 'coretemp'));
if ($raw_temp == -1) {
$raw_temp = phodevi_linux_parser::read_sysfs_node('/sys/class/hwmon/hwmon*/device/temp1_input', 'POSITIVE_NUMERIC', array('name' => 'k10temp'));
}
if ($raw_temp == -1) {
// Try ACPI thermal
// Assuming the system thermal sensor comes 2nd to the ACPI CPU temperature
// It appears that way on a ThinkPad T60, but TODO find a better way to validate
$raw_temp = phodevi_linux_parser::read_sysfs_node('/sys/class/thermal/thermal_zone*/temp', 'POSITIVE_NUMERIC', null, 2);
}
if ($raw_temp != -1) {
if ($raw_temp > 1000) {
$raw_temp = $raw_temp / 1000;
}
$temp_c = pts_math::set_precision($raw_temp, 2);
}
if ($temp_c == -1) {
// Try LM_Sensors
$sensors = phodevi_linux_parser::read_sensors(array('CPU Temp', 'Core 0', 'Core0 Temp', 'Core1 Temp'));
if ($sensors != false && is_numeric($sensors) && $sensors > 0) {
$temp_c = $sensors;
}
}
if (pts_client::executable_in_path('ipmitool')) {
$ipmi = phodevi_linux_parser::read_ipmitool_sensor('Temp 0');
if ($ipmi > 0 && is_numeric($ipmi)) {
$temp_c = $ipmi;
}
}
}
}
return $temp_c;
}
示例12: get_change_formatted
public function get_change_formatted()
{
$direction = '-';
if ($this->test_proportion == 'HIB' && $this->get_regressed_value() > $this->get_base_value()) {
$direction = '+';
} else {
if ($this->test_proportion == 'LIB' && $this->get_regressed_value() < $this->get_base_value()) {
$direction = '+';
}
}
return $direction . pts_math::set_precision($this->get_change() * 100, 2);
}
示例13: read_sensor
public static function read_sensor()
{
// Reads the system's temperature
$temp_c = -1;
if (phodevi::is_linux()) {
$raw_temp = phodevi_linux_parser::read_sysfs_node('/sys/class/hwmon/hwmon*/device/temp3_input', 'POSITIVE_NUMERIC', array('name' => '!coretemp,!radeon,!nouveau'));
if ($raw_temp == -1) {
$raw_temp = phodevi_linux_parser::read_sysfs_node('/sys/class/hwmon/hwmon*/device/temp2_input', 'POSITIVE_NUMERIC', array('name' => '!coretemp,!radeon,!nouveau'));
}
if ($raw_temp == -1) {
$raw_temp = phodevi_linux_parser::read_sysfs_node('/sys/class/hwmon/hwmon*/device/temp1_input', 'POSITIVE_NUMERIC', array('name' => '!coretemp,!radeon,!nouveau'));
}
if ($raw_temp == -1) {
$raw_temp = phodevi_linux_parser::read_sysfs_node('/sys/class/hwmon/hwmon*/temp1_input', 'POSITIVE_NUMERIC');
}
if ($raw_temp != -1) {
if ($raw_temp > 1000) {
$raw_temp = $raw_temp / 1000;
}
$temp_c = pts_math::set_precision($raw_temp, 2);
}
if ($temp_c == -1) {
$acpi = phodevi_linux_parser::read_acpi(array('/thermal_zone/THM1/temperature', '/thermal_zone/TZ00/temperature', '/thermal_zone/TZ01/temperature'), 'temperature');
if (($end = strpos($acpi, ' ')) > 0) {
$temp_c = substr($acpi, 0, $end);
}
}
if ($temp_c == -1) {
$sensors = phodevi_linux_parser::read_sensors(array('Sys Temp', 'Board Temp'));
if ($sensors != false && is_numeric($sensors)) {
$temp_c = $sensors;
}
}
if ($temp_c == -1 && is_file('/sys/class/thermal/thermal_zone0/temp')) {
$temp_c = pts_file_io::file_get_contents('/sys/class/thermal/thermal_zone0/temp');
if ($temp_c > 1000) {
$temp_c = pts_math::set_precision($temp_c / 1000, 1);
}
}
} else {
if (phodevi::is_bsd()) {
$acpi = phodevi_bsd_parser::read_sysctl(array('hw.sensors.acpi_tz1.temp0', 'hw.acpi.thermal.tz1.temperature'));
if (($end = strpos($acpi, ' degC')) > 0 || ($end = strpos($acpi, 'C')) > 0) {
$acpi = substr($acpi, 0, $end);
if (is_numeric($acpi)) {
$temp_c = $acpi;
}
}
}
}
return $temp_c;
}
示例14: swap_usage_linux
private function swap_usage_linux()
{
$proc_meminfo = explode("\n", file_get_contents('/proc/meminfo'));
$mem = array();
foreach ($proc_meminfo as $mem_line) {
$line_split = preg_split('/\\s+/', $mem_line);
if (count($line_split) == 3) {
$mem[$line_split[0]] = intval($line_split[1]);
}
}
$used_mem = $mem['SwapTotal:'] - $mem['SwapFree:'];
return pts_math::set_precision($used_mem / 1024, 0);
}
示例15: read_sensor
public function read_sensor()
{
$start_sys_jiffies = self::cpu_jiffies_count();
$start_cgroup_jiffies = self::cgroup_cpu_jiffies_count();
usleep(500000);
$end_sys_jiffies = self::cpu_jiffies_count();
$end_cgroup_jiffies = self::cgroup_cpu_jiffies_count();
$diff_sys_jiffies = $end_sys_jiffies - $start_sys_jiffies;
$diff_cgroup_jiffies = $end_cgroup_jiffies - $start_cgroup_jiffies;
$percent = $diff_sys_jiffies == 0 ? 0 : $diff_cgroup_jiffies / $diff_sys_jiffies * 100;
if (!is_numeric($percent) || $percent < 0 || $percent > 100) {
$percent = -1;
}
return pts_math::set_precision($percent, 2);
}