diff options
author | Lars Wirzenius <liw@liw.fi> | 2011-05-02 13:05:48 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2011-05-02 13:05:48 +0100 |
commit | 51b199a20f37baa7775ea30438f213ab087d08a7 (patch) | |
tree | d7f6381927bd58643ad048b6e1ae948d857425dc /seivot | |
parent | 2e2b6904bb3a59d75703e6d451dd377e4cd2a8b6 (diff) | |
download | seivot-51b199a20f37baa7775ea30438f213ab087d08a7.tar.gz |
Add function for dropping caches.
Diffstat (limited to 'seivot')
-rwxr-xr-x | seivot | 16 |
1 files changed, 15 insertions, 1 deletions
@@ -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 |