diff options
author | Markus Lehtonen <markus.lehtonen@linux.intel.com> | 2016-06-23 18:48:11 +0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-07-01 16:22:47 +0100 |
commit | c3ee14ef38f73c3a782b0fc8333ce437d165e4ff (patch) | |
tree | 86c9232aafb2aebf87696bdf69b1f19f2711d54a /scripts | |
parent | eb36f0000205230e78ab326d8ae6a504939af9c8 (diff) | |
download | poky-c3ee14ef38f73c3a782b0fc8333ce437d165e4ff.tar.gz |
oe-build-perf-test: enable locking
Makes it possible to guard that multiple tests are not run in parallel.
(From OE-Core rev: 181e92e7a1bccf678b3eb1bf547608a142784f97)
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 'scripts')
-rwxr-xr-x | scripts/oe-build-perf-test | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/scripts/oe-build-perf-test b/scripts/oe-build-perf-test index 9dd073cdfb..64873c90aa 100755 --- a/scripts/oe-build-perf-test +++ b/scripts/oe-build-perf-test | |||
@@ -15,6 +15,8 @@ | |||
15 | # | 15 | # |
16 | """Build performance test script""" | 16 | """Build performance test script""" |
17 | import argparse | 17 | import argparse |
18 | import errno | ||
19 | import fcntl | ||
18 | import logging | 20 | import logging |
19 | import os | 21 | import os |
20 | import sys | 22 | import sys |
@@ -33,6 +35,19 @@ logging.basicConfig(level=logging.INFO, format=LOG_FORMAT) | |||
33 | log = logging.getLogger() | 35 | log = logging.getLogger() |
34 | 36 | ||
35 | 37 | ||
38 | def acquire_lock(lock_f): | ||
39 | """Acquire flock on file""" | ||
40 | log.debug("Acquiring lock %s", os.path.abspath(lock_f.name)) | ||
41 | try: | ||
42 | fcntl.flock(lock_f, fcntl.LOCK_EX | fcntl.LOCK_NB) | ||
43 | except IOError as err: | ||
44 | if err.errno == errno.EAGAIN: | ||
45 | return False | ||
46 | raise | ||
47 | log.debug("Lock acquired") | ||
48 | return True | ||
49 | |||
50 | |||
36 | def pre_run_sanity_check(): | 51 | def pre_run_sanity_check(): |
37 | """Sanity check of build environment""" | 52 | """Sanity check of build environment""" |
38 | build_dir = os.environ.get("BUILDDIR") | 53 | build_dir = os.environ.get("BUILDDIR") |
@@ -72,6 +87,9 @@ def parse_args(argv): | |||
72 | help='Enable debug level logging') | 87 | help='Enable debug level logging') |
73 | parser.add_argument('--globalres-file', | 88 | parser.add_argument('--globalres-file', |
74 | help="Append results to 'globalres' csv file") | 89 | help="Append results to 'globalres' csv file") |
90 | parser.add_argument('--lock-file', default='./oe-build-perf.lock', | ||
91 | metavar='FILENAME', | ||
92 | help="Lock file to use") | ||
75 | 93 | ||
76 | return parser.parse_args(argv) | 94 | return parser.parse_args(argv) |
77 | 95 | ||
@@ -83,6 +101,11 @@ def main(argv=None): | |||
83 | if args.debug: | 101 | if args.debug: |
84 | log.setLevel(logging.DEBUG) | 102 | log.setLevel(logging.DEBUG) |
85 | 103 | ||
104 | lock_f = open(args.lock_file, 'w') | ||
105 | if not acquire_lock(lock_f): | ||
106 | log.error("Another instance of this script is running, exiting...") | ||
107 | return 1 | ||
108 | |||
86 | if not pre_run_sanity_check(): | 109 | if not pre_run_sanity_check(): |
87 | return 1 | 110 | return 1 |
88 | 111 | ||