From 3f5db0965de9eef808b050c8d6168a9f0bcb926d Mon Sep 17 00:00:00 2001 From: vermaas <vermaas@astron.nl> Date: Tue, 10 Jan 2023 15:26:54 +0100 Subject: [PATCH] calculate wall_clock_time for logentries between entries --- atdb/taskdatabase/models.py | 38 +++++++++++++++++++ atdb/taskdatabase/services/algorithms.py | 2 +- .../templates/taskdatabase/index.html | 2 +- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/atdb/taskdatabase/models.py b/atdb/taskdatabase/models.py index 0444c4f8..9a08e262 100644 --- a/atdb/taskdatabase/models.py +++ b/atdb/taskdatabase/models.py @@ -4,6 +4,9 @@ from django.utils import timezone from django.utils.timezone import datetime, timedelta from django.conf import settings +import logging +logger = logging.getLogger(__name__) + # constants datetime_format_string = '%Y-%m-%dT%H:%M:%SZ' @@ -228,6 +231,41 @@ class LogEntry(models.Model): def __str__(self): return str(self.id)+ ' - '+ str(self.task)+' - '+self.status + def save(self, *args, **kwargs): + #override save to check how long this task has been in this state. + try: + + # if this logentry already has a wall_clock_time, then don't change it. + if not self.wall_clock_time: + + # gather all entries for this task, to discover the previous one. + entries_for_this_task = LogEntry.objects.filter(task=self.task).order_by("-timestamp") + # remove entries from the list, including 'this', so that the latest remaining is the previous entry. + for entry in entries_for_this_task: + entries_for_this_task = entries_for_this_task.exclude(id=entry.id) + if entry == self: + break + + try: + latest_entry_before_self = entries_for_this_task.latest('timestamp') + previous_timestamp = latest_entry_before_self.timestamp + except: + # if no previous entry exists, then use the timestamp from the task. + previous_timestamp = self.task.creationTime + + dt = (self.timestamp - previous_timestamp).seconds + message = "logentry for task "+str(self.task.id)+", to "+self.status + " took " + str(dt) + " seconds" + logger.info(message) + + self.wall_clock_time = dt + except Exception as e: + print(e) + + finally: + # finally save the Monitor info itself also + super(LogEntry, self).save(*args, **kwargs) + + class Status(models.Model): name = models.CharField(max_length=50, default="unknown") diff --git a/atdb/taskdatabase/services/algorithms.py b/atdb/taskdatabase/services/algorithms.py index 482bfd61..917f3dae 100644 --- a/atdb/taskdatabase/services/algorithms.py +++ b/atdb/taskdatabase/services/algorithms.py @@ -608,7 +608,7 @@ def construct_logs_per_workflow_html_version1(log_records): def construct_logs_per_workflow_html(request, workflow_results): - results = "<p>Resources used per step per workflow: <b>cpu_cycles/wall_clock_time</b></p>" + results = "<p>Resources used per step per workflow: <b>cpu_cycles/wall_clock_time (seconds)</b></p>" # construct the header header = "<th>Workflow</th>" diff --git a/atdb/taskdatabase/templates/taskdatabase/index.html b/atdb/taskdatabase/templates/taskdatabase/index.html index 47e4181d..b463486b 100644 --- a/atdb/taskdatabase/templates/taskdatabase/index.html +++ b/atdb/taskdatabase/templates/taskdatabase/index.html @@ -34,7 +34,7 @@ {% include 'taskdatabase/pagination.html' %} </div> </div> - <p class="footer"> Version 23 December 2022 - 8:00 + <p class="footer"> Version 10 Januari 2022 - 15:00 </div> -- GitLab