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):
42 os.remove(sf(conf.jobfolder_linux_image))
43 except FileNotFoundError:
45 os.symlink(kernelimg, sf(conf.jobfolder_linux_image))
47 print("Configuration '" + con.hash + "' measured.")
51 class mainThread(Thread):
54 img, config = prepare()
57 while not __terminate__:
58 img, config = prepare()
61 # Multithread section #
65 class prepareThread(Thread):
66 def __init__(self, name='prepare'):
67 Thread.__init__(self, name=name)
70 while not __terminate__ and len(__conflist__) <= conf.multithread_buffer:
71 __listlock__.release()
73 img, config = prepare()
74 except exceptions.NoApplicableConfiguration:
77 __conflist__.add((img, config))
78 if not __measurethread__.isActive():
79 __measurethread__.start()
80 __listlock__.release()
82 class measureThread(Thread):
83 def __init__(self, name='measure'):
84 Thread.__init__(self, name=name)
87 while not __terminate__ and len(__conflist__) > 0:
88 img, config = __conflist__.pop()
89 __listlock__.release()
90 if not __preparethread__.isActive():
91 __preparethread__.start()
94 __listlock__.release()
96 __preparethread__ = prepareThread()
97 __measurethread__ = measureThread()
99 # Start and sigterm handler #
100 def sigterm_handler(_signo, _stack_frame):
110 except KeyboardInterrupt:
113 #################################################################################
115 if __name__ == '__main__':
116 signal.signal(signal.SIGTERM, sigterm_handler)