valFuzz 1.2.0
Loading...
Searching...
No Matches
reporter.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// Author: Giovanni Santini
3// Mail: giovanni.santini@proton.me
4// Github: @San7o
5
6#pragma once
7
8#include <iostream>
9#include <memory>
10#include <optional>
11#include <sstream>
12#include <vector>
13
14namespace valfuzz
15{
16
17struct report
18{
19 const std::string benchmark_name;
20 long unsigned int input_size;
21 double min;
22 double max;
23 double median;
24 double mean;
26 double q1;
27 double q2;
28};
29
34{
35public:
36 reporter() = default;
37 virtual ~reporter() = 0;
38
39 virtual std::string id() const = 0;
40 virtual std::ostringstream output(struct report *rep) const = 0;
41};
42
47{
48public:
49 reporter_engine() = default;
50 ~reporter_engine() = default;
51
52 std::ostringstream report(struct report *rep, std::string id) const
53 {
54 for (auto &r : reporters)
55 if (r->id() == id)
56 return r->output(rep);
57 return std::ostringstream();
58 }
59
60 void add_reporter(std::shared_ptr<reporter> in_reporter) noexcept
61 {
62 this->reporters.push_back(in_reporter);
63 }
64
65 bool has([[maybe_unused]] std::string id)
66 {
67 for (auto &r : reporters)
68 {
69 if (r->id() == id)
70 return true;
71 }
72 return false;
73 }
74
75private:
76 std::vector<std::shared_ptr<reporter>> reporters;
77};
78
82extern reporter_engine reporter_eg;
83
84#define ADD_REPORTER(in_rep) \
85 static struct in_rep##_reporter \
86 { \
87 in_rep##_reporter() \
88 { \
89 reporter_eg.add_reporter(std::make_shared<in_rep>(in_rep())); \
90 } \
91 } in_rep##_reporter_instance
92
94{
95public:
96 std::string id() const override
97 {
98 return "default";
99 }
100 std::ostringstream output(struct report *rep) const override
101 {
102 std::ostringstream oss;
103 oss << "benchmark: \"" << rep->benchmark_name
104 << "\"\n - space: " << rep->input_size << "\n - min: " << rep->min
105 << "s\n - max: " << rep->max << "s\n - median: " << rep->median
106 << "s\n - mean: " << rep->mean
107 << "s\n - standard deviation: " << rep->standard_deviation
108 << "\n - Q1: " << rep->q1 << "s\n - Q3: " << rep->q2 << "\n";
109 return oss;
110 }
111};
112
113class csv_reporter : public reporter
114{
115public:
116 std::string id() const override
117 {
118 return "csv";
119 }
120 std::ostringstream output(struct report *rep) const override
121 {
122 std::ostringstream oss;
123 oss << "\"" << rep->benchmark_name << "\"," << rep->input_size << ","
124 << rep->min << "," << rep->max << "," << rep->median << "," << rep->mean
125 << "," << rep->standard_deviation << "," << rep->q1 << "," << rep->q2
126 << "\n";
127 return oss;
128 }
129};
130
135{
136public:
137 std::string id() const override
138 {
139 return "none";
140 }
141 std::ostringstream output([[maybe_unused]] struct report *rep) const override
142 {
143 std::ostringstream oss;
144 return oss;
145 }
146};
147
148std::string &get_reporter();
149void set_reporter(std::string rep);
150
151} // namespace valfuzz
std::ostringstream output(struct report *rep) const override
Definition reporter.hpp:120
std::string id() const override
Definition reporter.hpp:116
std::string id() const override
Definition reporter.hpp:96
std::ostringstream output(struct report *rep) const override
Definition reporter.hpp:100
std::ostringstream output(struct report *rep) const override
Definition reporter.hpp:141
std::string id() const override
Definition reporter.hpp:137
void add_reporter(std::shared_ptr< reporter > in_reporter) noexcept
Definition reporter.hpp:60
bool has(std::string id)
Definition reporter.hpp:65
std::ostringstream report(struct report *rep, std::string id) const
Definition reporter.hpp:52
virtual std::string id() const =0
virtual ~reporter()=0
Definition reporter.cpp:16
virtual std::ostringstream output(struct report *rep) const =0
reporter()=default
void set_reporter(std::string rep)
Definition reporter.cpp:26
reporter_engine reporter_eg
Definition reporter.cpp:10
std::string & get_reporter()
Definition reporter.cpp:20
double standard_deviation
Definition reporter.hpp:25
const std::string benchmark_name
Definition reporter.hpp:19
long unsigned int input_size
Definition reporter.hpp:20