1 # Copyright 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.
8 from telemetry.core import util
9 from telemetry.core.platform import platform_backend
12 class DesktopPlatformBackend(platform_backend.PlatformBackend):
14 # This is an abstract class. It is OK to have abstract methods.
15 # pylint: disable=W0223
17 def GetFlushUtilityName(self):
18 return NotImplementedError()
20 def FlushSystemCacheForDirectory(self, directory, ignoring=None):
21 assert directory and os.path.exists(directory), \
22 'Target directory %s must exist' % directory
23 flush_command = util.FindSupportBinary(self.GetFlushUtilityName())
24 assert flush_command, \
25 'You must build %s first' % self.GetFlushUtilityName()
28 directory_contents = os.listdir(directory)
29 for item in directory_contents:
30 if not ignoring or item not in ignoring:
31 args.append(os.path.join(directory, item))
37 # http://msdn.microsoft.com/en-us/library/ms682425%28VS.85%29.aspx
38 # there's a maximum allowable command line of 32,768 characters on windows.
40 # Small note about [:256] and [256:]
41 # [:N] will return a list with the first N elements, ie.
42 # with [1,2,3,4,5], [:2] -> [1,2], and [2:] -> [3,4,5]
43 # with [1,2,3,4,5], [:5] -> [1,2,3,4,5] and [5:] -> []
44 p = subprocess.Popen([flush_command, '--recurse'] + args[:256])
46 assert p.returncode == 0, 'Failed to flush system cache'