bin/ci: crnm: Fix job duration calculation

The former version was problematic because:

- time.perf_counter() returns seconds relative to an arbitrary point in
  time (monotonic clock)
- time.mktime() converts to epoch time (seconds since 1970)

Signed-off-by: Guilherme Gallo <guilherme.gallo@collabora.com>
Reviewed-by: Sergi Blanch Torne <sergi.blanch.torne@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33750>
This commit is contained in:
Guilherme Gallo
2025-02-25 23:04:42 -03:00
committed by Marge Bot
parent b3a9125014
commit ce200e6a4a

View File

@@ -100,7 +100,10 @@ def job_duration(job: gitlab.v4.objects.ProjectPipelineJob) -> float:
if job.duration:
return job.duration
elif job.started_at:
return time.perf_counter() - time.mktime(job.started_at.timetuple())
# Convert both times to UTC timestamps for consistent comparison
current_time = time.time()
start_time = job.started_at.timestamp()
return current_time - start_time
return 0.0