Exemplo n.º 1
0
 def save_failed_config(self, failure: str):
     """
     Saving failed configs to not re-run them again
     :param failure: Failure Mode
     :return:
     """
     db_entry = Config()
     db_entry.name = 'Performance Testing Failed'  # TODO: Keep name field?
     db_entry.date = datetime.utcnow()
     db_entry.commitSHA = self.sha
     db_entry.commitMessage = self.repo.commit(self.sha).message
     db_entry.commitDate = self.repo.commit(self.sha).authored_datetime
     # Saving Setup used in perf script
     if self.perfSetup is not None:
         db_entry.setup = self.perfSetup
     db_entry.failure = failure
     db_entry.save()
Exemplo n.º 2
0
    def parse_and_upload(self):

        print("uploading", self.mdFlexDir)

        try:
            cpu = get_cpu_info()["brand"]
        except Exception as e:
            print(f"Couldn't determine CPU brand: {e}")
            cpu = "N/A"
        run_timestamp = datetime.utcnow()

        coarse_pattern = re.compile(
            r'Collected times for\s+{(.*)}\s:\s\[(.*)\]')
        config_pattern = re.compile(r'([^,]+): ([^,]+)')
        times_pattern = re.compile(r'(\d+)')
        config_runs = coarse_pattern.findall(
            self.measure_output.stdout.decode('utf-8'))

        db_entry = Config()
        db_entry.name = 'performance via single tuning phase'  # TODO: Keep name field?
        db_entry.date = run_timestamp
        db_entry.commitSHA = self.sha
        db_entry.commitMessage = self.repo.commit(self.sha).message
        db_entry.commitDate = self.repo.commit(self.sha).authored_datetime
        db_entry.mergedBaseSHA = self.baseSHA

        # Assumes tests were run on this system
        db_entry.system = cpu

        # Saving Setup used in perf script
        db_entry.setup = self.perfSetup

        # TODO: Decide if uniqueness is enforced (Change spare in models to False)
        # db_entry.unique = db_entry.name + db_entry.commitSHA + db_entry.system + str(db_entry.date)
        # try:
        #     db_entry.save()
        # except NotUniqueError:
        #     print("Exact Configuration for system and commit + date already saved!")
        #     continue
        try:
            db_entry.save()
        except Exception as e:
            self.updateStatus(-1, "UPLOAD", str(e))
            return False, f'Upload of config to DB failed {e}'
        print(db_entry)

        for run in config_runs:

            results = Result()
            results.config = db_entry

            # Filter all config parameters
            config = config_pattern.findall(run[0])

            # Parsing output
            try:
                # Parsing Config keys and values
                for pair in config:
                    key = pair[0].replace(' ', '')  # Replace spaces
                    key = 'dynamic_' + key  # Adding prefix to clearly show dynamic field creation in DB
                    quantity = pair[1].replace(' ', '')  # Replace spaces

                    try:  # Try converting to float if appropriate
                        quantity = float(quantity)
                    except ValueError:
                        pass

                    print(key, quantity)
                    results[key] = quantity

                # Parsing times
                times = times_pattern.findall(run[1])
                times = [float(t) for t in times]
                results.measurements = times
                results.meanTime = np.mean(times)  # Mean running Time
                results.minTime = np.min(times)  # Min running Time
            except Exception as e:
                print(f'Parsing of measurement failed {e}')
                self.updateStatus(-1, "PARSING", str(e))
                return False, f'Parsing failed with {e}'

            try:
                results.save()
            except Exception as e:
                self.updateStatus(-1, "UPLOAD", str(e))
                return False, f'Upload of Result failed with {e}'
            print(results)

        os.chdir(self.baseDir)
        self.updateStatus(1, "UPLOAD", "RESULT UPLOAD succeeded\n")
        return True, 'Upload succeeded'