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 that all component entries exist in output.
    component_utilization = result['component_utilization']
    for k in ['whole_package', '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)
Example #2
0
    def testParsePowerMetricsOutput(self):
        def getOutput(output_file):
            test_data_path = os.path.join(util.GetUnittestDataDir(),
                                          output_file)
            with open(test_data_path, 'r') as f:
                process_output = f.read()
            return (powermetrics_power_monitor.PowerMetricsPowerMonitor.
                    ParsePowerMetricsOutput(process_output))

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

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

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

        # Verify that all component entries exist in output.
        component_utilization = result['component_utilization']
        for k in ['whole_package', '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 = getOutput('powermetrics_output_unsupported_hardware.output')
        self.assertNotIn('energy_consumption_mwh', result)
Example #3
0
 def testCanMonitorPowerUsage(self):
   backend = mac_platform_backend.MacPlatformBackend()
   power_monitor = powermetrics_power_monitor.PowerMetricsPowerMonitor(backend)
   mavericks_or_later = (
       backend.GetOSVersionName() >= mac_platform_backend.MAVERICKS)
   # Should always be able to monitor power usage on OS Version >= 10.9 .
   self.assertEqual(power_monitor.CanMonitorPowerAsync(), mavericks_or_later,
       "Error checking powermetrics availability: '%s'" % '|'.join(os.uname()))
Example #4
0
def CreatePlatformBackendForCurrentOS():
    if sys.platform.startswith('linux'):
        return linux_platform_backend.LinuxPlatformBackend()
    elif sys.platform == 'darwin':
        return mac_platform_backend.MacPlatformBackend()
    elif sys.platform == 'win32':
        return win_platform_backend.WinPlatformBackend()
    else:
        raise NotImplementedError()
 def Create(self):
     backend = desktop_browser_backend.DesktopBrowserBackend(
         self._options, self._local_executable, self._is_content_shell,
         self._use_login)
     if sys.platform.startswith('linux'):
         p = linux_platform_backend.LinuxPlatformBackend()
     elif sys.platform == 'darwin':
         p = mac_platform_backend.MacPlatformBackend()
     elif sys.platform == 'win32':
         p = win_platform_backend.WinPlatformBackend()
     else:
         raise NotImplementedError()
     b = browser.Browser(backend, p)
     backend.SetBrowser(b)
     return b
Example #6
0
def _InitHostPlatformIfNeeded():
    global _host_platform
    if _host_platform:
        return

    if sys.platform.startswith('linux'):
        from telemetry.core.platform import linux_platform_backend
        backend = linux_platform_backend.LinuxPlatformBackend()
    elif sys.platform == 'darwin':
        from telemetry.core.platform import mac_platform_backend
        backend = mac_platform_backend.MacPlatformBackend()
    elif sys.platform == 'win32':
        from telemetry.core.platform import win_platform_backend
        backend = win_platform_backend.WinPlatformBackend()
    else:
        raise NotImplementedError()

    _host_platform = Platform(backend)
    def _CreateBrowserInternal(self, delete_profile_dir_after_run):
        backend = desktop_browser_backend.DesktopBrowserBackend(
            self._options,
            self._local_executable,
            self._is_content_shell,
            delete_profile_dir_after_run=delete_profile_dir_after_run)
        if sys.platform.startswith('linux'):
            p = linux_platform_backend.LinuxPlatformBackend()
        elif sys.platform == 'darwin':
            p = mac_platform_backend.MacPlatformBackend()
        elif sys.platform == 'win32':
            p = win_platform_backend.WinPlatformBackend()
        else:
            raise NotImplementedError()

        b = browser.Browser(backend, p)
        backend.SetBrowser(b)
        return (b, backend)