Replace some timer calls.

master
Simon Quigley 5 years ago
parent 42869ace27
commit 28c7f2b397

@ -16,7 +16,6 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
import git import git
import time
from os import getenv, path from os import getenv, path
from yaml import CLoader from yaml import CLoader
from yaml import load as yaml_load from yaml import load as yaml_load
@ -24,6 +23,9 @@ from jinja2 import Template
from shutil import rmtree from shutil import rmtree
from tempfile import mkdtemp from tempfile import mkdtemp
from jenkinsapi.jenkins import Jenkins from jenkinsapi.jenkins import Jenkins
from timer_metrics import TimerMetrics
timer = TimerMetrics()
class Generator: class Generator:
@ -103,6 +105,8 @@ class Generator:
set in Jenkins. These need to be private, so they are defined in the set in Jenkins. These need to be private, so they are defined in the
system-wide Jenkins credential storage. system-wide Jenkins credential storage.
""" """
timer.start("Authenticate to the server")
# Load the API values from the environment variables # Load the API values from the environment variables
api_site = getenv("API_SITE") api_site = getenv("API_SITE")
api_user = getenv("API_USER") api_user = getenv("API_USER")
@ -114,6 +118,8 @@ class Generator:
# Authenticate to the server # Authenticate to the server
server = Jenkins(api_site, username=api_user, password=api_key) server = Jenkins(api_site, username=api_user, password=api_key)
timer.stop("Authenticate to the server")
return server return server
def load_config(self, job_type, data=None): def load_config(self, job_type, data=None):
@ -182,8 +188,7 @@ class Generator:
""" """
# Start a timer # Start a timer
t_start = time.perf_counter() timer.start("Getting existing Jenkins jobs")
print("Getting list of existing Jenkins jobs...")
# Get the generator object with the jobs and create an empty list # Get the generator object with the jobs and create an empty list
s_jobs = server.get_jobs() s_jobs = server.get_jobs()
@ -199,8 +204,7 @@ class Generator:
jobs = tuple(jobs) jobs = tuple(jobs)
# Stop the timer and log the time # Stop the timer and log the time
t_end = time.perf_counter() timer.stop("Getting existing Jenkins jobs")
print(f"Finished in {t_end - t_start:0.4f} seconds.")
return jobs return jobs

Loading…
Cancel
Save