SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
BenchmarkResult.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <chrono>
4 #include <iostream>
5 #include <map>
6 
7 #include <boost/archive/text_iarchive.hpp>
8 #include <boost/archive/text_oarchive.hpp>
9 #include <boost/serialization/map.hpp>
10 #include <fstream>
11 #include <filesystem>
12 
13 #include "../settings/Settings.h"
14 
15 namespace benchmax {
16 
17 /**
18  * Results for a single benchmark run.
19  */
21  /// Shell exit code.
22  int exitCode;
23  /// Runtime in milliseconds.
24  std::chrono::milliseconds time;
25  /// Answer string.
26  std::string answer;
27  /// Peak memory usage.
28  std::size_t peak_memory_kbytes;
29  /// Standard output (mostly for parsing the answer and additional information).
30  std::string stdout;
31  /// Error output (mostly for parsing the answer and additional information).
32  std::string stderr;
33  /// Arbitrary additional information that can be provided by the tool class.
34  mutable std::map<std::string, std::string> additional;
35  /// Identifier for temporary file.
36  mutable size_t stored_id = 0;
37 
38  /**
39  * Properly detect timeouts.
40  * Most backends give processes a bit more time to avoid having race-condition-like situations.
41  */
42  template<typename TimeLimit>
43  void cleanup(const TimeLimit& limit) {
44  if (time > limit) {
45  answer = "timeout";
46  }
47  stdout = "";
48  stderr = "";
49  }
50 
51  auto get_path() const {
52  assert(stored_id > 0);
53  return std::filesystem::temp_directory_path()/("benchmark-result-" + std::to_string(stored_id) + ".xml");
54  }
55  void store(size_t id) const {
56  if (settings_operation().use_temp) {
57  stored_id = id;
58  std::ofstream ofs(get_path());
59  boost::archive::text_oarchive oa(ofs);
60  oa << additional;
61  store();
62  }
63  }
64  void store() const {
65  if (settings_operation().use_temp) {
66  additional.clear();
67  }
68  }
69  void restore() const {
70  if (settings_operation().use_temp) {
71  std::ifstream ifs(get_path());
72  boost::archive::text_iarchive ia(ifs);
73  ia >> additional;
74  }
75  }
76  void forget() const {
77  if (settings_operation().use_temp) {
79  additional.clear();
80  }
81  }
82 };
83 
84 /// Streaming operator for BenchmarkResult.
85 inline std::ostream& operator<<(std::ostream& os, const BenchmarkResult& results) {
86  os << "(" << results.answer << ", " << results.exitCode << ", " << results.time.count() << "ms)" << std::endl;
87  os << results.stdout << std::endl;
88  os << results.stderr << std::endl;
89  return os;
90 }
91 
92 
93 }
static void remove(V &ts, const T &t)
Definition: Alg.h:36
const auto & settings_operation()
Retrieved operation settings.
Definition: Settings.h:85
std::ostream & operator<<(std::ostream &os, const BenchmarkResult &results)
Streaming operator for BenchmarkResult.
Results for a single benchmark run.
int exitCode
Shell exit code.
std::string stdout
Standard output (mostly for parsing the answer and additional information).
void cleanup(const TimeLimit &limit)
Properly detect timeouts.
std::chrono::milliseconds time
Runtime in milliseconds.
std::string stderr
Error output (mostly for parsing the answer and additional information).
void store(size_t id) const
std::size_t peak_memory_kbytes
Peak memory usage.
size_t stored_id
Identifier for temporary file.
std::map< std::string, std::string > additional
Arbitrary additional information that can be provided by the tool class.
std::string answer
Answer string.