• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4
5import os
6import subprocess
7
8from telemetry.core import util
9from telemetry.core.platform import platform_backend
10
11
12class DesktopPlatformBackend(platform_backend.PlatformBackend):
13
14  # This is an abstract class. It is OK to have abstract methods.
15  # pylint: disable=W0223
16
17  def GetFlushUtilityName(self):
18    return NotImplementedError()
19
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()
26
27    args = []
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))
32
33    if not args:
34      return
35
36    # According to msdn:
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.
39    while args:
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])
45      p.wait()
46      assert p.returncode == 0, 'Failed to flush system cache'
47      args = args[256:]
48