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
16 from telemetry.util import support_binaries
19 class LinuxPlatformBackend(
20 posix_platform_backend.PosixPlatformBackend,
21 proc_supporting_platform_backend.ProcSupportingPlatformBackend):
23 def StartRawDisplayFrameRateMeasurement(self):
24 raise NotImplementedError()
26 def StopRawDisplayFrameRateMeasurement(self):
27 raise NotImplementedError()
29 def GetRawDisplayFrameRateMeasurements(self):
30 raise NotImplementedError()
32 def IsThermallyThrottled(self):
33 raise NotImplementedError()
35 def HasBeenThermallyThrottled(self):
36 raise NotImplementedError()
42 def GetOSVersionName(self):
43 if not os.path.exists('/etc/lsb-release'):
44 raise NotImplementedError('Unknown Linux OS version')
48 with open('/etc/lsb-release') as f:
49 for line in f.readlines():
50 key, _, value = line.partition('=')
51 if key == 'DISTRIB_CODENAME':
52 codename = value.strip()
53 elif key == 'DISTRIB_RELEASE':
54 version = float(value)
55 if codename and version:
57 return platform_backend.OSVersion(codename, version)
59 def CanFlushIndividualFilesFromSystemCache(self):
62 def FlushEntireSystemCache(self):
63 p = subprocess.Popen(['/sbin/sysctl', '-w', 'vm.drop_caches=3'])
65 assert p.returncode == 0, 'Failed to flush system cache'
67 def CanLaunchApplication(self, application):
68 if application == 'ipfw' and not self._IsIpfwKernelModuleInstalled():
70 return super(LinuxPlatformBackend, self).CanLaunchApplication(application)
72 def InstallApplication(self, application):
73 if application == 'ipfw':
75 elif application == 'avconv':
78 raise NotImplementedError(
79 'Please teach Telemetry how to install ' + application)
81 def _IsIpfwKernelModuleInstalled(self):
82 return 'ipfw_mod' in subprocess.Popen(
83 ['lsmod'], stdout=subprocess.PIPE).communicate()[0]
85 def _InstallIpfw(self):
86 ipfw_bin = support_binaries.FindPath('ipfw', self.GetOSName())
87 ipfw_mod = support_binaries.FindPath('ipfw_mod.ko', self.GetOSName())
90 changed = cloud_storage.GetIfChanged(
91 ipfw_bin, cloud_storage.INTERNAL_BUCKET)
92 changed |= cloud_storage.GetIfChanged(
93 ipfw_mod, cloud_storage.INTERNAL_BUCKET)
94 except cloud_storage.CloudStorageError, e:
96 logging.error('You may proceed by manually installing dummynet. See: '
97 'http://info.iet.unipi.it/~luigi/dummynet/')
100 if changed or not self.CanLaunchApplication('ipfw'):
101 if not self._IsIpfwKernelModuleInstalled():
102 subprocess.check_call(['sudo', 'insmod', ipfw_mod])
103 os.chmod(ipfw_bin, 0755)
104 subprocess.check_call(['sudo', 'cp', ipfw_bin, '/usr/local/sbin'])
106 assert self.CanLaunchApplication('ipfw'), 'Failed to install ipfw'
108 def _InstallAvconv(self):
109 avconv_bin = support_binaries.FindPath('avconv', self.GetOSName())
110 os.environ['PATH'] += os.pathsep + os.path.join(util.GetTelemetryDir(),
114 cloud_storage.GetIfChanged(avconv_bin, cloud_storage.INTERNAL_BUCKET)
115 except cloud_storage.CloudStorageError, e:
117 logging.error('You may proceed by manually installing avconv via:\n'
118 'sudo apt-get install libav-tools')
121 assert self.CanLaunchApplication('avconv'), 'Failed to install avconv'