]> rtime.felk.cvut.cz Git - linux-conf-perf.git/blobdiff - scripts/boot.py
Fix bug described in commit 5ef685
[linux-conf-perf.git] / scripts / boot.py
index dac17ef62785d5988f7d955a578f79b0a2d5d461..c12bb7978c21e090f68eb774244462bfb73971a0 100644 (file)
@@ -3,50 +3,43 @@ import sys
 import subprocess
 import shutil
 import importlib
+import traceback
 
 import utils
+import initialize
 from conf import conf
 from conf import sf
-from exceptions import MissingFile
+import exceptions
+import database
 
-def gen_nbscript():
+def boot(config, to_database = True):
        try:
-               os.remove(sf(conf.nbscript))
-       except OSError:
-               pass
-
-       with open(sf(conf.nbscript), 'w') as f:
-               f.write('# generated novaboot script. Please don\'t edit.\n')
-               f.write('load ' + sf(conf.linux_image) + ' console=ttyS0,115200\n')
-               f.write('load ' + sf(conf.initram) + '\n')
-
-def boot():
-       if not os.path.isfile((conf.nbscript)):
-               gen_nbscript()
+               out = utils.callsubprocess('boot', conf.boot_command, conf.boot_output, \
+                               True, timeout = conf.boot_timeout)
+               result = 'nominal'
+       except exceptions.ProcessFailed as e:
+               result = 'failed'
+               out = e.output
+               traceback.print_exc()
+       except exceptions.ProcessTimeout as e:
+               result = 'timeout'
+               out = e.output
+               traceback.print_exc()
+
+       value = None
        try:
-               os.mkdir(sf(conf.output_folder))
-       except FileExistsError:
-                       pass
-
-       bench = importlib.machinery.SourceFileLoader("module.name",
-                       "../benchmark.py").load_module()
-
-       sprc = subprocess.Popen([sf(conf.novaboot), sf(conf.nbscript)] + conf.novaboot_args,
-                       stdout = subprocess.PIPE)
-       output = ''
-       for linen in sprc.stdout:
-               line = linen.decode('utf-8')
-               if conf.boot_output:
-                       print(line, end="")
-               if line.startswith('lcp-output: '):
-                       output += line[12:]
-       print(output)
-       data = bench.stdoutput(output)
-
-       iteration = 0
-       with open(sf(conf.iteration_file), 'a') as f:
-               iteration = int(f.readline())
-
-       for key, val in data.items():
-               with open(os.path.join(sf(conf.output_folder),key), 'w') as f:
-                       f.write(str(iteration) + ':' + str(val) + '\n')
+               res = utils.callsubprocess('parse_command', conf.parse_command,
+                               conf.parse_output, True, stdin = out)
+               value = float(res[0])
+       except Exception as e:
+               print("W: parse exception: " + e.__str__())
+
+       if to_database:
+                       dtb = database.database()
+                       txt = ''
+                       for ln in out:
+                               for c in ln:
+                                       if c == b'\0':
+                                               c = ' '
+                               txt += ln + '\n'
+                       dtb.add_measure(txt, result, config.id, value)