toJson method

Map<String, dynamic> toJson()

Returns a JSON representation of the profile that will be sent to the server.

Implementation

Map<String, dynamic> toJson() {
  final List<String> scoreKeys = <String>[];
  final Map<String, dynamic> json = <String, dynamic>{
    'name': name,
    'scoreKeys': scoreKeys,
  };

  for (final String key in scoreData.keys) {
    final Timeseries timeseries = scoreData[key]!;

    if (timeseries.isReported) {
      scoreKeys.add('$key.${BenchmarkMetricComputation.average.name}');
      // Report `outlierRatio` rather than `outlierAverage`, because
      // the absolute value of outliers is less interesting than the
      // ratio.
      scoreKeys.add('$key.${BenchmarkMetricComputation.outlierRatio.name}');
    }

    final TimeseriesStats stats = timeseries.computeStats();
    json['$key.${BenchmarkMetricComputation.average.name}'] = stats.average;
    json['$key.${BenchmarkMetricComputation.outlierAverage.name}'] =
        stats.outlierAverage;
    json['$key.${BenchmarkMetricComputation.outlierRatio.name}'] =
        stats.outlierRatio;
    json['$key.${BenchmarkMetricComputation.noise.name}'] = stats.noise;
    for (final PercentileMetricComputation metric
        in PercentileMetricComputation.values) {
      json['$key.${metric.name}'] = stats.percentiles[metric.percentile];
    }
  }

  json.addAll(extraData);

  return json;
}