summaryrefslogtreecommitdiff
path: root/seivot
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-05-02 13:05:48 +0100
committerLars Wirzenius <liw@liw.fi>2011-05-02 13:05:48 +0100
commit51b199a20f37baa7775ea30438f213ab087d08a7 (patch)
treed7f6381927bd58643ad048b6e1ae948d857425dc /seivot
parent2e2b6904bb3a59d75703e6d451dd377e4cd2a8b6 (diff)
downloadseivot-51b199a20f37baa7775ea30438f213ab087d08a7.tar.gz
Add function for dropping caches.
Diffstat (limited to 'seivot')
-rwxr-xr-xseivot16
1 files changed, 15 insertions, 1 deletions
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