SkiaPerfPoint.fromPoint constructor

SkiaPerfPoint.fromPoint(
  1. MetricPoint p
)

Construct SkiaPerfPoint from a well-formed MetricPoint.

The MetricPoint must have kGithubRepoKey, kGitRevisionKey, kNameKey in its tags for this to be successful.

If the MetricPoint has a tag 'date', that tag will be removed so Skia perf can plot multiple metrics with different date as a single trace. Skia perf will use the git revision's date instead of this date tag in the time axis.

Implementation

factory SkiaPerfPoint.fromPoint(MetricPoint p) {
  final String? githubRepo = p.tags[kGithubRepoKey];
  final String? gitHash = p.tags[kGitRevisionKey];
  final String? name = p.tags[kNameKey];

  if (githubRepo == null || gitHash == null || name == null) {
    throw StateError(
        '$kGithubRepoKey, $kGitRevisionKey, $kNameKey must be set in'
        ' the tags of $p.');
  }

  final String subResult = p.tags[kSubResultKey] ?? kSkiaPerfValueKey;

  final Map<String, String> options = <String, String>{}..addEntries(
      p.tags.entries.where(
        (MapEntry<String, dynamic> entry) =>
            entry.key != kGithubRepoKey &&
            entry.key != kGitRevisionKey &&
            entry.key != kNameKey &&
            entry.key != kSubResultKey &&
            // https://github.com/google/benchmark automatically generates a
            // 'date' field. If it's included in options, the Skia perf won't
            // be able to connect different points in a single trace because
            // the date is always different.
            entry.key != 'date',
      ),
    );

  return SkiaPerfPoint._(
      githubRepo, gitHash, name, subResult, p.value, options, null);
}