Best Phoronix-test-suite code snippet using phodevi_osx_parser.read_osx_system_profiler
phodevi_memory.php
Source: phodevi_memory.php
...41 $mem_manufacturer = false;42 $mem_part = false;43 if(phodevi::is_macosx())44 {45 $mem_size = phodevi_osx_parser::read_osx_system_profiler('SPMemoryDataType', 'Size', true, array('Empty'));46 $mem_speed = phodevi_osx_parser::read_osx_system_profiler('SPMemoryDataType', 'Speed');47 $mem_type = phodevi_osx_parser::read_osx_system_profiler('SPMemoryDataType', 'Type');48 }49 else if(phodevi::is_solaris())50 {51 $mem_size = phodevi_solaris_parser::read_sun_ddu_dmi_info('MemoryDevice*,InstalledSize');52 $mem_speed = phodevi_solaris_parser::read_sun_ddu_dmi_info('MemoryDevice*,Speed');53 $mem_type = phodevi_solaris_parser::read_sun_ddu_dmi_info('MemoryDevice*,MemoryDeviceType');54 if(is_array($mem_speed) && count($mem_speed) > 0)55 {56 $mem_speed = array_shift($mem_speed);57 }58 $mem_speed = str_replace('MHZ', 'MHz', $mem_speed);59 }60 else if(phodevi::is_windows())61 {62 $mem_size = phodevi_windows_parser::read_cpuz('DIMM #', 'Size', true);63 foreach($mem_size as $key => &$individual_size)64 {65 $individual_size = pts_arrays::first_element(explode(' ', $individual_size));66 if(!is_numeric($individual_size))67 {68 unset($mem_size[$key]);69 } 70 }71 $mem_type = phodevi_windows_parser::read_cpuz('Memory Type', null);72 $mem_speed = intval(phodevi_windows_parser::read_cpuz('Memory Frequency', null)) . 'MHz';73 }74 else if(phodevi::is_linux())75 {76 $mem_size = phodevi_linux_parser::read_dmidecode('memory', 'Memory Device', 'Size', false, array('Not Installed', 'No Module Installed', 'Undefined'));77 $mem_speed = phodevi_linux_parser::read_dmidecode('memory', 'Memory Device', 'Configured Clock Speed', true, array('Unknown', 'Undefined'));78 if($mem_speed == false)79 {80 // "Speed" only reports stock frequency where "Configured Clock Speed" should report the over/underclocked memory81 $mem_speed = phodevi_linux_parser::read_dmidecode('memory', 'Memory Device', 'Speed', true, array('Unknown', 'Undefined'));82 }83 $mem_type = phodevi_linux_parser::read_dmidecode('memory', 'Memory Device', 'Type', true, array('Unknown', 'Other', 'Flash', 'Undefined'));84 $mem_manufacturer = phodevi_linux_parser::read_dmidecode('memory', 'Memory Device', 'Manufacturer', true, array('Unknown', 'Undefined'));85 $mem_part = phodevi_linux_parser::read_dmidecode('memory', 'Memory Device', 'Part Number', true, array('Unknown', 'Undefined'));86 }87 if(is_array($mem_type))88 {89 $mem_type = array_pop($mem_type);90 }91 if($mem_size != false && (!is_array($mem_size) || count($mem_size) != 0))92 {93 for($i = 0; $i < count($mem_size); $i++)94 {95 switch(substr($mem_size[$i], -1))96 {97 case 'K':98 // looks like sometimes Solaris now reports flash chip as memory. its string ends with K99 unset($mem_size[$i]);100 unset($mem_speed[$i]);101 unset($mem_type[$i]);102 break;103 case 'M':104 // report megabytes as MB, just not M, as on Solaris105 $mem_size[$i] .= 'B';106 break;107 case 'B':108 if(strtolower(substr($mem_size[$i], -2, 1)) == 'k')109 {110 // some hardware on Linux via dmidecode reports flash chips111 unset($mem_size[$i]);112 //unset($mem_speed[$i]);113 //unset($mem_type[$i]);114 }115 break;116 }117 }118 foreach($mem_size as $i => $mem_stick)119 {120 if(!is_numeric(substr($mem_stick, 0, 3)) && stripos($mem_stick, 'GB') == false)121 {122 // If the memory size isn't at least three digits (basically 128MB+), chances are something is wrong, i.e. reporting flash chip from dmidecode, so get rid of it.123 unset($mem_size[$i]);124 }125 }126 $mem_count = count($mem_size);127 if(!empty($mem_type))128 {129 if(($cut = strpos($mem_type, ' ')) > 0)130 {131 $mem_type = substr($mem_type, 0, $cut);132 }133 if(!in_array($mem_type, array('Other')) && (pts_strings::keep_in_string($mem_type, pts_strings::CHAR_NUMERIC | pts_strings::CHAR_LETTER) == $mem_type || phodevi::is_windows()))134 {135 $mem_prefix = $mem_type;136 }137 }138 else139 {140 $mem_prefix = null;141 }142 if(!empty($mem_speed))143 {144 if(($cut = strpos($mem_speed, ' (')) > 0)145 {146 $mem_speed = substr($mem_speed, 0, $cut);147 }148 if(!empty($mem_prefix))149 {150 $mem_prefix .= '-';151 }152 $mem_prefix .= str_replace(' ', null, $mem_speed);153 }154 // TODO: Allow a combination of both functions below, so like 2 x 2GB + 3 x 1GB DDR2-800155 if($mem_count > 1 && count(array_unique($mem_size)) > 1)156 {157 $mem_string = implode(' + ', $mem_size) . ' ' . $mem_prefix;158 }159 else160 {161 if(($mem_count * $mem_size[0]) != phodevi::read_property('memory', 'capacity') && phodevi::read_property('memory', 'capacity') % $mem_size[0] == 0)162 {163 // This makes sure the correct number of RAM modules is reported...164 // On at least Linux with dmidecode on an AMD Opteron multi-socket setup it's only showing the data for one socket165 if($mem_size[0] < 1024)166 {167 $mem_size[0] *= 1024;168 }169 $mem_count = phodevi::read_property('memory', 'capacity') / $mem_size[0];170 }171 $product_string = null;172 if(isset($mem_manufacturer[2]) && pts_strings::is_alpha($mem_manufacturer[0]) && stripos($mem_manufacturer, 'manufacturer') === false && stripos($mem_manufacturer, 'part') === false && stripos($mem_manufacturer, 'module') === false && stripos($mem_manufacturer, 'dimm') === false && isset($mem_manufacturer[2]) && pts_strings::is_alpha($mem_manufacturer))173 {174 $product_string .= ' ' . $mem_manufacturer;175 }176 if(($x = strpos($mem_part, '/')) !== false)177 {178 // Cleanup/shorten strings like KHX2133C13S4/4G179 $mem_part = substr($mem_part, 0, $x);180 }181 if(isset($mem_part[2]) && stripos($mem_part, 'part') === false && stripos($mem_part, 'module') === false && stripos($mem_part, 'dimm') === false && substr($mem_part, 0, 2) != '0x' && !isset($mem_part[24]) && pts_strings::is_alnum($mem_part))182 {183 $product_string .= ' ' . $mem_part;184 }185 if(is_numeric($mem_size[0]) && stripos($mem_size[0], 'b') === false)186 {187 if($mem_size >= 1024)188 {189 $mem_size[0] .= ' MB';190 }191 else192 {193 $mem_size[0] .= ' GB';194 }195 }196 $mem_string = $mem_count . ' x ' . $mem_size[0] . ' ' . $mem_prefix . $product_string;197 }198 }199 if(empty($mem_string))200 {201 $mem_string = phodevi::read_property('memory', 'capacity');202 if($mem_string != null)203 {204 $mem_string .= 'MB';205 }206 }207 return trim($mem_string);208 }209 public static function memory_capacity()210 {211 // Returns physical memory capacity212 if(isset(phodevi::$vfs->meminfo))213 {214 $info = phodevi::$vfs->meminfo;215 $info = substr($info, strpos($info, 'MemTotal:') + 9);216 $info = intval(trim(substr($info, 0, strpos($info, 'kB'))));217 $info = floor($info / 1024);218 if(is_numeric($info) && $info > 950)219 {220 if($info > 4608)221 {222 $info = ceil($info / 1024) * 1024;223 }224 else if($info > 1536)225 {226 $info = ceil($info / 512) * 512;227 }228 else229 {230 $info = ceil($info / 256) * 256;231 }232 }233 }234 else if(phodevi::is_solaris())235 {236 $info = shell_exec('prtconf 2>&1 | grep Memory');237 $info = substr($info, strpos($info, ':') + 2);238 $info = substr($info, 0, strpos($info, 'Megabytes'));239 }240 else if(phodevi::is_bsd())241 {242 $mem_size = phodevi_bsd_parser::read_sysctl('hw.physmem');243 if($mem_size == false)244 {245 $mem_size = phodevi_bsd_parser::read_sysctl('hw.realmem');246 }247 $info = ceil(floor($mem_size / 1048576) / 256) * 256;248 }249 else if(phodevi::is_macosx())250 {251 $info = phodevi_osx_parser::read_osx_system_profiler('SPHardwareDataType', 'Memory');252 $info = explode(' ', $info);253 $info = (isset($info[1]) && $info[1] == 'GB' ? $info[0] * 1024 : $info[0]);254 }255 else if(phodevi::is_windows())256 {257 $info = phodevi_windows_parser::read_cpuz('Memory Size', null);258 if($info != null)259 {260 if(($e = strpos($info, ' MBytes')) !== false)261 {262 $info = substr($info, 0, $e);263 }264 $info = trim($info);265 }...
sys_power.php
Source: sys_power.php
...119 }120 }121 else if(phodevi::is_macosx())122 {123 $current = abs(phodevi_osx_parser::read_osx_system_profiler('SPPowerDataType', 'Amperage')); // in mA124 }125 return $current;126 }127 private static function sys_battery_power()128 {129 // Returns power consumption rate in mW130 $rate = -1;131 if(phodevi::is_linux())132 {133 $power_now = phodevi_linux_parser::read_sysfs_node('/sys/class/power_supply/*/power_now', 'POSITIVE_NUMERIC', array('status' => 'Discharging'));134 if($power_now != -1)135 {136 // sysfs power_now seems to be displayed in microWatts137 $rate = pts_math::set_precision($power_now / 1000, 2);138 }139 if($rate == -1)140 {141 $battery = array('/battery/BAT0/state', '/battery/BAT1/state');142 $state = phodevi_linux_parser::read_acpi($battery, 'charging state');143 $power = phodevi_linux_parser::read_acpi($battery, 'present rate');144 $voltage = phodevi_linux_parser::read_acpi($battery, 'present voltage');145 if($state == 'discharging')146 {147 $power_unit = substr($power, strrpos($power, ' ') + 1);148 $power = substr($power, 0, strpos($power, ' '));149 if($power_unit == 'mA')150 {151 $voltage_unit = substr($voltage, strrpos($voltage, ' ') + 1);152 $voltage = substr($voltage, 0, strpos($voltage, ' '));153 if($voltage_unit == 'mV')154 {155 $rate = round(($power * $voltage) / 1000);156 }157 }158 else if($power_unit == 'mW')159 {160 $rate = $power;161 }162 }163 }164 if($rate == -1 && is_file('/sys/class/power_supply/BAT0/voltage_now') && is_file('/sys/class/power_supply/BAT0/current_now'))165 {166 $voltage_now = pts_file_io::file_get_contents('/sys/class/power_supply/BAT0/voltage_now') / 1000;167 $current_now = pts_file_io::file_get_contents('/sys/class/power_supply/BAT0/current_now') / 1000;168 $power_now = $voltage_now * $current_now / 1000;169 if($power_now > 1)170 {171 $rate = $power_now;172 }173 }174 if($rate == -1 && is_file('/sys/class/power_supply/BAT1/voltage_now') && is_file('/sys/class/power_supply/BAT1/current_now'))175 {176 $voltage_now = pts_file_io::file_get_contents('/sys/class/power_supply/BAT1/voltage_now') / 1000;177 $current_now = pts_file_io::file_get_contents('/sys/class/power_supply/BAT1/current_now') / 1000;178 $power_now = $voltage_now * $current_now / 1000;179 if($power_now > 1)180 {181 $rate = $power_now;182 }183 }184 }185 else if(phodevi::is_macosx())186 {187 $amperage = abs(phodevi_osx_parser::read_osx_system_profiler('SPPowerDataType', 'Amperage')); // in mA188 $voltage = phodevi_osx_parser::read_osx_system_profiler('SPPowerDataType', 'Voltage'); // in mV189 if($amperage > 0 && $voltage > 0)190 {191 $rate = round(($amperage * $voltage) / 1000);192 }193 else if(pts_client::executable_in_path('ioreg'))194 {195 $ioreg = trim(shell_exec("ioreg -l | grep LegacyBatteryInfo | cut -d '{' -f 2 | tr -d \} | tr ',' '=' | awk -F'=' '{print ($2*$10/10^22)}' 2>&1"));196 if(is_numeric($ioreg) && $ioreg > 0)197 {198 $rate = $ioreg;199 }200 }201 }202 else if(phodevi::is_solaris())...
Check out the latest blogs from LambdaTest on this topic:
Have you ever visited a website that only has plain text and images? Most probably, no. It’s because such websites do not exist now. But there was a time when websites only had plain text and images with almost no styling. For the longest time, websites did not focus on user experience. For instance, this is how eBay’s homepage looked in 1999.
Pair testing can help you complete your testing tasks faster and with higher quality. But who can do pair testing, and when should it be done? And what form of pair testing is best for your circumstance? Check out this blog for more information on how to conduct pair testing to optimize its benefits.
Continuous integration is a coding philosophy and set of practices that encourage development teams to make small code changes and check them into a version control repository regularly. Most modern applications necessitate the development of code across multiple platforms and tools, so teams require a consistent mechanism for integrating and validating changes. Continuous integration creates an automated way for developers to build, package, and test their applications. A consistent integration process encourages developers to commit code changes more frequently, resulting in improved collaboration and code quality.
Greetings folks! With the new year finally upon us, we’re excited to announce a collection of brand-new product updates. At LambdaTest, we strive to provide you with a comprehensive test orchestration and execution platform to ensure the ultimate web and mobile experience.
Development practices are constantly changing and as testers, we need to embrace change. One of the changes that we can experience is the move from monthly or quarterly releases to continuous delivery or continuous deployment. This move to continuous delivery or deployment offers testers the chance to learn new skills.
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_osx_system_profiler 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!!