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 global __confs_unmeasured__
24 if len(__confs_unmeasured__) == 0:
25 dtb = database.database()
26 confs = dtb.get_unmeasured()
28 configurations.generate()
29 confs = dtb.get_unmeasured()
31 raise exceptions.NoApplicableConfiguration()
32 __confs_unmeasured__ = list(confs)
33 con = __confs_unmeasured__.pop()
34 kernel.config(con.cfile)
35 img = kernel.make(con.hash)
36 print("Prepared image: " + img)
39 def measure(kernelimg, con):
41 os.remove(sf(conf.jobfolder_linux_image))
42 except FileNotFoundError:
44 os.symlink(kernelimg, sf(conf.jobfolder_linux_image))
46 print("Configuration '" + con.hash + "' measured.")
50 class mainThread(Thread):
53 img, config = prepare()
56 while not __terminate__:
57 img, config = prepare()
60 # Multithread section #
64 class prepareThread(Thread):
65 def __init__(self, name='prepare'):
66 Thread.__init__(self, name=name)
69 while not __terminate__ and len(__conflist__) <= conf.multithread_buffer:
70 __listlock__.release()
72 img, config = prepare()
73 except exceptions.NoApplicableConfiguration:
76 __conflist__.add((img, config))
77 if not __measurethread__.isActive():
78 __measurethread__.start()
79 __listlock__.release()
81 class measureThread(Thread):
82 def __init__(self, name='measure'):
83 Thread.__init__(self, name=name)
86 while not __terminate__ and len(__conflist__) > 0:
87 img, config = __conflist__.pop()
88 __listlock__.release()
89 if not __preparethread__.isActive():
90 __preparethread__.start()
93 __listlock__.release()
95 __preparethread__ = prepareThread()
96 __measurethread__ = measureThread()
98 # Start and sigterm handler #
99 def sigterm_handler(_signo, _stack_frame):
109 except KeyboardInterrupt:
112 #################################################################################
114 if __name__ == '__main__':
115 signal.signal(signal.SIGTERM, sigterm_handler)