SMT-RAT  24.02
Toolbox for Strategic and Parallel Satisfiability-Modulo-Theories Solving
LocalBackend.h
Go to the documentation of this file.
1 /**
2  * @file LocalBackend.h
3  * @author Gereon Kremer <gereon.kremer@cs.rwth-aachen.de>
4  */
5 
6 #pragma once
7 
8 #include <chrono>
9 
10 #include "Backend.h"
11 
12 #include "../utils/execute.h"
13 
14 #include "../utils/parsing.h"
15 
16 namespace benchmax {
17 
18 /**
19  * This backend simply runs files sequentially on the local machine.
20  */
21 class LocalBackend: public Backend {
22 protected:
23  /// Execute the tool on the file manually.
24  virtual void execute(const Tool* tool, const fs::path& file) {
25  std::stringstream call;
26  call << "ulimit -S -t " << std::chrono::seconds(settings_benchmarks().limit_time).count() << " && ";
27  call << "ulimit -S -v " << settings_benchmarks().limit_memory.kibi() << " && ";
28  call << "date +\"Start: %s%3N\" && ";
29  call << "/usr/bin/time -v ";
30  call << tool->getCommandline(file.native()) << " 2> stderr.log && ";
31  call << "date +\"End: %s%3N\"";
32 
33  BenchmarkResult results;
34  auto start = std::chrono::high_resolution_clock::now();
35 
36  int exitCode = call_program(call.str(), results.stdout);
37  results.exitCode = WEXITSTATUS(exitCode);
38 
39  auto end = std::chrono::high_resolution_clock::now();
40  results.time = std::chrono::duration_cast<decltype(results.time)>(end - start);
41 
42  std::ifstream ifs("stderr.log");
43  results.stderr.assign((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
44  results.peak_memory_kbytes = parse_peak_memory(results.stderr);
45  results.stderr.clear();
46 
47  addResult(tool, file, std::move(results));
48  madeProgress();
49  }
50 };
51 
52 }
Base class for all backends.
Definition: Backend.h:23
void madeProgress(std::size_t files=1)
Can be called to give information about the current progress, if available.
Definition: Backend.h:51
void addResult(const Tool *tool, const fs::path &file, BenchmarkResult &&result)
Add a result.
Definition: Backend.h:97
This backend simply runs files sequentially on the local machine.
Definition: LocalBackend.h:21
virtual void execute(const Tool *tool, const fs::path &file)
Execute the tool on the file manually.
Definition: LocalBackend.h:24
Base class for any tool.
Definition: Tool.h:38
virtual std::string getCommandline(const std::string &file) const
Compose commandline for this tool and the given input file.
Definition: Tool.h:122
int call_program(const std::string &commandline, std::string &stdout, bool print_to_stdout=false)
Runs an external program from some command line and records the output to stdout.
Definition: execute.h:18
const auto & settings_benchmarks()
Return the benchmark settings.
Definition: benchmarks.h:41
std::size_t parse_peak_memory(const std::string &output)
Definition: parsing.h:4
Results for a single benchmark run.
int exitCode
Shell exit code.
std::string stdout
Standard output (mostly for parsing the answer and additional information).
std::chrono::milliseconds time
Runtime in milliseconds.
std::string stderr
Error output (mostly for parsing the answer and additional information).
std::size_t peak_memory_kbytes
Peak memory usage.