本文整理汇总了PHP中pts_arrays::last_element方法的典型用法代码示例。如果您正苦于以下问题:PHP pts_arrays::last_element方法的具体用法?PHP pts_arrays::last_element怎么用?PHP pts_arrays::last_element使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pts_arrays
的用法示例。
在下文中一共展示了pts_arrays::last_element方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: image_file_to_gd
public static function image_file_to_gd($img_file)
{
$img = false;
switch (strtolower(pts_arrays::last_element(explode('.', $img_file)))) {
case 'tga':
$img = pts_image::imagecreatefromtga($img_file);
break;
case 'png':
$img = imagecreatefrompng($img_file);
break;
case 'jpg':
case 'jpeg':
$img = imagecreatefromjpeg($img_file);
break;
}
return $img;
}
示例3: prompt_text_menu
public static function prompt_text_menu($user_string, $options_r, $allow_multi_select = false, $return_index = false, $line_prefix = null)
{
$option_count = count($options_r);
if ($option_count == 1) {
return $return_index ? pts_arrays::last_element(array_keys($options_r)) : array_pop($options_r);
}
$select = array();
do {
echo PHP_EOL;
$key_index = array();
foreach (array_keys($options_r) as $i => $key) {
$key_index[$i + 1] = $key;
echo $line_prefix . ($i + 1) . ': ' . str_repeat(' ', strlen($option_count) - strlen($i + 1)) . $options_r[$key] . PHP_EOL;
}
echo $line_prefix . $user_string . ': ';
$select_choice = pts_user_io::read_user_input();
foreach ($allow_multi_select ? pts_strings::comma_explode($select_choice) : array($select_choice) as $choice) {
if (in_array($choice, $options_r)) {
$select[] = array_search($choice, $options_r);
} else {
if (isset($key_index[$choice])) {
$select[] = $key_index[$choice];
} else {
if ($allow_multi_select && strpos($choice, '-') !== false) {
$choice_range = pts_strings::trim_explode('-', $choice);
if (count($choice_range) == 2 && is_numeric($choice_range[0]) && is_numeric($choice_range[1]) && isset($key_index[$choice_range[0]]) && isset($key_index[$choice_range[1]])) {
for ($i = min($choice_range); $i <= max($choice_range); $i++) {
$select[] = $key_index[$i];
}
}
}
}
}
}
} while (!isset($select[0]));
if ($return_index == false) {
foreach ($select as &$index) {
$index = $options_r[$index];
}
}
return implode(',', $select);
}
示例4: download_test_files
protected static function download_test_files(&$test_install_request, $download_location = false, $no_prompts = false)
{
// Download needed files for a test
if ($test_install_request->get_download_object_count() == 0) {
return true;
}
$identifier = $test_install_request->test_profile->get_identifier();
pts_client::$display->test_install_downloads($test_install_request);
if ($download_location == false) {
$download_location = $test_install_request->test_profile->get_install_dir();
}
pts_file_io::mkdir($download_location);
$module_pass = array($identifier, $test_install_request->get_download_objects());
pts_module_manager::module_process('__pre_test_download', $module_pass);
foreach ($test_install_request->get_download_objects() as $download_package) {
$package_filename = $download_package->get_filename();
$download_destination = $download_location . $package_filename;
$download_destination_temp = $download_destination . '.pts';
if ($download_package->get_download_location_type() == null) {
// Attempt a possible last-minute look-aside copy cache in case a previous test in the install queue downloaded this file already
$lookaside_copy = pts_test_install_manager::file_lookaside_test_installations($download_package);
if ($lookaside_copy) {
if ($download_package->get_filesize() == 0) {
$download_package->set_filesize(filesize($lookaside_copy));
}
$download_package->set_download_location('LOOKASIDE_DOWNLOAD_CACHE', array($lookaside_copy));
}
}
switch ($download_package->get_download_location_type()) {
case 'IN_DESTINATION_DIR':
pts_client::$display->test_install_download_file('FILE_FOUND', $download_package);
continue;
case 'REMOTE_DOWNLOAD_CACHE':
$download_tries = 0;
do {
foreach ($download_package->get_download_location_path() as $remote_download_cache_file) {
pts_client::$display->test_install_download_file('DOWNLOAD_FROM_CACHE', $download_package);
pts_network::download_file($remote_download_cache_file, $download_destination_temp);
if (!is_file($download_destination_temp) || filesize($download_destination_temp) == 0) {
self::test_install_error(null, $test_install_request, 'The file failed to download from the cache.');
pts_file_io::unlink($download_destination_temp);
break;
} else {
if ($download_package->check_file_hash($download_destination_temp)) {
rename($download_destination_temp, $download_destination);
break;
} else {
self::test_install_error(null, $test_install_request, 'The check-sum of the downloaded file failed.');
pts_file_io::unlink($download_destination_temp);
}
}
}
$download_tries++;
} while (!is_file($download_destination) && $download_tries < 2);
if (is_file($download_destination)) {
continue;
}
case 'MAIN_DOWNLOAD_CACHE':
case 'LOCAL_DOWNLOAD_CACHE':
case 'LOOKASIDE_DOWNLOAD_CACHE':
$download_cache_file = pts_arrays::last_element($download_package->get_download_location_path());
if (is_file($download_cache_file)) {
if (pts_config::read_bool_config('PhoronixTestSuite/Options/Installation/SymLinkFilesFromCache', 'FALSE') && $download_package->get_download_location_type() != 'LOOKASIDE_DOWNLOAD_CACHE') {
// For look-aside copies never symlink (unless a pre-packaged LiveCD) in case the other test ends up being un-installed
// SymLinkFilesFromCache is disabled by default
pts_client::$display->test_install_download_file('LINK_FROM_CACHE', $download_package);
symlink($download_cache_file, $download_destination);
} else {
// File is to be copied
// Try up to two times to copy a file
$attempted_copies = 0;
do {
pts_client::$display->test_install_download_file('COPY_FROM_CACHE', $download_package);
// $context = stream_context_create();
// stream_context_set_params($context, array('notification' => array('pts_network', 'stream_status_callback')));
// TODO: get the context working correctly for this copy()
copy($download_cache_file, $download_destination_temp);
pts_client::$display->test_install_progress_completed();
// Verify that the file was copied fine
if ($download_package->check_file_hash($download_destination_temp)) {
rename($download_destination_temp, $download_destination);
break;
} else {
self::test_install_error(null, $test_install_request, 'The check-sum of the copied file failed.');
pts_file_io::unlink($download_destination_temp);
}
$attempted_copies++;
} while ($attempted_copies < 2);
}
if (is_file($download_destination)) {
continue;
}
}
default:
$package_urls = $download_package->get_download_url_array();
// Download the file
if (!is_file($download_destination) && count($package_urls) > 0 && $package_urls[0] != null) {
$fail_count = 0;
do {
if (pts_network::internet_support_available()) {
//.........这里部分代码省略.........
示例5: evaluate_redundant_identifier_words
public static function evaluate_redundant_identifier_words($identifiers)
{
if (count($identifiers) < 4 || strpos(pts_arrays::first_element($identifiers), ':') !== false) {
// Probably not worth shortening so few result identifiers
return false;
}
// Breakup the an identifier into an array by spaces to be used for comparison
$common_segments = explode(' ', pts_arrays::first_element($identifiers));
$common_segments_last = explode(' ', pts_arrays::last_element($identifiers));
if (!isset($common_segments_last[2]) || !isset($common_segments[2])) {
// If there aren't at least three words in identifier, probably can't be shortened well
return false;
}
foreach (array_reverse($identifiers) as $id) {
$words = explode(' ', $id);
foreach ($words as $i => $word) {
if (isset($common_segments[$i]) && $word != $common_segments[$i] && isset($word[2]) && !ctype_alnum(substr($word, -1))) {
// IS COMMON WORD
} else {
unset($common_segments[$i]);
}
}
if (count($common_segments) == 0) {
return false;
}
}
return $common_segments;
}
示例6: environmental_variables
public static function environmental_variables()
{
// The PTS environmental variables passed during the testing process, etc
static $env_variables = null;
if ($env_variables == null) {
$env_variables = array('PTS_VERSION' => PTS_VERSION, 'PTS_CODENAME' => PTS_CODENAME, 'PTS_DIR' => PTS_PATH, 'PHP_BIN' => PHP_BIN, 'NUM_CPU_CORES' => phodevi::read_property('cpu', 'core-count'), 'NUM_CPU_NODES' => phodevi::read_property('cpu', 'node-count'), 'NUM_CPU_JOBS' => phodevi::read_property('cpu', 'core-count') * 2, 'SYS_MEMORY' => phodevi::read_property('memory', 'capacity'), 'VIDEO_MEMORY' => phodevi::read_property('gpu', 'memory-capacity'), 'VIDEO_WIDTH' => pts_arrays::first_element(phodevi::read_property('gpu', 'screen-resolution')), 'VIDEO_HEIGHT' => pts_arrays::last_element(phodevi::read_property('gpu', 'screen-resolution')), 'VIDEO_MONITOR_COUNT' => phodevi::read_property('monitor', 'count'), 'VIDEO_MONITOR_LAYOUT' => phodevi::read_property('monitor', 'layout'), 'VIDEO_MONITOR_SIZES' => phodevi::read_property('monitor', 'modes'), 'OPERATING_SYSTEM' => phodevi::read_property('system', 'vendor-identifier'), 'OS_VERSION' => phodevi::read_property('system', 'os-version'), 'OS_ARCH' => phodevi::read_property('system', 'kernel-architecture'), 'OS_TYPE' => phodevi::operating_system(), 'THIS_RUN_TIME' => PTS_INIT_TIME, 'DEBUG_REAL_HOME' => pts_core::user_home_directory());
if (!pts_client::executable_in_path('cc') && pts_client::executable_in_path('gcc') && getenv('CC') == false) {
// This helps some test profiles build correctly if they don't do a cc check internally
$env_variables['CC'] = 'gcc';
}
}
return $env_variables;
}
示例7: process_user_config_external_hook_process
protected static function process_user_config_external_hook_process($process, $cmd_value, $description_string = null, &$passed_obj = null)
{
if (!empty($cmd_value) && (is_executable($cmd_value) || ($cmd_value = pts_client::executable_in_path($cmd_value)))) {
$descriptor_spec = array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w'));
$env_vars = array('PTS_EXTERNAL_TEST_HOOK' => $process);
if ($passed_obj instanceof pts_test_result) {
$env_vars['PTS_EXTERNAL_TEST_IDENTIFIER'] = $passed_obj->test_profile->get_identifier();
$env_vars['PTS_EXTERNAL_TEST_RUN_POSITION'] = $passed_obj->test_result_buffer->get_count() + 1;
$env_vars['PTS_EXTERNAL_TEST_RUN_COUNT'] = $passed_obj->test_profile->get_times_to_run();
$env_vars['PTS_EXTERNAL_TEST_ARGS'] = $passed_obj->get_arguments();
$env_vars['PTS_EXTERNAL_TEST_DESCRIPTION'] = $passed_obj->get_arguments_description();
$env_vars['PTS_EXTERNAL_TEST_RESULT_SET'] = $passed_obj->test_result_buffer->get_values_as_string();
$env_vars['PTS_EXTERNAL_TEST_RESULT'] = $passed_obj->get_result() != 0 ? $passed_obj->get_result() : pts_arrays::last_element($passed_obj->test_result_buffer->get_values());
$env_vars['PTS_EXTERNAL_TEST_HASH'] = bin2hex($passed_obj->get_comparison_hash());
$env_vars['PTS_EXTERNAL_TEST_STD_DEV_PERCENT'] = pts_math::percent_standard_deviation($passed_obj->test_result_buffer->get_values());
if (is_file($passed_obj->test_profile->get_install_dir() . 'cache-share-' . PTS_INIT_TIME . '.pt2so')) {
// There's a cache share present
$env_vars['PTS_EXTERNAL_TEST_CACHE_SHARE'] = 1;
}
} else {
if ($passed_obj instanceof pts_test_run_manager) {
$env_vars['PTS_EXTERNAL_TESTS_IN_QUEUE'] = implode(':', $passed_obj->get_tests_to_run_identifiers());
$env_vars['PTS_EXTERNAL_TEST_FILE_NAME'] = $passed_obj->get_file_name();
$env_vars['PTS_EXTERNAL_TEST_IDENTIFIER'] = $passed_obj->get_results_identifier();
}
}
$description_string != null && pts_client::$display->test_run_instance_error($description_string);
$proc = proc_open($cmd_value, $descriptor_spec, $pipes, null, $env_vars);
$std_output = stream_get_contents($pipes[1]);
$return_value = proc_close($proc);
// If you want PTS to exit or something when your script returns !0, you could add an 'exit;' or whatever you want below
// The contents of $std_output is anything that may have been written by your script, if you want it to be interpreted by anything in this module
if ($return_value != 0) {
return false;
}
}
return true;
}
示例8: __construct
public function __construct(&$result_object = null, &$result_file = null)
{
// Initalize Colors
$this->i['identifier_size'] = self::$c['size']['identifiers'];
// Copy this since it's commonly overwritten
$this->i['graph_orientation'] = 'VERTICAL';
$this->i['graph_value_type'] = 'NUMERICAL';
$this->i['hide_graph_identifiers'] = false;
$this->i['show_graph_key'] = false;
$this->i['show_background_lines'] = false;
$this->i['iveland_view'] = false;
$this->i['graph_max_value_multiplier'] = 1.285;
$this->i['graph_max_value'] = 0;
$this->i['bottom_offset'] = 0;
$this->i['hide_y_title'] = false;
$this->i['compact_result_view'] = false;
$this->i['key_line_height'] = 0;
$this->i['graph_height'] = 0;
$this->i['graph_width'] = 0;
$this->i['left_start'] = 10;
$this->i['left_end_right'] = 10;
$this->i['top_start'] = 62;
$this->i['top_end_bottom'] = 22;
$this->i['mark_count'] = 6;
// Number of marks to make on vertical axis
$this->i['notes'] = array();
// Reset of setup besides config
if ($result_object != null) {
$test_version = $result_object->test_profile->get_app_version();
if (isset($test_version[2]) && is_numeric($test_version[0])) {
$test_version = 'v' . $test_version;
}
$this->graph_title = trim($result_object->test_profile->get_title() . ' ' . $test_version);
$this->graph_y_title = $result_object->test_profile->get_result_scale_formatted();
$this->test_identifier = $result_object->test_profile->get_identifier();
$this->i['graph_proportion'] = $result_object->test_profile->get_result_proportion();
$this->addSubTitle($result_object->get_arguments_description());
}
$this->update_graph_dimensions(self::$c['graph']['width'], self::$c['graph']['height'], true);
if ($result_file != null && $result_file instanceof pts_result_file) {
$pts_version = pts_arrays::last_element($result_file->get_system_pts_version());
$this->is_multi_way_comparison = $result_file->is_multi_way_comparison();
}
if (!isset($pts_version) || empty($pts_version)) {
$pts_version = PTS_VERSION;
}
$this->i['graph_version'] = 'Phoronix Test Suite ' . $pts_version;
}
示例9: 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;
}
示例10: increase_run_count_check
public function increase_run_count_check(&$active_result_buffer, $scheduled_times_to_run, $latest_test_run_time)
{
// First make sure this test doesn't take too long to run where we don't want dynamic handling
if (floor($latest_test_run_time / 60) > $this->dynamic_run_count_on_length_or_less) {
return false;
}
// Determine if results are statistically significant, otherwise up the run count
$std_dev = pts_math::percent_standard_deviation($active_result_buffer->results);
if ($std_dev >= $this->dynamic_run_count_std_deviation_threshold) {
static $last_run_count = 128;
// just a number that should always cause the first check below to be true
static $run_std_devs;
$times_already_ran = $active_result_buffer->get_trial_run_count();
if ($times_already_ran <= $last_run_count) {
// We're now onto a new test so clear out the array
$run_std_devs = array();
}
$last_run_count = $times_already_ran;
$run_std_devs[$last_run_count] = $std_dev;
// If we haven't reached scheduled times to run x 2, increase count straight away
if ($times_already_ran < $scheduled_times_to_run * 2) {
return true;
} else {
if ($times_already_ran < $scheduled_times_to_run * 3) {
// More aggressive determination whether to still keep increasing the run count
$first_and_now_diff = pts_arrays::first_element($run_std_devs) - pts_arrays::last_element($run_std_devs);
// Increasing the run count at least looks to be helping...
if ($first_and_now_diff > pts_arrays::first_element($run_std_devs) / 2) {
// If we are at least making progress in the right direction, increase the run count some more
return true;
}
// TODO: could add more checks and take better advantage of the array of data to better determine if it's still worth increasing
}
}
}
// Check to see if there is an external/custom script to export the results to in determining whether results are valid
if (($ex_file = $this->dynamic_run_count_export_script) != null && is_executable($ex_file) || is_executable($ex_file = PTS_USER_PATH . $this->dynamic_run_count_export_script)) {
$exit_status = trim(shell_exec($ex_file . ' ' . $active_result_buffer->get_values_as_string() . ' > /dev/null 2>&1; echo $?'));
switch ($exit_status) {
case 1:
// Run the test again
return true;
case 2:
// Results are bad, abandon testing and do not record results
return -1;
case 0:
default:
// Return was 0 or something else, results are valid, or was some other exit status
break;
}
}
// No reason to increase the run count with none of the previous checks requesting otherwise
return false;
}
示例11: get_results
public function get_results()
{
$return_results = array();
$compared_to_index = array();
foreach ($this->relations as $test_name => $tests_of_same_name) {
foreach ($tests_of_same_name as $test_version => $tests_of_same_name_and_version) {
if (count($tests_of_same_name_and_version) == 1) {
// Stub, no similar results to analyze
array_push($return_results, $this->test_results[$tests_of_same_name_and_version[0][0]]);
} else {
if (in_array($this->test_results[$tests_of_same_name_and_version[0][0]]->test_profile->get_display_format(), array('IMAGE_COMPARISON', 'LINE_GRAPH'))) {
foreach ($tests_of_same_name_and_version as $add) {
array_push($return_results, $this->test_results[$add[0]]);
}
} else {
foreach ($tests_of_same_name_and_version as $test_info) {
$similar_ids = array($test_info[0]);
$similar_ids_names = array();
$diff_index = null;
$this_attributes = $test_info[1];
foreach ($tests_of_same_name_and_version as $compare_to) {
if (in_array($compare_to[0], $similar_ids)) {
continue;
}
$diff = array_diff_assoc($this_attributes, $compare_to[1]);
if (count($diff) == 1) {
if ($diff_index == null) {
$this_index = pts_arrays::last_element(array_keys($diff));
//$this_index_value = $diff[$this_index];
$index_id = implode(',', array($test_name, $test_version, $this_index));
if (in_array($index_id, $compared_to_index)) {
continue;
}
array_push($compared_to_index, $index_id);
array_push($similar_ids_names, $this_attributes[$this_index]);
$diff_index = $this_index;
}
if (isset($diff[$diff_index])) {
array_push($similar_ids, $compare_to[0]);
array_push($similar_ids_names, $compare_to[1][$diff_index]);
}
}
}
if (count($similar_ids) > 1) {
$mto = $this->test_results[$similar_ids[0]];
$results = array();
foreach ($mto->test_result_buffer->get_identifiers() as $identifier) {
$results[$identifier] = array();
}
foreach ($similar_ids as $id) {
$mto_read = $this->test_results[$id];
$mto_identifiers = $mto_read->test_result_buffer->get_identifiers();
$mto_values = $mto_read->test_result_buffer->get_values();
foreach (array_keys($results) as $key) {
for ($i = 0; $i < count($mto_identifiers); $i++) {
if ($mto_identifiers[$i] == $key) {
array_push($results[$key], $mto_values[$i]);
break;
}
}
}
}
$mto->test_result_buffer = new pts_test_result_buffer();
$do_line_graph = true;
foreach ($similar_ids_names as $id_name_check) {
if (str_ireplace(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'x', 'M', 'K', 'B', ' '), null, $id_name_check) != null) {
$do_line_graph = false;
break;
}
}
if ($do_line_graph && count($similar_ids_names) < 4) {
$do_line_graph = false;
}
$mto->test_profile->set_display_format($do_line_graph ? 'LINE_GRAPH' : 'BAR_ANALYZE_GRAPH');
$mto->set_used_arguments_description($diff_index . ' Analysis');
$mto->test_profile->set_result_scale($mto->test_profile->get_result_scale() . ' | ' . implode(',', $similar_ids_names));
foreach ($results as $identifier => $values) {
$mto->test_result_buffer->add_test_result($identifier, implode(',', $values), null);
}
array_push($return_results, $mto);
}
}
}
}
}
}
return $return_results;
}