Skip to content

Commit

Permalink
Add signature id field for perfcompare (#8111)
Browse files Browse the repository at this point in the history
* Add signature_id field

* Refactor methods

* Changed tests
  • Loading branch information
beatrice-acasandrei authored Jun 26, 2024
1 parent 3e098fe commit b064699
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 45 deletions.
4 changes: 4 additions & 0 deletions tests/webapp/api/test_perfcompare_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def test_perfcompare_results_against_no_base(
"is_regression": response["is_regression"],
"is_meaningful": response["is_meaningful"],
"parent_signature": response["parent_signature"],
"signature_id": response["signature_id"],
},
]

Expand Down Expand Up @@ -309,6 +310,7 @@ def test_perfcompare_results_with_only_one_run_and_diff_repo(
"is_regression": response["is_regression"],
"is_meaningful": response["is_meaningful"],
"parent_signature": response["parent_signature"],
"signature_id": response["signature_id"],
},
]

Expand Down Expand Up @@ -471,6 +473,7 @@ def test_perfcompare_results_subtests_support(
"is_regression": response["is_regression"],
"is_meaningful": response["is_meaningful"],
"parent_signature": response["parent_signature"],
"signature_id": response["signature_id"],
},
]

Expand Down Expand Up @@ -815,4 +818,5 @@ def get_expected(
response["parent_signature"] = (
base_sig.parent_signature.id if base_sig.parent_signature else None
)
response["signature_id"] = base_sig.id
return response
80 changes: 35 additions & 45 deletions treeherder/webapp/api/performance_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,7 @@ def list(self, request):
"parent_signature": parent_signature
if parent_signature
else base_sig.get("parent_signature_id", None),
"signature_id": base_sig_id,
}

self.queryset.append(row_result)
Expand Down Expand Up @@ -1093,8 +1094,13 @@ def _get_push_timestamp(base_push, new_push):
break
return max(values)

def _get_perf_data(self, repository_name, revision, signatures, interval, startday, endday):
perf_data = self._get_perf_data_by_repo_and_signatures(repository_name, signatures)
@staticmethod
def _get_perf_data(repository_name, revision, signatures, interval, startday, endday):
signature_ids = [signature["id"] for signature in list(signatures)]
perf_data = PerformanceDatum.objects.select_related("push", "repository", "id").filter(
signature_id__in=signature_ids,
repository__name=repository_name,
)
if revision:
perf_data = perf_data.filter(push__revision=revision)
elif interval and not startday and not endday:
Expand All @@ -1108,16 +1114,37 @@ def _get_perf_data(self, repository_name, revision, signatures, interval, startd

return perf_data

def _get_signatures(self, repository_name, framework, parent_signature, interval, no_subtests):
signatures = self._get_filtered_signatures_by_repo(repository_name)
@staticmethod
def _get_signatures(repository_name, framework, parent_signature, interval, no_subtests):
signatures = PerformanceSignature.objects.select_related(
"framework", "repository", "platform", "push", "job"
).filter(repository__name=repository_name)
signatures = signatures.filter(parent_signature__isnull=no_subtests)
if framework:
signatures = signatures.filter(framework__id=framework)
if parent_signature:
signatures = signatures.filter(parent_signature_id=parent_signature)
if interval:
signatures = self._get_filtered_signatures_by_interval(signatures, interval)
signatures = self._get_signatures_values(signatures)
signatures = signatures.filter(
last_updated__gte=datetime.datetime.utcfromtimestamp(
int(time.time() - int(interval))
)
)
signatures = signatures.values(
"framework_id",
"id",
"extra_options",
"suite",
"platform__platform",
"test",
"option_collection_id",
"parent_signature_id",
"repository_id",
"measurement_unit",
"lower_is_better",
"signature_hash",
"application",
)
return signatures

@staticmethod
Expand Down Expand Up @@ -1174,44 +1201,6 @@ def _get_interval(base_push, new_push):
break
return new_time_range

@staticmethod
def _get_perf_data_by_repo_and_signatures(repository_name, signatures):
signature_ids = [signature["id"] for signature in list(signatures)]
return PerformanceDatum.objects.select_related("push", "repository", "id").filter(
signature_id__in=signature_ids,
repository__name=repository_name,
)

@staticmethod
def _get_filtered_signatures_by_interval(signatures, interval):
return signatures.filter(
last_updated__gte=datetime.datetime.utcfromtimestamp(int(time.time() - int(interval)))
)

@staticmethod
def _get_signatures_values(signatures):
return signatures.values(
"framework_id",
"id",
"extra_options",
"suite",
"platform__platform",
"test",
"option_collection_id",
"parent_signature_id",
"repository_id",
"measurement_unit",
"lower_is_better",
"signature_hash",
"application",
)

@staticmethod
def _get_filtered_signatures_by_repo(repository_name):
return PerformanceSignature.objects.select_related(
"framework", "repository", "platform", "push", "job"
).filter(repository__name=repository_name)

@staticmethod
def _get_grouped_perf_data(perf_data):
grouped_values = defaultdict(list)
Expand All @@ -1222,7 +1211,8 @@ def _get_grouped_perf_data(perf_data):
grouped_job_ids[signature_id].append(job_id)
return grouped_job_ids, grouped_values

def _get_signatures_map(self, signatures, grouped_values, option_collection_map):
@staticmethod
def _get_signatures_map(signatures, grouped_values, option_collection_map):
"""
@return: signatures_map - contains a mapping of all the signatures for easy access and matching
header_names - list of header names for all given signatures
Expand Down
2 changes: 2 additions & 0 deletions treeherder/webapp/api/performance_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@ class PerfCompareResultsSerializer(serializers.ModelSerializer):
is_regression = serializers.BooleanField(required=False)
is_meaningful = serializers.BooleanField(required=False)
parent_signature = serializers.IntegerField()
signature_id = serializers.IntegerField()

class Meta:
model = PerformanceSignature
Expand Down Expand Up @@ -594,6 +595,7 @@ class Meta:
"is_regression",
"is_meaningful",
"parent_signature",
"signature_id",
]


Expand Down

0 comments on commit b064699

Please sign in to comment.