Best Phoronix-test-suite code snippet using cpu_power
cpu_power.php
Source: cpu_power.php
...14 GNU General Public License for more details.15 You should have received a copy of the GNU General Public License16 along with this program. If not, see <http://www.gnu.org/licenses/>.17*/18class cpu_power extends phodevi_sensor19{20 const SENSOR_TYPE = 'cpu';21 const SENSOR_SENSES = 'power';22 static $cpu_energy = 0;23 static $last_time = 0;24 protected static $amd_energy_sockets = false;25 protected static $cpu_power_inputs = false;26 public function read_sensor()27 {28 if(phodevi::is_linux())29 {30 return $this->cpu_power_linux();31 }32 else if(phodevi::is_macosx())33 {34 return self::read_macosx_power_metrics();35 }36 return -1; // TODO make -1 a named constant37 }38 public static function get_unit()39 {40 $unit = null;41 if(phodevi::is_linux() && is_readable('/sys/bus/i2c/drivers/ina3221x/0-0041/iio:device1/in_power1_input'))42 {43 $unit = 'Milliwatts';44 }45 else46 {47 $unit = 'Watts';48 }49 return $unit;50 }51 private function cpu_power_linux()52 {53 $cpu_power = -1;54 if(self::$amd_energy_sockets === false)55 {56 self::$amd_energy_sockets = array();57 foreach(pts_file_io::glob('/sys/class/hwmon/hwmon*/name') as $hwmon)58 {59 if(pts_file_io::file_get_contents($hwmon) == 'amd_energy')60 {61 $hwmon_dir = dirname($hwmon);62 foreach(glob($hwmon_dir . '/energy*_label') as $label)63 {64 if(strpos(file_get_contents($label), 'Esocket') !== false)65 {66 self::$amd_energy_sockets[] = str_replace('_label', '_input', $label);67 }68 }69 break;70 }71 }72 }73 if(self::$cpu_power_inputs === false)74 {75 self::$cpu_power_inputs = array();76 foreach(pts_file_io::glob('/sys/class/hwmon/hwmon*/power*_label') as $hwmon)77 {78 if(pts_file_io::file_get_contents($hwmon) == 'CPU power')79 {80 $hwmon = str_replace('_label', '_input', $hwmon);81 if(pts_file_io::file_get_contents($hwmon) > 0)82 {83 self::$cpu_power_inputs[] = $hwmon;84 }85 }86 }87 }88 if(is_readable('/sys/bus/i2c/drivers/ina3221x/0-0041/iio:device1/in_power1_input'))89 {90 $in_power1_input = pts_file_io::file_get_contents('/sys/bus/i2c/drivers/ina3221x/0-0041/iio:device1/in_power1_input');91 if(is_numeric($in_power1_input) && $in_power1_input > 1)92 {93 $cpu_power = $in_power1_input;94 }95 }96 else if(is_readable('/sys/class/powercap/intel-rapl/intel-rapl:0/energy_uj'))97 {98 $rapl_base_path = "/sys/class/powercap/intel-rapl/intel-rapl:";99 $total_energy = 0;100 for($x = 0; $x <= 128; $x++)101 {102 $rapl_base_path_1 = $rapl_base_path . $x;103 if(is_readable($rapl_base_path_1))104 {105 $energy_uj = pts_file_io::file_get_contents($rapl_base_path_1 . '/energy_uj');106 if(is_numeric($energy_uj))107 {108 $total_energy += $energy_uj;109 }110 }111 else112 {113 break;114 }115 }116 if($total_energy > 1)117 {118 if(self::$cpu_energy == 0)119 {120 self::$cpu_energy = $total_energy;121 self::$last_time = time();122 $cpu_power = 0;123 }124 else125 {126 $cpu_power = ($total_energy - self::$cpu_energy) / (time() - self::$last_time) / 1000000;127 }128 self::$last_time = time();129 self::$cpu_energy = $total_energy;130 }131 }132 else if(!empty(self::$amd_energy_sockets))133 {134 $tries = 0;135 do136 {137 $tries++;138 $j1 = 0;139 $j2 = 0;140 foreach(self::$amd_energy_sockets as $f)141 {142 $j1 += trim(file_get_contents($f));143 }144 sleep(1);145 foreach(self::$amd_energy_sockets as $f)146 {147 $j2 += trim(file_get_contents($f));148 }149 $cpu_power = ($j2 - $j1) * 0.0000010;150 // This loop is in case the counters roll over151 }152 while($cpu_power < 1 && $tries < 2);153 }154 else if(!empty(self::$cpu_power_inputs))155 {156 // APM XGene / Ampere Computing157 $cpu_uwatts = 0;158 foreach(self::$cpu_power_inputs as $power_input)159 {160 $pi = pts_file_io::file_get_contents($power_input);161 if(is_numeric($pi))162 {163 $cpu_uwatts += $pi;164 }165 }166 $cpu_power = $cpu_uwatts / 1000000;167 }168 else if(is_readable('/sys/class/hwmon/hwmon0/name') && pts_file_io::file_get_contents('/sys/class/hwmon/hwmon0/name') == 'zenpower')169 {170 foreach(pts_file_io::glob('/sys/class/hwmon/hwmon*/power*_label') as $label)171 {172 if(pts_file_io::file_get_contents($label) == 'SVI2_P_SoC')173 {174 $cpu_power += pts_file_io::file_get_contents(str_replace('_label', '_input', $label));175 }176 }177 if($cpu_power > 100000)178 {179 $cpu_power = $cpu_power / 100000;180 }181 }182 return round($cpu_power, 2);183 }184 public static function read_macosx_power_metrics()185 {186 $watts = 0;187 if(pts_client::executable_in_path('powermetrics'))188 {189 $powermetrics = shell_exec("sudo -n powermetrics -n 1 -i 1 --samplers cpu_power 2>&1");190 if(($x = strpos($powermetrics, 'Package Power: ')) !== false)191 {192 $powermetrics = substr($powermetrics, $x + strlen('Package Power: '));193 if(($x = strpos($powermetrics, ' mW')) !== false)194 {195 $powermetrics = substr($powermetrics, 0, $x);196 if(is_numeric($powermetrics) && $powermetrics > 0)197 {198 $watts = $powermetrics / 1000;199 }200 }201 }202 }203 return $watts;...
cpu_power
Using AI Code Generation
1include_once('pts-core/pts-core.php');2include_once('pts-core/objects/pts_test_profile.php');3include_once('pts-core/objects/pts_test_result.php');4include_once('pts-core/objects/pts_result_file_analyzer.php');5include_once('pts-core/objects/pts_result_file.php');6include_once('pts-core/objects/pts_test_run_request.php');7include_once('pts-core/objects/pts_test_run_manager.php');8include_once('pts-core/objects/pts_test_run_request.php');9include_once('p
cpu_power
Using AI Code Generation
1require_once('pts-core/pts-core.php');2$power = new cpu_power();3$power->start();4$power->stop();5require_once('pts-core/pts-core.php');6$power = new cpu_power();7$power->start();8$power->stop();
cpu_power
Using AI Code Generation
1require_once(PTS_CORE_STATIC_PATH . 'pts_test_installer.php');2$test = new pts_test_installer();3$test->install_test('cpu_power', false, false);4$test = new pts_test_run_manager('cpu_power');5$test->test_profile->set_test_installation(false);6$test->test_profile->set_test_arguments(array('--iterations', '2'));7$test->test_profile->set_result_scale('Watts');
Check out the latest blogs from LambdaTest on this topic:
Anyone who has worked in the software industry for a while can tell you stories about projects that were on the verge of failure. Many initiatives fail even before they reach clients, which is especially disheartening when the failure is fully avoidable.
Entering the world of testers, one question started to formulate in my mind: “what is the reason that bugs happen?”.
Automating testing is a crucial step in the development pipeline of a software product. In an agile development environment, where there is continuous development, deployment, and maintenance of software products, automation testing ensures that the end software products delivered are error-free.
In some sense, testing can be more difficult than coding, as validating the efficiency of the test cases (i.e., the ‘goodness’ of your tests) can be much harder than validating code correctness. In practice, the tests are just executed without any validation beyond the pass/fail verdict. On the contrary, the code is (hopefully) always validated by testing. By designing and executing the test cases the result is that some tests have passed, and some others have failed. Testers do not know much about how many bugs remain in the code, nor about their bug-revealing efficiency.
In my last blog, I investigated both the stateless and the stateful class of model-based testing. Both have some advantages and disadvantages. You can use them for different types of systems, depending on whether a stateful solution is required or a stateless one is enough. However, a better solution is to use an aggregate technique that is appropriate for each system. Currently, the only aggregate solution is action-state testing, introduced in the book Paradigm Shift in Software Testing. This method is implemented in Harmony.
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.
Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.
Test now for FreeGet 100 minutes of automation test minutes FREE!!