compareProfileMethods function
ProfileMethodComparison
compareProfileMethods({
- required ProfileMethodInspection baseline,
- required ProfileMethodInspection current,
- int? relationLimit,
Compares one selected method across two inspected profiles.
Implementation
ProfileMethodComparison compareProfileMethods({
required ProfileMethodInspection baseline,
required ProfileMethodInspection current,
int? relationLimit,
}) {
final warnings = <String>[];
final baselineMethod = baseline.method;
final currentMethod = current.method;
final status = switch ((baseline.status, current.status)) {
(
ProfileMethodInspectionStatus.found,
ProfileMethodInspectionStatus.found,
) =>
ProfileMethodComparisonStatus.compared,
(ProfileMethodInspectionStatus.unavailable, _) ||
(
_,
ProfileMethodInspectionStatus.unavailable,
) => ProfileMethodComparisonStatus.unavailable,
(ProfileMethodInspectionStatus.found, _) ||
(
_,
ProfileMethodInspectionStatus.found,
) => ProfileMethodComparisonStatus.partial,
_ => ProfileMethodComparisonStatus.unresolved,
};
if (baseline.status != current.status) {
warnings.add(
'The compared method lookup statuses differ: '
'${baseline.status.name} vs ${current.status.name}.',
);
}
if (baselineMethod != null &&
currentMethod != null &&
baselineMethod.methodId != currentMethod.methodId) {
warnings.add(
'The resolved method ids differ between baseline and current: '
'"${baselineMethod.methodId}" vs "${currentMethod.methodId}".',
);
}
if (baseline.message != null &&
current.message != null &&
baseline.message != current.message) {
warnings.add('The baseline and current method resolution details differ.');
}
final methodDelta = switch ((baselineMethod, currentMethod)) {
(final ProfileMethodSummary left, final ProfileMethodSummary right) =>
_buildMethodDelta(left, right),
_ => null,
};
final callerDeltas = switch ((baselineMethod, currentMethod)) {
(final ProfileMethodSummary left, final ProfileMethodSummary right) =>
_limitList(
_buildRelationDeltas(left.callers, right.callers),
relationLimit,
),
_ => const <ProfileMethodRelationDelta>[],
};
final calleeDeltas = switch ((baselineMethod, currentMethod)) {
(final ProfileMethodSummary left, final ProfileMethodSummary right) =>
_limitList(
_buildRelationDeltas(left.callees, right.callees),
relationLimit,
),
_ => const <ProfileMethodRelationDelta>[],
};
return ProfileMethodComparison(
query: baseline.query,
queryKind: baseline.queryKind,
status: status,
baseline: baseline,
current: current,
methodDelta: methodDelta,
callerDeltas: callerDeltas,
calleeDeltas: calleeDeltas,
warnings: warnings,
);
}