diff options
Diffstat (limited to 'meta/lib/oeqa/buildperf/base.py')
| -rw-r--r-- | meta/lib/oeqa/buildperf/base.py | 78 |
1 files changed, 77 insertions, 1 deletions
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""" |
| 13 | from oeqa.utils.commands import runCmd | 13 | import logging |
| 14 | import os | ||
| 15 | import shutil | ||
| 16 | import time | ||
| 17 | from datetime import datetime | ||
| 18 | |||
| 19 | from oeqa.utils.commands import runCmd, get_bb_vars | ||
| 20 | |||
| 21 | # Get logger for this module | ||
| 22 | log = logging.getLogger('build-perf') | ||
| 14 | 23 | ||
| 15 | 24 | ||
| 16 | class KernelDropCaches(object): | 25 | class 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 | |||
| 58 | class 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) | ||
