diff --git a/mozci/task.py b/mozci/task.py index a91a4238..5ef8c259 100644 --- a/mozci/task.py +++ b/mozci/task.py @@ -2,6 +2,7 @@ import json import os from abc import ABC, abstractmethod +from argparse import Namespace from dataclasses import dataclass, field from enum import Enum from inspect import signature @@ -9,6 +10,7 @@ from typing import Dict, List, Optional import requests +from adr.query import run_query from adr.util import memoized_property from loguru import logger from urllib3.response import HTTPResponse @@ -358,6 +360,21 @@ def configuration(self): parts = config.split("-") return "-".join(parts[:-1] if parts[-1].isdigit() else parts) + @property + def overhead(self): + """Calculate the overhead of a task. + + The methodology is simple: each task is associated with a duration value. + Obtain and sum the runtime of all groups in the task, then take the + difference and we have the overhead value. + + Returns: + float: Difference of task duration and sum of group durations. + """ + data = run_query("group_durations", Namespace(task_id=self.id))["data"] + group_runtime = [runtime for *_, runtime in data] + return self.duration - sum(group_runtime) + # Don't perform type checking because of https://github.com/python/mypy/issues/5374. @dataclass # type: ignore