23namespace kamping::measurements {
28inline std::string quote_string(std::string
const& str) {
29 return "\"" + str +
"\"";
68template <
typename Duration =
double>
87 _internal_printer(_outstream),
94 _outstream << std::string(
indentation,
' ') <<
"{" << std::endl;
95 _outstream << std::string(
indentation + indentation_per_level,
' ') << quote_string(
"data") <<
": {"
97 print_impl(
node,
indentation + indentation_per_level + indentation_per_level);
98 _outstream << std::endl;
99 _outstream << std::string(
indentation + indentation_per_level,
' ') <<
"}," << std::endl;
102 _outstream << std::string(
indentation,
' ') <<
"}";
106 std::ostream& _outstream;
107 std::size_t indentation_per_level = 2u;
110 std::vector<std::pair<std::string, std::string>> _config_info;
113 _outstream << std::boolalpha;
114 _outstream << std::string(
indentation,
' ') << quote_string(
"config") <<
": {";
115 if (_config_info.empty()) {
117 _outstream <<
"}" << std::endl;
121 _outstream << std::endl;
123 for (
auto const& [
key, value]: _config_info) {
125 _outstream <<
"," << std::endl;
128 _outstream << std::string(indentation + indentation_per_level,
' ') << quote_string(key) <<
":"
129 << quote_string(value);
131 _outstream << std::endl << std::string(indentation,
' ') <<
"}" << std::endl;
137 void print_impl(AggregatedTreeNode<Duration>
const& node, std::size_t indentation = 0) {
138 auto name = node.name();
139 auto evaluation_data = node.aggregated_data();
140 _outstream << std::string(indentation,
' ') << quote_string(name) <<
": {" << std::endl;
141 _outstream << std::string(indentation + indentation_per_level,
' ') << quote_string(
"statistics") <<
": {"
143 if (!evaluation_data.empty()) {
144 bool is_first_outer =
true;
145 for (
auto const& [
op, data]: evaluation_data) {
146 if (!is_first_outer) {
147 _outstream <<
"," << std::endl;
149 is_first_outer =
false;
150 _outstream << std::string(indentation + 2 * indentation_per_level,
' ') <<
"\"" <<
get_string(
op)
153 bool is_first =
true;
154 for (
auto const& data_item: data) {
159 std::visit(_internal_printer, data_item);
163 _outstream << std::endl;
165 _outstream << std::string(indentation + indentation_per_level,
' ') <<
"}";
166 if (!node.children().empty()) {
169 _outstream << std::endl;
171 bool is_first =
true;
172 for (
auto const& children: node.children()) {
174 _outstream <<
"," << std::endl;
177 print_impl(*children, indentation + indentation_per_level);
179 if (!node.children().empty()) {
180 _outstream << std::endl;
182 _outstream << std::string(indentation,
' ') <<
"}";
216 template <
typename Duration>
218 _key_stack.push_back(
node.name());
220 for (
auto const& [
operation, aggregated_data]:
node.aggregated_data()) {
223 for (
auto const&
data_item: aggregated_data) {
233 for (
auto const&
child:
node.children()) {
238 _key_stack.pop_back();
242 std::ostream& _outstream;
243 std::vector<std::string> _key_stack;
245 std::string concatenate_key_stack()
const {
247 for (
auto const&
key: _key_stack) {
STL-compatible allocator for requesting memory using the builtin MPI allocator.
Definition allocator.hpp:32
Printer class that prints an evaluated TimerTree in a flat format in which the timer hierarchy is col...
Definition printer.hpp:204
FlatPrinter(std::ostream &outstream)
Construct a printer printing to a given outstream.
Definition printer.hpp:212
FlatPrinter()
Construct a printer that use std::cout as outstream.
Definition printer.hpp:207
void print(AggregatedTreeNode< Duration > const &node)
Prints an evaluated TimerTree in Json format to stdout.
Definition printer.hpp:217
Printer class that prints an evaluated TimerTree in Json format.
Definition printer.hpp:69
SimpleJsonPrinter(std::ostream &outstream, std::vector< std::pair< std::string, std::string > > config_info)
Construct a printer printing to a given outstream and adding additional configuration info.
Definition printer.hpp:85
void print(AggregatedTreeNode< Duration > const &node, std::size_t indentation=0)
Prints an evaluated TimerTree in Json format to stdout.
Definition printer.hpp:93
SimpleJsonPrinter()
Construct a printer that use std::cout as outstream.
Definition printer.hpp:72
SimpleJsonPrinter(std::ostream &outstream)
Construct a printer printing to a given outstream.
Definition printer.hpp:77
internal::OperationBuilder< Op, Commutative > op(Op &&op, Commutative commute=ops::internal::undefined_commutative_tag{})
Passes a reduction operation to ther underlying call. Accepts function objects, lambdas,...
Definition named_parameters.hpp:1155
std::string get_string(GlobalAggregationMode mode)
Returns name of given GlobalAggregationMode.
Definition measurement_aggregation_definitions.hpp:47
Able to print either a single value or a vector of value to the given outstream.
Definition printer.hpp:36
ScalarOrVectorPrinter(std::ostream &outstream)
Constructs a printer printing to the given outstream.
Definition printer.hpp:39
void operator()(T const &scalar) const
Outputs the given scalar to outstream.
Definition printer.hpp:58
void operator()(std::vector< T > const &vec) const
Outputs the content of the given vector to outstream.
Definition printer.hpp:43
std::ostream & _outstream
Outstream used for printing.
Definition printer.hpp:61