1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
10 from telemetry import decorators
11 from telemetry.core import util
12 from telemetry.core.platform import platform_backend
13 from telemetry.core.platform import posix_platform_backend
14 from telemetry.core.platform import proc_supporting_platform_backend
15 from telemetry.page import cloud_storage
18 class LinuxPlatformBackend(
19 posix_platform_backend.PosixPlatformBackend,
20 proc_supporting_platform_backend.ProcSupportingPlatformBackend):
22 def StartRawDisplayFrameRateMeasurement(self):
23 raise NotImplementedError()
25 def StopRawDisplayFrameRateMeasurement(self):
26 raise NotImplementedError()
28 def GetRawDisplayFrameRateMeasurements(self):
29 raise NotImplementedError()
31 def IsThermallyThrottled(self):
32 raise NotImplementedError()
34 def HasBeenThermallyThrottled(self):
35 raise NotImplementedError()
41 def GetOSVersionName(self):
42 if not os.path.exists('/etc/lsb-release'):
43 raise NotImplementedError('Unknown Linux OS version')
47 for line in open('/etc/lsb-release', 'r').readlines():
48 key, _, value = line.partition('=')
49 if key == 'DISTRIB_CODENAME':
50 codename = value.strip()
51 elif key == 'DISTRIB_RELEASE':
52 version = float(value)
53 if codename and version:
55 return platform_backend.OSVersion(codename, version)
57 def CanFlushIndividualFilesFromSystemCache(self):
60 def FlushEntireSystemCache(self):
61 p = subprocess.Popen(['/sbin/sysctl', '-w', 'vm.drop_caches=3'])
63 assert p.returncode == 0, 'Failed to flush system cache'
65 def CanLaunchApplication(self, application):
66 if application == 'ipfw' and not self._IsIpfwKernelModuleInstalled():
68 return super(LinuxPlatformBackend, self).CanLaunchApplication(application)
70 def InstallApplication(self, application):
71 if application == 'ipfw':
73 elif application == 'avconv':
76 raise NotImplementedError(
77 'Please teach Telemetry how to install ' + application)
79 def _IsIpfwKernelModuleInstalled(self):
80 return 'ipfw_mod' in subprocess.Popen(
81 ['lsmod'], stdout=subprocess.PIPE).communicate()[0]
83 def _InstallIpfw(self):
84 ipfw_bin = os.path.join(util.GetTelemetryDir(), 'bin', 'ipfw')
85 ipfw_mod = os.path.join(util.GetTelemetryDir(), 'bin', 'ipfw_mod.ko')
88 changed = cloud_storage.GetIfChanged(
89 ipfw_bin, cloud_storage.INTERNAL_BUCKET)
90 changed |= cloud_storage.GetIfChanged(
91 ipfw_mod, cloud_storage.INTERNAL_BUCKET)
92 except cloud_storage.CloudStorageError, e:
94 logging.error('You may proceed by manually installing dummynet. See: '
95 'http://info.iet.unipi.it/~luigi/dummynet/')
98 if changed or not self.CanLaunchApplication('ipfw'):
99 if not self._IsIpfwKernelModuleInstalled():
100 subprocess.check_call(['sudo', 'insmod', ipfw_mod])
101 os.chmod(ipfw_bin, 0755)
102 subprocess.check_call(['sudo', 'cp', ipfw_bin, '/usr/local/sbin'])
104 assert self.CanLaunchApplication('ipfw'), 'Failed to install ipfw'
106 def _InstallAvconv(self):
107 telemetry_bin_dir = os.path.join(util.GetTelemetryDir(), 'bin')
108 avconv_bin = os.path.join(telemetry_bin_dir, 'avconv')
109 os.environ['PATH'] += os.pathsep + telemetry_bin_dir
112 cloud_storage.GetIfChanged(avconv_bin, cloud_storage.INTERNAL_BUCKET)
113 except cloud_storage.CloudStorageError, e:
115 logging.error('You may proceed by manually installing avconv via:\n'
116 'sudo apt-get install libav-tools')
119 assert self.CanLaunchApplication('avconv'), 'Failed to install avconv'