Best Phoronix-test-suite code snippet using phodevi_cpu.read_cpuinfo_line
phodevi_cpu.php
Source:phodevi_cpu.php
...222 $ucode_version = pts_file_io::file_get_contents('/sys/devices/system/cpu/cpu0/microcode/version');223 }224 if(empty($ucode_version) && isset(phodevi::$vfs->cpuinfo))225 {226 $ucode_version = self::read_cpuinfo_line('microcode');227 }228 return $ucode_version;229 }230 public static function cpu_default_frequency($cpu_core = 0)231 {232 // Find out the processor frequency233 $info = null;234 // First, the ideal way, with modern CPUs using CnQ or EIST and cpuinfo reporting the current235 if(is_file('/sys/devices/system/cpu/cpu' . $cpu_core . '/cpufreq/scaling_max_freq'))236 {237 $info = pts_file_io::file_get_contents('/sys/devices/system/cpu/cpu' . $cpu_core . '/cpufreq/scaling_max_freq');238 $info = intval($info) / 1000000;239 if($info > 9)240 {241 // For some reason on Linux 3.10 the scaling_max_freq is reported as 25GHz...242 $info = null;243 }244 }245 if($info == null && isset(phodevi::$vfs->cpuinfo)) // fall back for those without cpufreq246 {247 $cpu_mhz = self::read_cpuinfo_line('cpu MHz');248 $info = $cpu_mhz / 1000;249 if(empty($info))250 {251 $cpu_mhz = self::read_cpuinfo_line('clock');252 $info = $cpu_mhz / 1000;253 }254 }255 else if($info == null && phodevi::is_bsd())256 {257 $info = phodevi_bsd_parser::read_sysctl(array('dev.cpu.0.freq_levels'));258 if($info != null)259 {260 // Popping the top speed off of dev.cpu.0.freq_levels should be the default/highest supported frequency261 $info = pts_arrays::first_element(explode(' ', str_replace('/', ' ', $info)));262 if(!is_numeric($info))263 {264 $info = null;265 }266 }267 if($info == null)268 {269 $info = phodevi_bsd_parser::read_sysctl(array('hw.acpi.cpu.px_global', 'machdep.est.frequency.target', 'hw.cpuspeed'));270 }271 if($info == null)272 {273 // dev.cpu.0.freq seems to be the real/current frequency, affected by power management, etc so only use as last fallback274 $info = phodevi_bsd_parser::read_sysctl(array('dev.cpu.0.freq'));275 }276 if(is_numeric($info))277 {278 $info = $info / 1000;279 }280 else281 {282 $info = null;283 }284 }285 else if($info == null && phodevi::is_windows())286 {287 $info = phodevi_windows_parser::read_cpuz('Processor 1', 'Stock frequency');288 if($info != null)289 {290 if(($e = strpos($info, ' MHz')) !== false)291 {292 $info = substr($info, 0, $e);293 }294 $info = $info / 1000;295 }296 }297 else if($info == null)298 {299 $freq_sensor = new cpu_freq(0, NULL);300 $info = phodevi::read_sensor($freq_sensor);301 unset($freq_sensor);302 if($info > 1000)303 {304 // Convert from MHz to GHz305 $info = $info / 1000;306 }307 }308 return pts_math::set_precision($info, 2);309 }310 public static function cpu_model()311 {312 // Returns the processor name / frequency information313 $info = null;314 if(isset(phodevi::$vfs->cpuinfo))315 {316 $physical_cpu_ids = phodevi_linux_parser::read_cpuinfo('physical id');317 $physical_cpu_count = count(array_unique($physical_cpu_ids));318 $cpu_strings = phodevi_linux_parser::read_cpuinfo(array('model name', 'Processor', 'cpu', 'cpu model'));319 $cpu_strings_unique = array_unique($cpu_strings);320 if($physical_cpu_count == 1 || empty($physical_cpu_count))321 {322 // Just one processor323 if(isset($cpu_strings[0]) && ($cut = strpos($cpu_strings[0], ' (')) !== false)324 {325 $cpu_strings[0] = substr($cpu_strings[0], 0, $cut);326 }327 $info = isset($cpu_strings[0]) ? $cpu_strings[0] : null;328 if(strpos($info, 'ARM') !== false)329 {330 if(is_dir('/sys/devices/system/exynos-core/') && stripos($info, 'Exynos') === false)331 {332 $info = 'Exynos ' . $info;333 }334 }335 }336 else if($physical_cpu_count > 1 && count($cpu_strings_unique) == 1)337 {338 // Multiple processors, same model339 $info = $physical_cpu_count . ' x ' . $cpu_strings[0];340 }341 else if($physical_cpu_count > 1 && count($cpu_strings_unique) > 1)342 {343 // Multiple processors, different models344 $current_id = -1;345 $current_string = $cpu_strings[0];346 $current_count = 0;347 $cpus = array();348 for($i = 0; $i < count($physical_cpu_ids); $i++)349 {350 if($current_string != $cpu_strings[$i] || $i == (count($physical_cpu_ids) - 1))351 {352 array_push($cpus, $current_count . ' x ' . $current_string);353 $current_string = $cpu_strings[$i];354 $current_count = 0;355 }356 if($physical_cpu_ids[$i] != $current_id)357 {358 $current_count++;359 $current_id = $physical_cpu_ids[$i];360 }361 }362 $info = implode(', ', $cpus);363 }364 }365 else if(phodevi::is_solaris())366 {367 $dmi_cpu = phodevi_solaris_parser::read_sun_ddu_dmi_info('CPUType', '-C');368 if(count($dmi_cpu) == 0)369 {370 $dmi_cpu = phodevi_solaris_parser::read_sun_ddu_dmi_info('ProcessorName');371 }372 if(count($dmi_cpu) > 0)373 {374 $info = $dmi_cpu[0];375 }376 else377 {378 $info = trim(shell_exec('dmesg 2>&1 | grep cpu0'));379 $info = trim(substr($info, strrpos($info, 'cpu0:') + 6));380 if(empty($info))381 {382 $info = array_pop(phodevi_solaris_parser::read_sun_ddu_dmi_info('ProcessorManufacturer'));383 }384 }385 //TODO: Add in proper support for reading multiple CPUs, similar to the code from above386 $physical_cpu_count = count(phodevi_solaris_parser::read_sun_ddu_dmi_info('ProcessorSocketType'));387 if($physical_cpu_count > 1 && !empty($info))388 {389 // TODO: For now assuming when multiple CPUs are installed, that they are of the same type390 $info = $physical_cpu_count . ' x ' . $info;391 }392 }393 else if(phodevi::is_bsd())394 {395 $info = phodevi_bsd_parser::read_sysctl('hw.model');396 }397 else if(phodevi::is_macosx())398 {399 $info = phodevi_osx_parser::read_osx_system_profiler('SPHardwareDataType', 'ProcessorName');400 }401 else if(phodevi::is_windows())402 {403 $info = phodevi_windows_parser::read_cpuz('Processor 1', 'Name');404 if(!$info)405 {406 $info = getenv('PROCESSOR_IDENTIFIER');407 }408 }409 if(empty($info))410 {411 $info = 'Unknown';412 }413 else414 {415 if(($strip_point = strpos($info, '@')) > 0)416 {417 $info = trim(substr($info, 0, $strip_point)); // stripping out the reported freq, since the CPU could be overclocked, etc418 }419 $info = pts_strings::strip_string($info);420 // It seems Intel doesn't report its name when reporting Pentium hardware421 if(strpos($info, 'Pentium') !== false && strpos($info, 'Intel') === false)422 {423 $info = 'Intel ' . $info;424 }425 if(substr($info, 0, 5) == 'Intel')426 {427 $cpu_words = explode(' ', $info);428 $cpu_words_count = count($cpu_words);429 // Convert strings like 'Intel Core i7 M 620' -> 'Intel Core i7 620M' and 'Intel Core i7 X 990' -> 'Intel Core i7 990X' to better reflect Intel product marketing names430 if($cpu_words_count > 4 && is_numeric($cpu_words[($cpu_words_count - 1)]) && strlen($cpu_words[($cpu_words_count - 2)]) == 1 && strlen($cpu_words[($cpu_words_count - 3)]) == 2)431 {432 $cpu_words[($cpu_words_count - 1)] .= $cpu_words[($cpu_words_count - 2)];433 unset($cpu_words[($cpu_words_count - 2)]);434 $info = implode(' ', $cpu_words);435 }436 }437 }438 return $info;439 }440 public static function get_cpu_feature_constants()441 {442 return array(443 'sse2' => (1 << 1), // SSE 2444 'sse3' => (1 << 2), // SSE 3445 'sse4a' => (1 << 3), // SSE 4a446 'sse4_1' => (1 << 4), // SSE 4.1447 'sse4_2' => (1 << 5), // SSE 4.2448 'sse5' => (1 << 6), // SSE 5449 'avx' => (1 << 7), // AVX450 'avx2' => (1 << 8), // AVX2451 'aes' => (1 << 9), // AES452 'epb' => (1 << 10), // EPB453 'svm' => (1 << 11), // AMD SVM (Virtualization)454 'vmx' => (1 << 12), // Intel Virtualization455 'xop' => (1 << 13), // AMD XOP Instruction Set456 'fma3' => (1 << 14), // FMA3 Instruction Set457 'fma4' => (1 << 15), // FMA4 Instruction Set458 'rdrand' => (1 << 16), // Intel Bull Mountain RDRAND - Ivy Bridge459 'fsgsbase' => (1 << 17), // FSGSBASE - Ivy Bridge AVX460 'bmi2' => (1 << 18), // Intel Haswell has BMI2461 'avx512cd' => (1 << 19) // AVX-512462 );463 }464 public static function get_cpu_feature_constant($constant)465 {466 $features = self::get_cpu_feature_constants();467 return isset($features[$constant]) ? $features[$constant] : -1;468 }469 public static function read_cpuinfo_line($key, $from_start = true)470 {471 $line = false;472 $key .= "\t";473 if(isset(phodevi::$vfs->cpuinfo) && ($from_start && ($key_pos = strpos(phodevi::$vfs->cpuinfo, PHP_EOL . $key)) !== false) || ($key_pos = strrpos(phodevi::$vfs->cpuinfo, PHP_EOL . $key)) !== false)474 {475 $line = substr(phodevi::$vfs->cpuinfo, $key_pos);476 $line = substr($line, strpos($line, ':') + 1);477 $line = trim(substr($line, 0, strpos($line, PHP_EOL)));478 }479 return $line;480 }481 public static function set_cpu_feature_flags()482 {483 $flags = explode(' ', self::read_cpuinfo_line('flags'));484 self::$cpu_flags = 0;485 foreach(self::get_cpu_feature_constants() as $feature => $value)486 {487 if(in_array($feature, $flags))488 {489 // The feature is supported on the CPU490 self::$cpu_flags |= $value;491 }492 }493 }494 public static function get_cpu_flags()495 {496 if(self::$cpu_flags === -1)497 {498 self::set_cpu_feature_flags();499 }500 return self::$cpu_flags;501 }502 public static function instruction_set_extensions()503 {504 $constants = self::get_cpu_feature_constants();505 self::set_cpu_feature_flags();506 $cpu_flags = self::get_cpu_flags();507 $extension_string = null;508 foreach($constants as $feature => $value)509 {510 // find maximum SSE version511 if(substr($feature, 0, 3) == 'sse' && ($cpu_flags & $value))512 {513 $extension_string = 'SSE ' . str_replace('_', '.', substr($feature, 3));514 }515 }516 // Check for other instruction sets517 foreach(array('avx512cd', 'avx2', 'avx', 'xop', 'fma3', 'fma4', 'rdrand', 'fsgsbase') as $instruction_set)518 {519 if(($cpu_flags & self::get_cpu_feature_constant($instruction_set)))520 {521 $extension_string .= ($extension_string != null ? ' + ' : null) . strtoupper($instruction_set);522 }523 }524 return $extension_string;525 }526 public static function virtualization_technology()527 {528 $constants = self::get_cpu_feature_constants();529 $cpu_flags = self::get_cpu_flags();530 $virtualitzation_technology = false;531 if(($cpu_flags & self::get_cpu_feature_constant('vmx')))532 {533 $virtualitzation_technology = 'VT-x';534 }535 else if(($cpu_flags & self::get_cpu_feature_constant('svm')))536 {537 $virtualitzation_technology = 'AMD-V';538 }539 return $virtualitzation_technology;540 }541 public static function lscpu_l2_cache()542 {543 $l2_cache = false;544 if(isset(phodevi::$vfs->lscpu) && ($t = strpos(phodevi::$vfs->lscpu, 'L2 cache:')))545 {546 $lscpu = substr(phodevi::$vfs->lscpu, $t + strlen('L2 cache:') + 1);547 $lscpu = substr($lscpu, 0, strpos($lscpu, PHP_EOL));548 $l2_cache = trim($lscpu);549 }550 return $l2_cache;551 }552 public static function cpuinfo_core_count()553 {554 if(pts_client::executable_in_path('lscpu'))555 {556 $lscpu = trim(shell_exec('lscpu -p | egrep -v \'^#\' | sort -u -t, -k 2,4 | wc -l'));557 }558 $core_count = self::read_cpuinfo_line('cpu cores');559 if($core_count == false || !is_numeric($core_count))560 {561 $core_count = self::read_cpuinfo_line('core id', false);562 if(is_numeric($core_count))563 {564 // cpuinfo 'core id' begins counting at 0565 $core_count += 1;566 }567 }568 if($core_count == false || !is_numeric($core_count))569 {570 $core_count = self::cpuinfo_thread_count();571 }572 if(is_numeric($lscpu) && $lscpu > $core_count)573 {574 $core_count = $lscpu;575 }576 return $core_count;577 }578 public static function cpuinfo_thread_count()579 {580 $thread_count = self::read_cpuinfo_line('processor', false);581 if(is_numeric($thread_count))582 {583 // cpuinfo 'processor' begins counting at 0584 $thread_count += 1;585 }586 return $thread_count;587 }588 public static function cpuinfo_cache_size()589 {590 // CPU cache size in KB591 $cache_size = self::read_cpuinfo_line('cache size');592 if(substr($cache_size, -3) == ' KB')593 {594 $cache_size = substr($cache_size, 0, -3);595 }596 else597 {598 $cache_size = null;599 }600 return $cache_size;601 }602 public static function cpu_cache_size_string()603 {604 $cache_size = phodevi::read_property('cpu', 'cache-size');605 if($cache_size > 1)...
pts_DetailedSystemComponentTable.php
Source:pts_DetailedSystemComponentTable.php
...145 case 'Virtualization':146 $line = phodevi_cpu::virtualization_technology();147 break;148 default:149 $line = phodevi_cpu::read_cpuinfo_line(strtolower($cpuinfo_item), false);150 break;151 }152 if($line)153 {154 $line = pts_strings::strip_string($line);155 }156 $this->table_data[$i][$rows_index] = $line;157 }158 }159 protected function generate_graphics_data(&$result_file, $system_identifier)160 {161 $this->rows[] = $system_identifier;162 $rows_index = count($this->rows) - 1;163 foreach($this->columns as $i => $cpuinfo_item)...
read_cpuinfo_line
Using AI Code Generation
1include('phodevi.php');2$cpu = new phodevi_cpu();3echo $cpu->read_cpuinfo_line('model name');4include('phodevi.php');5$cpu = new phodevi_cpu();6echo $cpu->read_cpuinfo_line('cpu MHz');7include('phodevi.php');8$cpu = new phodevi_cpu();9echo $cpu->read_cpuinfo_line('cache size');10include('phodevi.php');11$cpu = new phodevi_cpu();12echo $cpu->read_cpuinfo_line('bogomips');13include('phodevi.php');14$cpu = new phodevi_cpu();15echo $cpu->read_cpuinfo_line('flags');16include('phodevi.php');17$cpu = new phodevi_cpu();18echo $cpu->read_cpuinfo_line('vendor_id');19include('phodevi.php');20$cpu = new phodevi_cpu();21echo $cpu->read_cpuinfo_line('cpu family');22include('phodevi.php');23$cpu = new phodevi_cpu();24echo $cpu->read_cpuinfo_line('model');25include('phodevi.php');26$cpu = new phodevi_cpu();27echo $cpu->read_cpuinfo_line('stepping');
read_cpuinfo_line
Using AI Code Generation
1$cpu = new phodevi_cpu();2$cpu->read_cpuinfo_line('model name');3print_r($cpu->read_cpuinfo_line('model name'));4$cpu = new phodevi_cpu();5$cpu->read_cpuinfo_line('model name');6print_r($cpu->read_cpuinfo_line('model name'));7$cpu = new phodevi_cpu();8$cpu->read_cpuinfo_line('model name');9print_r($cpu->read_cpuinfo_line('model name'));10$cpu = new phodevi_cpu();11$cpu->read_cpuinfo_line('model name');12print_r($cpu->read_cpuinfo_line('model name'));13$cpu = new phodevi_cpu();14$cpu->read_cpuinfo_line('model name');15print_r($cpu->read_cpuinfo_line('model name'));16$cpu = new phodevi_cpu();17$cpu->read_cpuinfo_line('model name');18print_r($cpu->read_cpuinfo_line('model name'));19$cpu = new phodevi_cpu();20$cpu->read_cpuinfo_line('model name');21print_r($cpu->read_cpuinfo_line('model name'));22$cpu = new phodevi_cpu();23$cpu->read_cpuinfo_line('model name');24print_r($cpu->read_cpuinfo_line('model name'));25$cpu = new phodevi_cpu();26$cpu->read_cpuinfo_line('model name');27print_r($cpu->read_cpuinfo_line('model name'));
read_cpuinfo_line
Using AI Code Generation
1require_once('phodevi.php');2$cpu = phodevi::read_cpuinfo_line('model name');3echo "CPU Model: ".$cpu;4require_once('phodevi.php');5$cpu = phodevi::read_cpuinfo_line('cpu MHz');6echo "CPU Frequency: ".$cpu;7require_once('phodevi.php');8$cpu = phodevi::read_cpuinfo_line('cache size');9echo "CPU Cache: ".$cpu;10require_once('phodevi.php');11$cpu = phodevi::read_cpuinfo_line('cpu cores');12echo "CPU Cores: ".$cpu;13require_once('phodevi.php');14$cpu = phodevi::read_cpuinfo_line('flags');15echo "CPU Flags: ".$cpu;16require_once('phodevi.php');17$cpu = phodevi::read_cpuinfo_line('model name');18echo "CPU Model: ".$cpu;19require_once('phodevi.php');20$cpu = phodevi::read_cpuinfo_line('cpu MHz');21echo "CPU Frequency: ".$cpu;22require_once('phodevi.php');23$cpu = phodevi::read_cpuinfo_line('cache size');24echo "CPU Cache: ".$cpu;25require_once('phodevi.php');26$cpu = phodevi::read_cpuinfo_line('cpu cores');27echo "CPU Cores: ".$cpu;28require_once('phodevi.php');
read_cpuinfo_line
Using AI Code Generation
1require_once 'phodevi.php';2$cpu = new phodevi_cpu();3$cpu->read_cpuinfo_line();4$cpu->print_cpuinfo_line();5require_once 'phodevi.php';6$cpu = new phodevi_cpu();7$cpu->read_cpuinfo_line();8$cpu->print_cpuinfo_line();9require_once 'phodevi.php';10$cpu = new phodevi_cpu();11$cpu->read_cpuinfo_line();12$cpu->print_cpuinfo_line();13require_once 'phodevi.php';14$cpu = new phodevi_cpu();15$cpu->read_cpuinfo_line();16$cpu->print_cpuinfo_line();17require_once 'phodevi.php';18$cpu = new phodevi_cpu();19$cpu->read_cpuinfo_line();20$cpu->print_cpuinfo_line();21require_once 'phodevi.php';22$cpu = new phodevi_cpu();23$cpu->read_cpuinfo_line();24$cpu->print_cpuinfo_line();25require_once 'phodevi.php';26$cpu = new phodevi_cpu();27$cpu->read_cpuinfo_line();28$cpu->print_cpuinfo_line();29require_once 'phodevi.php';30$cpu = new phodevi_cpu();31$cpu->read_cpuinfo_line();32$cpu->print_cpuinfo_line();33require_once 'phodevi.php';34$cpu = new phodevi_cpu();35$cpu->read_cpuinfo_line();36$cpu->print_cpuinfo_line();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with read_cpuinfo_line on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!