6 from threading import Thread
7 from threading import Lock
19 __confs_unmeasured__ = []
22 """Prepare for measuring
23 Outcome is Linux image for generated configuration."""
24 print("Preparing new image.")
25 global __confs_unmeasured__
26 if len(__confs_unmeasured__) == 0:
27 dtb = database.database()
28 confs = dtb.get_unmeasured()
30 configurations.generate()
31 confs = dtb.get_unmeasured()
33 raise exceptions.NoApplicableConfiguration()
34 __confs_unmeasured__ = list(confs)
35 con = __confs_unmeasured__.pop()
36 kernel.config(con.config)
37 img = kernel.make(con.hash)
38 print("Prepared image: " + img)
41 def measure(kernelimg, con):
42 print("Measuring " + con.hash)
44 os.remove(sf(conf.jobfolder_linux_image))
45 except FileNotFoundError:
47 os.symlink(kernelimg, sf(conf.jobfolder_linux_image))
49 print("Configuration '" + con.hash + "' measured.")
53 class mainThread(Thread):
56 img, config = prepare()
59 while not __terminate__:
60 img, config = prepare()
63 # Multithread section #
67 class prepareThread(Thread):
68 def __init__(self, name='prepare'):
69 Thread.__init__(self, name=name)
72 while not __terminate__ and len(__conflist__) <= conf.multithread_buffer:
73 __listlock__.release()
75 img, config = prepare()
76 except exceptions.NoApplicableConfiguration:
79 __conflist__.add((img, config))
80 if not __measurethread__.isActive():
81 __measurethread__.start()
82 __listlock__.release()
84 class measureThread(Thread):
85 def __init__(self, name='measure'):
86 Thread.__init__(self, name=name)
89 while not __terminate__ and len(__conflist__) > 0:
90 img, config = __conflist__.pop()
91 __listlock__.release()
92 if not __preparethread__.isActive():
93 __preparethread__.start()
96 __listlock__.release()
98 __preparethread__ = prepareThread()
99 __measurethread__ = measureThread()
101 # Start and sigterm handler #
102 def sigterm_handler(_signo, _stack_frame):
113 except KeyboardInterrupt:
116 #################################################################################
118 if __name__ == '__main__':
119 signal.signal(signal.SIGTERM, sigterm_handler)