summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/buildperf
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2016-05-11 13:22:50 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-07-01 16:22:46 +0100
commit1b10ded015d4375602c6be0b98493002b984d0e5 (patch)
treeb57208e056d3e45fa47f0d6cef372269fdc00170 /meta/lib/oeqa/buildperf
parentcee685ca0d29b022e0665fccf58de006e7ffaef1 (diff)
downloadpoky-1b10ded015d4375602c6be0b98493002b984d0e5.tar.gz
oeqa.buildperf: add BuildPerfTest class
The new class will be used as an abstract base class for build performance tests. This implementation contains some common functionality used in multiple tests, "copied" from the build-perf-test.sh shell script. (From OE-Core rev: 35cd7363759a286e80ddca0d028db3d2bf524b17) Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/buildperf')
-rw-r--r--meta/lib/oeqa/buildperf/__init__.py2
-rw-r--r--meta/lib/oeqa/buildperf/base.py78
2 files changed, 78 insertions, 2 deletions
diff --git a/meta/lib/oeqa/buildperf/__init__.py b/meta/lib/oeqa/buildperf/__init__.py
index bab122e4ec..3bee5b9028 100644
--- a/meta/lib/oeqa/buildperf/__init__.py
+++ b/meta/lib/oeqa/buildperf/__init__.py
@@ -10,4 +10,4 @@
10# more details. 10# more details.
11# 11#
12"""Build performance tests""" 12"""Build performance tests"""
13from .base import KernelDropCaches 13from .base import BuildPerfTest, KernelDropCaches
diff --git a/meta/lib/oeqa/buildperf/base.py b/meta/lib/oeqa/buildperf/base.py
index 3cbdfa7818..3ef038494f 100644
--- a/meta/lib/oeqa/buildperf/base.py
+++ b/meta/lib/oeqa/buildperf/base.py
@@ -10,7 +10,16 @@
10# more details. 10# more details.
11# 11#
12"""Build performance test base classes and functionality""" 12"""Build performance test base classes and functionality"""
13from oeqa.utils.commands import runCmd 13import logging
14import os
15import shutil
16import time
17from datetime import datetime
18
19from oeqa.utils.commands import runCmd, get_bb_vars
20
21# Get logger for this module
22log = logging.getLogger('build-perf')
14 23
15 24
16class KernelDropCaches(object): 25class KernelDropCaches(object):
@@ -44,3 +53,70 @@ class KernelDropCaches(object):
44 cmd += ['tee', '/proc/sys/vm/drop_caches'] 53 cmd += ['tee', '/proc/sys/vm/drop_caches']
45 input_data += b'3' 54 input_data += b'3'
46 runCmd(cmd, data=input_data) 55 runCmd(cmd, data=input_data)
56
57
58class BuildPerfTest(object):
59 """Base class for build performance tests"""
60 name = None
61 description = None
62
63 def __init__(self, out_dir):
64 self.out_dir = out_dir
65 self.results = {'name':self.name,
66 'description': self.description,
67 'status': 'NOTRUN',
68 'start_time': None,
69 'elapsed_time': None,
70 'measurements': []}
71 if not os.path.exists(self.out_dir):
72 os.makedirs(self.out_dir)
73 if not self.name:
74 self.name = self.__class__.__name__
75 self.bb_vars = get_bb_vars()
76
77 def run(self):
78 """Run test"""
79 self.results['status'] = 'FAILED'
80 self.results['start_time'] = datetime.now()
81 self._run()
82 self.results['elapsed_time'] = (datetime.now() -
83 self.results['start_time'])
84 # Test is regarded as completed if it doesn't raise an exception
85 self.results['status'] = 'COMPLETED'
86
87 def _run(self):
88 """Actual test payload"""
89 raise NotImplementedError
90
91 @staticmethod
92 def force_rm(path):
93 """Equivalent of 'rm -rf'"""
94 if os.path.isfile(path) or os.path.islink(path):
95 os.unlink(path)
96 elif os.path.isdir(path):
97 shutil.rmtree(path)
98
99 def rm_tmp(self):
100 """Cleanup temporary/intermediate files and directories"""
101 log.debug("Removing temporary and cache files")
102 for name in ['bitbake.lock', 'conf/sanity_info',
103 self.bb_vars['TMPDIR']]:
104 self.force_rm(name)
105
106 def rm_sstate(self):
107 """Remove sstate directory"""
108 log.debug("Removing sstate-cache")
109 self.force_rm(self.bb_vars['SSTATE_DIR'])
110
111 def rm_cache(self):
112 """Drop bitbake caches"""
113 self.force_rm(self.bb_vars['PERSISTENT_DIR'])
114
115 @staticmethod
116 def sync():
117 """Sync and drop kernel caches"""
118 log.debug("Syncing and dropping kernel caches""")
119 KernelDropCaches.drop()
120 os.sync()
121 # Wait a bit for all the dirty blocks to be written onto disk
122 time.sleep(3)