diff --git a/ci/jobgenerator.py b/ci/jobgenerator.py index dfc1237..23fad7e 100755 --- a/ci/jobgenerator.py +++ b/ci/jobgenerator.py @@ -70,6 +70,7 @@ class Generator: return metadata_conf + @timer.run("Parse the metadata") def parse_metadata(self): """Parse the data pulled from clone_metadata @@ -98,6 +99,7 @@ class Generator: return metadata_conf["repositories"] + @timer.run("Auth to Jenkins") def auth_jenkins_server(self): """Authenticate to the Jenkins server @@ -105,8 +107,6 @@ class Generator: set in Jenkins. These need to be private, so they are defined in the system-wide Jenkins credential storage. """ - timer.start("Authenticate to the server") - # Load the API values from the environment variables api_site = getenv("API_SITE") api_user = getenv("API_USER") @@ -118,8 +118,6 @@ class Generator: # Authenticate to the server server = Jenkins(api_site, username=api_user, password=api_key) - timer.stop("Authenticate to the server") - return server def load_config(self, job_type, data=None): @@ -179,6 +177,7 @@ class Generator: return package_config + @timer.run("Get existing jobs") def get_existing_jenkins_jobs(self, server): """This returns a tuple of all existing Jenkins jobs @@ -233,6 +232,7 @@ class Generator: total_rel = set() for package in metadata: + timer.start("Merger job creation") # Create the merger jobs first job_name = "merger_" + package["name"] package_config = self.load_config("merger", package) @@ -247,7 +247,9 @@ class Generator: else: view = server.views.create("merger") view.add_job(job_name) + timer.stop("Merger job creation") + timer.start("Release job creation") for release in package["releases"]: # Add the release to the total release set, which is used to # generate the management jobs @@ -272,7 +274,9 @@ class Generator: view = server.views.create(viewname) view.add_job(job_name) + timer.stop("Release job creation") + timer.start("Management job creation") # From here on out, the same template is used package_config = self.load_config("release-mgmt") @@ -302,7 +306,10 @@ class Generator: view = server.views["mgmt"] view.add_job("merger") + timer.stop("Management job creation") + if __name__ == "__main__": generator = Generator() print(generator.create_jenkins_jobs()) + timer.display() diff --git a/ci/timer_metrics.py b/ci/timer_metrics.py index 19046ca..cb6f6f5 100755 --- a/ci/timer_metrics.py +++ b/ci/timer_metrics.py @@ -17,6 +17,7 @@ import time import tabulate +import sys from tabulate import tabulate tabulate.PRESERVE_WHITESPACE = True @@ -100,6 +101,24 @@ class TimerMetrics: cur_time = t_val - self.data[name]["start_time"] self.data[name]["total_time"] += cur_time + def run(self, label): + """Wrap a function inside a timer + + This allows for the usage of a decorator on a function which + automatically and easily starts and ends a timer + """ + self.start(label) + + def wrap(func): + def run_function(*args, **kwargs): + try: + return func(*args, **kwargs) + finally: + self.stop(label) + return run_function + return wrap + + def display(self): """Print a pretty(-ish) table with all of the data in it"""