def testParsePowerMetricsOutput(self):
    power_monitor = powermetrics_power_monitor.PowerMetricsPowerMonitor(
        mac_platform_backend.MacPlatformBackend())
    if not power_monitor.CanMonitorPower():
      logging.warning('Test not supported on this platform.')
      return

    # Not supported on Mac at this time.
    self.assertFalse(power_monitor.CanMeasurePerApplicationPower())

    # Supported hardware reports power samples and energy consumption.
    result = _parsePowerMetricsDataFromTestFile('powermetrics_output.output')

    self.assertTrue(result['energy_consumption_mwh'] > 0)

    # Verify platform info exists in output.
    self.assertTrue(result['platform_info']['average_frequency_hz'] > 0)
    self.assertTrue(result['platform_info']['idle_percent'] > 0)

    # Verify that all component entries exist in output.
    component_utilization = result['component_utilization']
    for k in ['gpu'] + ['cpu%d' % x for x in range(8)]:
      self.assertTrue(component_utilization[k]['average_frequency_hz'] > 0)
      self.assertTrue(component_utilization[k]['idle_percent'] > 0)

    # Unsupported hardware doesn't.
    result = _parsePowerMetricsDataFromTestFile(
        'powermetrics_output_unsupported_hardware.output')
    self.assertNotIn('energy_consumption_mwh', result)
 def testCanMonitorPowerUsage(self):
   backend = mac_platform_backend.MacPlatformBackend()
   power_monitor = powermetrics_power_monitor.PowerMetricsPowerMonitor(backend)
   mavericks_or_later = (
       backend.GetOSVersionName() >= os_version.MAVERICKS)
   # Should always be able to monitor power usage on OS Version >= 10.9 .
   self.assertEqual(
       power_monitor.CanMonitorPower(), mavericks_or_later,
       "Error checking powermetrics availability: '%s'" % '|'.join(os.uname()))
Пример #3
0
 def __init__(self):
     super(MacPlatformBackend, self).__init__()
     self.libproc = None
     self._power_monitor = powermetrics_power_monitor.PowerMetricsPowerMonitor(
         self)