Skip to content

File reporter.cpp

File List > benchmark > reporter > reporter.cpp

Go to the documentation of this file

#include "reporter.h"
#include "result.h"

#include <chrono>
#include <vector>

namespace Argos {

bool BenchmarkReporter::ReportContext(const Context &context) {
  BenchmarkResultMetadata meta;

  auto now = std::chrono::system_clock::now();
  std::time_t now_c = std::chrono::system_clock::to_time_t(now);
  meta.date_time = now_c;
  meta.num_cpus = context.cpu_info.num_cpus;
  meta.mhz_per_cpu = static_cast<int>(context.cpu_info.cycles_per_second / 1e6);

  value.meta = meta;

  console_reporter.ReportContext(context);
  return true;
}

void BenchmarkReporter::ReportRuns(const std::vector<Run> &report) {
  std::vector<BenchmarkResultLine> lines;
  for (const auto &run : report) {
    // Saute les runs aggregation et non-iteration
    if (run.run_type != Run::RT_Iteration) {
      continue;
    }

    if(run.skipped) continue;

    BenchmarkResultLine line;
    // Résumé d'une iteration
    line.name = run.run_name.function_name;
    line.cpu_time_per_op =
        run.cpu_accumulated_time / static_cast<double>(run.iterations);
    line.wall_time_per_op =
        run.real_accumulated_time / static_cast<double>(run.iterations);
    line.iterations = run.iterations;
    line.metrics = run.counters;

    lines.push_back(line);
  }

  // Ajoute les nouvelles lignes aux resultats existants pour que chaque benchmark soit comptabilisées
  value.results.insert(value.results.end(), lines.begin(), lines.end());

  console_reporter.ReportRuns(report);
}

void BenchmarkReporter::Finalize() {
  console_reporter.Finalize();
}

const BenchmarkResultMetadata &BenchmarkReporter::metadata() const {
  return value.meta;
}

const std::vector<BenchmarkResultLine> &BenchmarkReporter::results() const {
  return value.results;
}

const BenchmarkResult &BenchmarkReporter::result() const {
  return value;
}

} // namespace Argos