Skip to content
Snippets Groups Projects
Commit 3f5db096 authored by Nico Vermaas's avatar Nico Vermaas
Browse files

calculate wall_clock_time for logentries between entries

parent 7d91617d
No related branches found
No related tags found
1 merge request!272Sdc 782 resource dashboard change
Pipeline #42234 passed
......@@ -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")
......
......@@ -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>"
......
......@@ -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>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment