Skip to content

File testbed.h

File List > kernel-sim > testbed.h

Go to the documentation of this file

#pragma once

#include <simtix/statistics.h>
#include <simtix/system.h>

#include <chrono>
#include <string>

#include "utils.h"

namespace tb {

class Testbed {
 public:
  explicit Testbed(const SimConfig &cfg);
  ~Testbed();

  Testbed(const Testbed &) = delete;
  Testbed &operator=(const Testbed &) = delete;

  int Initialize();
  int Run();
  void Report();

 private:
  std::string DumpMem(uint64_t addr, std::size_t size);

  SimConfig cfg_;

  simtix::system::SingleCoreSystem *system_ = nullptr;

  std::ostream *kofs_ = nullptr;  // Konata's ofstream

  std::chrono::high_resolution_clock::time_point start_time_;
  std::chrono::high_resolution_clock::time_point end_time_;

  struct TestbedStat : simtix::stat::Group {
    TestbedStat()
        : Group("Testbed"),
          STAT(sim_time, "Wall clock time", "sec"),
          STAT(sim_ticks, "Number of ticks executed", "N/A"),
          STAT(sim_freq, "Simulation frequency", "Hz") {
      sim_freq = sim_ticks / sim_time;
    }
    simtix::stat::Real sim_time;
    simtix::stat::Integer sim_ticks;
    simtix::stat::Formula<simtix::stat::Real> sim_freq;
  } stat_;
};

}  // namespace tb