summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/buildperf/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/buildperf/base.py')
-rw-r--r--meta/lib/oeqa/buildperf/base.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/meta/lib/oeqa/buildperf/base.py b/meta/lib/oeqa/buildperf/base.py
new file mode 100644
index 0000000000..3cbdfa7818
--- /dev/null
+++ b/meta/lib/oeqa/buildperf/base.py
@@ -0,0 +1,46 @@
1# Copyright (c) 2016, Intel Corporation.
2#
3# This program is free software; you can redistribute it and/or modify it
4# under the terms and conditions of the GNU General Public License,
5# version 2, as published by the Free Software Foundation.
6#
7# This program is distributed in the hope it will be useful, but WITHOUT
8# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
10# more details.
11#
12"""Build performance test base classes and functionality"""
13from oeqa.utils.commands import runCmd
14
15
16class KernelDropCaches(object):
17 """Container of the functions for dropping kernel caches"""
18 sudo_passwd = None
19
20 @classmethod
21 def check(cls):
22 """Check permssions for dropping kernel caches"""
23 from getpass import getpass
24 from locale import getdefaultlocale
25 cmd = ['sudo', '-k', '-n', 'tee', '/proc/sys/vm/drop_caches']
26 ret = runCmd(cmd, ignore_status=True, data=b'0')
27 if ret.output.startswith('sudo:'):
28 pass_str = getpass(
29 "\nThe script requires sudo access to drop caches between "
30 "builds (echo 3 > /proc/sys/vm/drop_caches).\n"
31 "Please enter your sudo password: ")
32 cls.sudo_passwd = bytes(pass_str, getdefaultlocale()[1])
33
34 @classmethod
35 def drop(cls):
36 """Drop kernel caches"""
37 cmd = ['sudo', '-k']
38 if cls.sudo_passwd:
39 cmd.append('-S')
40 input_data = cls.sudo_passwd + b'\n'
41 else:
42 cmd.append('-n')
43 input_data = b''
44 cmd += ['tee', '/proc/sys/vm/drop_caches']
45 input_data += b'3'
46 runCmd(cmd, data=input_data)