]> rtime.felk.cvut.cz Git - linux-conf-perf.git/commitdiff
Store boot output to database
authorKarel Kočí <cynerd@email.cz>
Wed, 19 Aug 2015 08:14:53 +0000 (10:14 +0200)
committerKarel Kočí <cynerd@email.cz>
Wed, 19 Aug 2015 08:19:06 +0000 (10:19 +0200)
Because configuration is now stored in database only missing
informations to make database fully descriptive is boot output. This
makes output of boot command to be saved to database and not to file.

Also parse script should read input from stdin and not from file from
argument.

scripts/boot.py
scripts/database.py
scripts/databaseinit.sql
scripts/utils.py
tests/cyclictest/parse

index 2d1461acf3c2fa2d99af4cfc45db3c8dd10d6337..6209461709262f7dc1e7e4c681f50c76b790fe7d 100644 (file)
@@ -12,20 +12,7 @@ from exceptions import MissingFile
 import database
 
 def boot(config, to_database = True):
-       try:
-               os.mkdir(sf(conf.output_folder))
-       except FileExistsError:
-                       pass
-
-       sprc = subprocess.Popen(conf.boot_command, stdout = subprocess.PIPE)
-       with open(os.path.join(sf(conf.output_folder), config.cfile), "a") as f:
-               for linen in sprc.stdout:
-                       line = linen.decode('utf-8')
-                       if conf.boot_output:
-                               print(line, end="")
-                       f.write(line)
-
-       # Let user script parse double value
+       out = utils.callsubprocess('boot', conf.boot_command, conf.boot_output, True)
 
        value = None
        try:
@@ -38,6 +25,4 @@ def boot(config, to_database = True):
 
        if to_database:
                        dtb = database.database()
-                       dtb.add_measure(config.cfile, config.id, value)
-
-       return config.cfile
+                       dtb.add_measure(out, config.id, value)
index 01c341a8b2ae22f3b215cd90c5ff88fcd0850ab5..df89a9ae781cb61a080c47bb0bcf85ad73e425f4 100644 (file)
@@ -20,7 +20,7 @@ def __timestamp__():
        return datetime.datetime.now().strftime('%y-%m-%d-%H-%M-%S')
 
 Config = collections.namedtuple('Config', 'id hash config') # Named tuple for configuration
-Measure = collections.namedtuple('Measure', 'id conf_id mfile value') # Named tuple for measurement
+Measure = collections.namedtuple('Measure', 'id conf_id output value') # Named tuple for measurement
 
 class database:
        "Class used for accessing PostgreSQL project database."
@@ -99,17 +99,17 @@ class database:
                        rtn.append(Config(dt[0], hash, dt[1]))
                return rtn
 
-       def add_measure(self, mfile, conf_id, value = None):
+       def add_measure(self, output, conf_id, value = None):
                "Add measurement."
                ps = self.db.prepare("""INSERT INTO measure
-                                                               (conf, mfile, value, mtime, toolgit, linuxgit, measurement)
+                                                               (conf, output, value, mtime, toolgit, linuxgit, measurement)
                                                                VALUES
                                                                ($1, $2, $3, $4, $5, $6, $7);
                                                                """)
                gt = self.check_toolsgit()
                lgt = self.check_linuxgit()
                tm = datetime.datetime.now()
-               ps(conf_id, mfile, value, tm, gt, lgt, conf.measure_identifier)
+               ps(conf_id, output, value, tm, gt, lgt, conf.measure_identifier)
 
        def update_measure(self, measure_id, value):
                "Update measured value"
@@ -122,7 +122,7 @@ class database:
 
        def get_measures(self, conf_id):
                "Get measures for configuration with conf_id id"
-               ps = self.db.prepare("""SELECT id, mfile, value FROM measure
+               ps = self.db.prepare("""SELECT id, output, value FROM measure
                                                                WHERE conf = $1;
                                                                """)
                rtn = []
@@ -132,7 +132,7 @@ class database:
 
        def get_unmeasured(self):
                "Returns list of all unmeasured configurations."
-               ps = self.db.prepare("""SELECT id, hash, cfile FROM configurations
+               ps = self.db.prepare("""SELECT id, hash, config FROM configurations
                                                                WHERE id NOT IN
                                                                (SELECT conf FROM measure)
                                                                """)
index d1ab3e2231e35a440f7c44b01437218139814c15..0ca9b5a1434bc9af3baae3ce967e71cd74e529c3 100644 (file)
@@ -28,7 +28,7 @@ CREATE TABLE measure (
        id BIGSERIAL PRIMARY KEY, -- Id
        conf BIGINT REFERENCES configurations (id), -- Reference to configuration
        measurement TEXT NOT NULL, -- Text identifivator of measuring tool
-       mfile TEXT NOT NULL, -- File with measuring output
+       output TEXT NOT NULL, -- Output of boot
        value DOUBLE PRECISION DEFAULT null, -- Measured data value
        mtime timestamp NOT NULL, -- Time and date of measurement
        linuxgit BIGINT REFERENCES linuxgit (id), -- Reference to git version of Linux
index 742aec56029d0447bbac2a850e61dd8e6f665670..e06bdbb6b05c173bbd4245efb7d07eaf1d5dcf28 100644 (file)
@@ -30,15 +30,18 @@ def build_symbol_map():
 
 def callsubprocess(process_name, process, show_output = True,
                return_output = False, env=os.environ, allowed_exit_codes = [0],
-               allow_all_exit_codes = False):
+               allow_all_exit_codes = False, stdin = None):
        sprc = subprocess.Popen(process, stdout = subprocess.PIPE,
-                       stderr = subprocess.STDOUT, env = env)
+                       stderr = subprocess.STDOUT, stdin = subprocess.PIPE, env = env)
 
        try:
                os.mkdir(os.path.join(sf(conf.log_folder), process_name))
        except OSError:
                pass
 
+       if stdin != None:
+               sprc.stdin.write(bytes(stdin, sys.getdefaultencoding()))
+
        rtn = []
        with open(os.path.join(sf(conf.log_folder),
                        process_name, time.strftime("%y-%m-%d-%H-%M-%S") + ".log"),
index 868212c9ec63c40820a83631d738ba4005683a4c..64a6fefe3262567b68662de375bcbc057c9061a4 100755 (executable)
@@ -1,3 +1,3 @@
 #!/bin/bash
 
-cat $1 | grep -e "^! .* ok" | sed -n '2p' | awk '{print $17}'
+grep -e "^! .* ok" | sed -n '2p' | awk '{print $17}'