本文整理汇总了PHP中pts_strings::trim_spaces方法的典型用法代码示例。如果您正苦于以下问题:PHP pts_strings::trim_spaces方法的具体用法?PHP pts_strings::trim_spaces怎么用?PHP pts_strings::trim_spaces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pts_strings
的用法示例。
在下文中一共展示了pts_strings::trim_spaces方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: parse_result_process
protected static function parse_result_process(&$test_run_request, $parse_xml_file, $log_file, $pts_test_arguments, $extra_arguments, $is_numeric_check = true, $prefix = null)
{
$test_identifier = $test_run_request->test_profile->get_identifier();
$results_parser_xml = new pts_parse_results_nye_XmlReader($parse_xml_file);
$result_match_test_arguments = $results_parser_xml->getXMLArrayValues('PhoronixTestSuite/ResultsParser/MatchToTestArguments');
$result_scale = $results_parser_xml->getXMLArrayValues('PhoronixTestSuite/ResultsParser/ResultScale');
$result_proportion = $results_parser_xml->getXMLArrayValues('PhoronixTestSuite/ResultsParser/ResultProportion');
$result_precision = $results_parser_xml->getXMLArrayValues('PhoronixTestSuite/ResultsParser/ResultPrecision');
$result_template = $results_parser_xml->getXMLArrayValues('PhoronixTestSuite/ResultsParser/OutputTemplate');
$result_key = $results_parser_xml->getXMLArrayValues('PhoronixTestSuite/ResultsParser/ResultKey');
$result_line_hint = $results_parser_xml->getXMLArrayValues('PhoronixTestSuite/ResultsParser/LineHint');
$result_line_before_hint = $results_parser_xml->getXMLArrayValues('PhoronixTestSuite/ResultsParser/LineBeforeHint');
$result_line_after_hint = $results_parser_xml->getXMLArrayValues('PhoronixTestSuite/ResultsParser/LineAfterHint');
$result_before_string = $results_parser_xml->getXMLArrayValues('PhoronixTestSuite/ResultsParser/ResultBeforeString');
$result_after_string = $results_parser_xml->getXMLArrayValues('PhoronixTestSuite/ResultsParser/ResultAfterString');
$result_divide_by = $results_parser_xml->getXMLArrayValues('PhoronixTestSuite/ResultsParser/DivideResultBy');
$result_multiply_by = $results_parser_xml->getXMLArrayValues('PhoronixTestSuite/ResultsParser/MultiplyResultBy');
$strip_from_result = $results_parser_xml->getXMLArrayValues('PhoronixTestSuite/ResultsParser/StripFromResult');
$strip_result_postfix = $results_parser_xml->getXMLArrayValues('PhoronixTestSuite/ResultsParser/StripResultPostfix');
$multi_match = $results_parser_xml->getXMLArrayValues('PhoronixTestSuite/ResultsParser/MultiMatch');
$file_format = $results_parser_xml->getXMLArrayValues('PhoronixTestSuite/ResultsParser/FileFormat');
$test_result = false;
if ($prefix != null && substr($prefix, -1) != '_') {
$prefix .= '_';
}
for ($i = 0; $i < count($result_template); $i++) {
if (!empty($result_match_test_arguments[$i]) && strpos($pts_test_arguments, $result_match_test_arguments[$i]) === false) {
// This is not the ResultsParser XML section to use as the MatchToTestArguments does not match the PTS test arguments
continue;
}
if ($result_key[$i] == null) {
$result_key[$i] = '#_' . $prefix . 'RESULT_#';
} else {
switch ($result_key[$i]) {
case 'PTS_TEST_ARGUMENTS':
$result_key[$i] = '#_' . $prefix . str_replace(' ', '', $pts_test_arguments) . '_#';
break;
case 'PTS_USER_SET_ARGUMENTS':
$result_key[$i] = '#_' . $prefix . str_replace(' ', '', $extra_arguments) . '_#';
break;
}
}
// The actual parsing here
$start_result_pos = strrpos($result_template[$i], $result_key[$i]);
if ($prefix != null && $start_result_pos === false && $result_template[$i] != 'csv-dump-frame-latencies' && $result_template[$i] != 'libframetime-output') {
// XXX: technically the $prefix check shouldn't be needed, verify whether safe to have this check be unconditional on start_result_pos failing...
return false;
}
$space_out_chars = array('(', ')', "\t");
if (isset($file_format[$i]) && $file_format[$i] == 'CSV') {
array_push($space_out_chars, ',');
}
if (isset($result_template[$i][$start_result_pos - 1]) && $result_template[$i][$start_result_pos - 1] == '/' || isset($result_template[$i][$start_result_pos + strlen($result_key[$i])]) && $result_template[$i][$start_result_pos + strlen($result_key[$i])] == '/') {
array_push($space_out_chars, '/');
}
$end_result_pos = $start_result_pos + strlen($result_key[$i]);
$end_result_line_pos = strpos($result_template[$i], "\n", $end_result_pos);
$result_template_line = substr($result_template[$i], 0, $end_result_line_pos === false ? strlen($result_template[$i]) : $end_result_line_pos);
$result_template_line = substr($result_template_line, strrpos($result_template_line, "\n"));
$result_template_r = explode(' ', pts_strings::trim_spaces(str_replace($space_out_chars, ' ', str_replace('=', ' = ', $result_template_line))));
$result_template_r_pos = array_search($result_key[$i], $result_template_r);
if ($result_template_r_pos === false) {
// Look for an element that partially matches, if like a '.' or '/sec' or some other pre/post-fix is present
foreach ($result_template_r as $x => $r_check) {
if (isset($result_key[$x]) && strpos($r_check, $result_key[$x]) !== false) {
$result_template_r_pos = $x;
break;
}
}
}
$search_key = null;
$line_before_key = null;
if (isset($result_line_hint[$i]) && $result_line_hint[$i] != null && strpos($result_template_line, $result_line_hint[$i]) !== false) {
$search_key = $result_line_hint[$i];
} else {
if (isset($result_line_before_hint[$i]) && $result_line_before_hint[$i] != null && strpos($result_template[$i], $result_line_hint[$i]) !== false) {
$search_key = null;
// doesn't really matter what this value is
} else {
if (isset($result_line_after_hint[$i]) && $result_line_after_hint[$i] != null && strpos($result_template[$i], $result_line_hint[$i]) !== false) {
$search_key = null;
// doesn't really matter what this value is
} else {
foreach ($result_template_r as $line_part) {
if (strpos($line_part, ':') !== false && strlen($line_part) > 1) {
// add some sort of && strrpos($result_template[$i], $line_part) to make sure there isn't two of the same $search_key
$search_key = $line_part;
break;
}
}
if ($search_key == null && isset($result_key[$i])) {
// Just try searching for the first part of the string
/*
for($i = 0; $i < $result_template_r_pos; $i++)
{
$search_key .= $result_template_r[$i] . ' ';
}
*/
// This way if there are ) or other characters stripped, the below method will work where the above one will not
$search_key = substr($result_template_line, 0, strpos($result_template_line, $result_key[$i]));
//.........这里部分代码省略.........
示例3: cpu_usage_solaris
private function cpu_usage_solaris()
{
//TODO test this on 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];
return $percent;
}
示例4: read_ati_overdrive
public static function read_ati_overdrive($attribute, $adapter = 0)
{
// Read ATI OverDrive information
// OverDrive supported in fglrx 8.52+ drivers
$value = false;
if ($amdconfig = self::find_amdconfig()) {
if ($attribute == 'Temperature') {
$info = shell_exec($amdconfig . ' --adapter=' . $adapter . ' --od-gettemperature 2>&1');
if (($start = strpos($info, 'Temperature -')) !== false) {
$info = substr($info, $start + 14);
$value = substr($info, 0, strpos($info, ' C'));
}
} else {
if ($attribute == 'FanSpeed') {
// Right now there is no standardized interface to get the fan speed through besides the pplib command
$info = shell_exec($amdconfig . ' --adapter=' . $adapter . ' --pplib-cmd \'get fanspeed 0\' 2>&1');
if (($start = strpos($info, 'Fan Speed:')) !== false) {
$info = substr($info, $start + 11);
$info = substr($info, 0, strpos($info, '%'));
if (is_numeric($info)) {
$value = $info;
}
}
} else {
$info = shell_exec($amdconfig . ' --adapter=' . $adapter . ' --od-getclocks 2>&1');
if (strpos($info, 'GPU') !== false) {
foreach (explode("\n", $info) as $line) {
$line_r = pts_strings::colon_explode($line);
if (count($line_r) == 2) {
$od_option = str_replace(' ', null, $line_r[0]);
if ($od_option == $attribute) {
$od_value = pts_strings::trim_spaces($line_r[1]);
$od_value = str_replace(array('%'), null, $od_value);
$od_value_r = explode(' ', $od_value);
$value = count($od_value_r) == 1 ? $od_value_r[0] : $od_value_r;
}
}
}
}
}
}
}
return $value;
}
示例5: strip_string
public static function strip_string($str)
{
// Clean a string containing hardware information of some common things to change/strip out
$change_phrases = array('MCH' => 'Memory Controller Hub', 'AMD' => 'Advanced Micro Devices', 'MSI' => 'MICRO-STAR INTERNATIONAL', 'SiS' => 'Silicon Integrated Systems', 'Abit' => 'http://www.abit.com.tw/', 'ASUS' => 'ASUSTeK', 'HP' => 'Hewlett-Packard', 'NVIDIA' => 'nVidia', 'HDD' => 'HARDDISK', 'Intel' => 'Intel64', 'HD' => 'High Definition', 'IGP' => array('Integrated Graphics Controller', 'Express Graphics Controller', 'Integrated Graphics Device', 'Chipset Integrated'));
foreach ($change_phrases as $new_phrase => $original_phrase) {
$str = str_ireplace($original_phrase, $new_phrase, $str);
}
$remove_phrases = array('incorporation', 'corporation', 'corp.', 'invalid', 'technologies', 'technology', 'version', ' project ', 'computer', 'To Be Filled By', 'ODM', 'O.E.M.', 'Desktop Reference Platform', 'small form factor', 'convertible', ' group', 'chipset', 'community', 'reference', 'communications', 'semiconductor', 'processor', 'host bridge', 'adapter', ' CPU', 'platform', 'international', 'express', 'graphics', 'none', 'electronics', 'integrated', 'alternate', 'quad-core', 'memory', 'series', 'network', 'motherboard', 'electric ', 'industrial ', 'serverengines', 'Manufacturer', 'x86/mmx/sse2', '/AGP/SSE/3DNOW!', '/AGP/SSE2', 'controller', '(extreme graphics innovation)', 'pci-e_gfx and ht3 k8 part', 'pci-e_gfx and ht1 k8 part', 'Northbridge only', 'dual slot', 'dual-core', 'dual core', 'microsystems', 'not specified', 'single slot', 'genuine', 'unknown device', 'systemberatung', 'gmbh', 'graphics adapter', 'video device', 'http://', 'www.', '.com', '.tw/', '/pci/sse2/3dnow!', '/pcie/sse2', '/pci/sse2', 'balloon', 'network connection', 'ethernet', 'limited.', ' system', 'compliant', 'co. ltd', 'co.', 'ltd.', 'LTD ', ' LTD', '\\AE', '(r)', '(tm)', 'inc.', 'inc', '6.00 PG', ',', '\'', '_ ', '_ ', 'corp', 'product name', 'base board', 'mainboard', 'pci to pci', ' release ', 'nee ', ' AG ', 'with Radeon HD', '/DRAM');
$str = str_ireplace($remove_phrases, ' ', $str);
if (($w = stripos($str, 'WARNING')) !== false) {
// to get rid of Scheisse like 'Gtk-WARNING **: Unable'
$str = substr($str, 0, strrpos($str, ' ', 0 - (strlen($str) - $w)));
}
$str = pts_strings::trim_spaces($str);
// Fixes an AMD string issue like 'FX -4100' due to stripping (TM) from in between characters, possibly other cases too
$str = str_replace(' -', '-', $str);
return $str;
}
示例6: mem_usage
public static function mem_usage($TYPE = 'TOTAL', $READ = 'USED')
{
// Reads system memory usage
$mem_usage = -1;
if (pts_client::executable_in_path('free') != false) {
$mem = explode("\n", shell_exec('free -t -m 2>&1'));
$grab_line = null;
$buffers_and_cache = 0;
for ($i = 0; $i < count($mem); $i++) {
$line_parts = pts_strings::colon_explode($mem[$i]);
if (count($line_parts) == 2) {
$line_type = $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];
} else {
if ($line_type == '-/+ buffers/cache' && $TYPE != 'SWAP') {
$buffers_and_cache = pts_arrays::first_element(explode(' ', pts_strings::trim_spaces($line_parts[1])));
}
}
}
}
}
}
if (!empty($grab_line)) {
$grab_line = pts_strings::trim_spaces($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] - $buffers_and_cache;
}
} 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];
}
}
}
}
}
} else {
if (pts_client::executable_in_path('vm_stat') != false) {
$vmstats = explode("\n", shell_exec('vm_stat 2>&1'));
$grab_line = null;
// 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;
}
}
}
$mem_usage = pts_math::set_precision($mem_usage);
}
}
return $mem_usage;
}