carl  24.04
Computer ARithmetic Library
StatisticsPrinter.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Statistics.h"
4 #include "StatisticsCollector.h"
5 
6 #include <fstream>
7 #include <iostream>
8 #include <iomanip>
9 
10 namespace carl {
11 namespace statistics {
12 
14  SMTLIB,
15  XML
16 };
17 
18 template<StatisticsOutputFormat SOF>
20 
21 template<StatisticsOutputFormat SOF>
22 std::ostream& operator<<(std::ostream& os, StatisticsPrinter<SOF>);
23 
24 template<>
26  for (const auto& s: StatisticsCollector::getInstance().statistics()) {
27  if (s->collected().empty()) continue;
28  os << "(:" << s->name() << " (" << std::endl;
29  std::size_t max_width = 0;
30  for (const auto& kv: s->collected()) {
31  max_width = std::max(max_width, kv.first.size());
32  }
33  for (const auto& kv: s->collected()) {
34  os << "\t:" << std::setw(static_cast<int>(max_width)) << std::left << kv.first << " " << kv.second << std::endl;
35  }
36  os << "))" << std::endl;
37  }
38  return os;
39 }
40 
41 template<>
43  for (const auto& s: StatisticsCollector::getInstance().statistics()) {
44  if (s->collected().empty()) continue;
45  std::string name = s->name();
46  std::replace(name.begin(), name.end(), '<', '(');
47  std::replace(name.begin(), name.end(), '>', ')');
48  os << "\t<module name=\"" << name << "\">\n";
49  for (const auto& kv: s->collected()) {
50  os << "\t\t<stat name=\"" << kv.first << "\" value=\"" << kv.second << "\" />\n";
51  }
52  os << "\t</module>\n";
53  }
54  return os;
55 }
56 
59 }
62 }
63 
64 void statistics_to_xml_file(const std::string& filename) {
65  std::ofstream file;
66  file.open(filename, std::ios::out);
67  file << "<runtimestats>" << std::endl;
68  file << statistics_as_xml();
69  file << "</runtimestats>" << std::endl;
70  file.close();
71 }
72 
73 
74 }
75 }
carl is the main namespace for the library.
void statistics_to_xml_file(const std::string &filename)
std::ostream & operator<<(std::ostream &os, StatisticsPrinter< SOF >)
static StatisticsCollector & getInstance()
Returns the single instance of this class by reference.
Definition: Singleton.h:45