6 from threading import Thread
7 from threading import Lock
18 __confs_unmeasured__ = []
21 """Prepare for measuring
22 Outcome is Linux image for generated configuration."""
23 print("Preparing new image.")
24 global __confs_unmeasured__
25 if len(__confs_unmeasured__) == 0:
26 dtb = database.database()
27 confs = dtb.get_unmeasured()
29 configurations.generate()
30 confs = dtb.get_unmeasured()
32 raise exceptions.NoApplicableConfiguration()
33 __confs_unmeasured__ = list(confs)
34 con = __confs_unmeasured__.pop()
35 kernel.config(con.config)
36 img = kernel.make(con.hash)
37 print("Prepared image: " + img)
40 def measure(kernelimg, con):
41 print("Measuring " + con.hash)
43 os.remove(sf(conf.jobfolder_linux_image))
44 except FileNotFoundError:
46 os.symlink(kernelimg, sf(conf.jobfolder_linux_image))
48 print("Configuration '" + con.hash + "' measured.")
52 class mainThread(Thread):
55 img, config = prepare()
58 while not __terminate__:
59 img, config = prepare()
62 # Multithread section #
66 class prepareThread(Thread):
67 def __init__(self, name='prepare'):
68 Thread.__init__(self, name=name)
71 while not __terminate__ and len(__conflist__) <= conf.multithread_buffer:
72 __listlock__.release()
74 img, config = prepare()
75 except exceptions.NoApplicableConfiguration:
78 __conflist__.add((img, config))
79 if not __measurethread__.isActive():
80 __measurethread__.start()
81 __listlock__.release()
83 class measureThread(Thread):
84 def __init__(self, name='measure'):
85 Thread.__init__(self, name=name)
88 while not __terminate__ and len(__conflist__) > 0:
89 img, config = __conflist__.pop()
90 __listlock__.release()
91 if not __preparethread__.isActive():
92 __preparethread__.start()
95 __listlock__.release()
97 __preparethread__ = prepareThread()
98 __measurethread__ = measureThread()
100 # Start and sigterm handler #
101 def sigterm_handler(_signo, _stack_frame):
111 except KeyboardInterrupt:
114 #################################################################################
116 if __name__ == '__main__':
117 signal.signal(signal.SIGTERM, sigterm_handler)