From 51b199a20f37baa7775ea30438f213ab087d08a7 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Mon, 2 May 2011 13:05:48 +0100 Subject: Add function for dropping caches. --- seivot | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'seivot') diff --git a/seivot b/seivot index 4709c1d..66c696c 100755 --- a/seivot +++ b/seivot @@ -47,11 +47,25 @@ def runcmd(argv, **kwargs): data = os.read(fd, 1024**2) os.close(fd) if p.returncode != 0: - raise Exception('command failed: %s\n%s' % (argv, err)) + raise cliapp.AppException('command failed: %s\n%s' % (argv, err)) return Measurement(data), out +def drop_caches(): + def sudo_tee(status): + p = subprocess.Popen(['sudo', '-p', 'Password (for clearing cache): ', + 'tee', '/proc/sys/vm/drop_caches'], + stdin=subprocess.PIPE, stdout=subprocess.PIPE) + out, err = p.communicate('%s\n' % status) + if p.returncode != 0: + raise cliapp.AppException('failed to clear cache') + + logging.debug('clearing Linux kernel cache') + sudo_tee(3) + sudo_tee(0) + + class BackupProgram(object): name = None -- cgit v1.2.1