SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
Results.h
Go to the documentation of this file.
1 /**
2  * @file Results.h
3  * @author Gereon Kremer <gereon.kremer@cs.rwth-aachen.de>
4  */
5 
6 #pragma once
7 
8 #include <functional>
9 #include <map>
10 #include <mutex>
11 #include <optional>
12 #include <utility>
13 #include <vector>
14 
15 #include <filesystem>
16 
17 #include "../logging.h"
18 #include "../tools/Tool.h"
19 #include "Database.h"
20 #include "XMLWriter.h"
21 #include "CSVWriter.h"
22 #include "BenchmarkResult.h"
23 
24 namespace benchmax {
25 
26 namespace fs = std::filesystem;
27 
28 /**
29  * Stores results for for whole benchmax run.
30  * Allows for (concurrent) insertion of the individual results via addResult().
31  * Eventually results can be stored to a database (if enabled) or to a xml file.
32  */
33 class Results {
34 private:
35  std::mutex mMutex;
36  std::map<const Tool*, std::size_t> mTools;
37  std::map<fs::path, std::size_t> mFiles;
38  std::map<std::pair<std::size_t,std::size_t>, BenchmarkResult> mData;
39  size_t result_id = 1;
40 public:
41  std::optional<std::reference_wrapper<const BenchmarkResult>> get(const Tool* tool, const fs::path& file) const {
42  auto toolIt = mTools.find(tool);
43  if (toolIt == mTools.end()) return std::nullopt;
44  auto fileIt = mFiles.find(file);
45  if (fileIt == mFiles.end()) return std::nullopt;
46  auto dataIt = mData.find(std::make_pair(toolIt->second, fileIt->second));
47  if (dataIt == mData.end()) return std::nullopt;
48  return std::ref(dataIt->second);
49  }
50  const auto& data() const {
51  return mData;
52  }
53  /// Add a new result.
54  void addResult(const Tool* tool, const fs::path& file, BenchmarkResult&& results) {
55  std::lock_guard<std::mutex> lock(mMutex);
56  auto toolIt = mTools.find(tool);
57  if (toolIt == mTools.end()) {
58  toolIt = mTools.emplace(tool, mTools.size()).first;
59  }
60  auto fileIt = mFiles.find(file);
61  if (fileIt == mFiles.end()) {
62  fileIt = mFiles.emplace(file, mFiles.size()).first;
63  }
64  results.store(result_id++);
65  mData.emplace(std::make_pair(toolIt->second, fileIt->second), std::move(results));
66  }
67 
68  /// Store all results to some database.
69  void store(Database& db) {
70  std::map<std::size_t, std::size_t> toolIDs;
71  std::map<std::size_t, std::size_t> fileIDs;
72 
73  for (const auto& it: mTools) {
74  toolIDs[it.second] = db.getToolID(it.first);
75  std::cout << toolIDs << std::endl;
76  }
77  for (const auto& it: mFiles) {
78  fileIDs[it.second] = db.getFileID(it.first);
79  }
80  std::size_t benchmarkID = db.createBenchmark();
81 
82  for (const auto& it: mData) {
83  std::size_t tool = toolIDs[it.first.first];
84  std::size_t file = fileIDs[it.first.second];
85  it.second.restore();
86  std::size_t id = db.addBenchmarkResult(benchmarkID, tool, file, it.second.exitCode, std::size_t(std::chrono::milliseconds(it.second.time).count()));
87  for (const auto& attr: it.second.additional) {
88  db.addBenchmarkAttribute(id, attr.first, attr.second);
89  }
90  it.second.forget();
91  }
92  }
93 
94  /// Store all results to a xml file.
95  void store(XMLWriter& xml, const Jobs& jobs) const {
96  xml.write(jobs, *this);
97  }
98 
99  /// Store all results to a csl file.
100  void store(CSVWriter& csv, const Jobs& jobs) const {
101  csv.write(jobs, *this);
102  }
103 };
104 
105 }
Writes results to a csv file.
Definition: CSVWriter.h:18
void write(const Jobs &jobs, const Results &results)
Write results to file.
Definition: CSVWriter.h:69
Dummy database that effectively disables storing to database. Set BENCHMAX_DATABASE to actually use a...
Definition: Database.h:96
Index getToolID(const Tool *)
Dummy.
Definition: Database.h:103
void addBenchmarkAttribute(Index, const std::string &, const std::string &)
Dummy.
Definition: Database.h:113
Index createBenchmark()
Dummy.
Definition: Database.h:109
Index addBenchmarkResult(Index, Index, Index, int, std::size_t)
Dummy.
Definition: Database.h:111
Index getFileID(const fs::path &)
Dummy.
Definition: Database.h:107
Represents a set of jobs, constructed as the cartesian product of a set of tools and a set of benchma...
Definition: Jobs.h:70
Stores results for for whole benchmax run.
Definition: Results.h:33
std::map< fs::path, std::size_t > mFiles
Definition: Results.h:37
std::map< std::pair< std::size_t, std::size_t >, BenchmarkResult > mData
Definition: Results.h:38
const auto & data() const
Definition: Results.h:50
void store(Database &db)
Store all results to some database.
Definition: Results.h:69
std::mutex mMutex
Definition: Results.h:35
std::optional< std::reference_wrapper< const BenchmarkResult > > get(const Tool *tool, const fs::path &file) const
Definition: Results.h:41
std::map< const Tool *, std::size_t > mTools
Definition: Results.h:36
void store(CSVWriter &csv, const Jobs &jobs) const
Store all results to a csl file.
Definition: Results.h:100
void store(XMLWriter &xml, const Jobs &jobs) const
Store all results to a xml file.
Definition: Results.h:95
size_t result_id
Definition: Results.h:39
void addResult(const Tool *tool, const fs::path &file, BenchmarkResult &&results)
Add a new result.
Definition: Results.h:54
Base class for any tool.
Definition: Tool.h:38
Writes results to a xml file.
Definition: XMLWriter.h:18
void write(const Jobs &jobs, const Results &results)
Write results to file.
Definition: XMLWriter.h:66
Results for a single benchmark run.