40 template<
typename T,
typename S,
typename U>
42 std::cout << std::setw(54) << std::left <<
"" << std::setw(16) <<
"First value" <<
"\t" << std::setw(16) <<
"Second value" <<
"\t" << std::setw(16) <<
"Evolution" <<
"Unit" << std::endl;
43 for (
size_t i = 0; i < d.
size(); i++)
44 std::cout << std::setw(54) << std::left << names[i].first << std::setw(16) << m1[i] <<
"\t" << std::setw(16) << m2[i] <<
"\t" << std::setw(16) << d[i] << names[i].second << std::endl;
45 std::cout << std::endl << std::endl;
56 std::cout << std::setw(54) <<
" ";
58 std::cout << std::setw(16) << std::left << st <<
"\t";
59 std::cout <<
"Unit" << std::endl;
60 for (
size_t i = 0; i < s.
min.
size(); i++) {
61 std::cout << std::setw(54) << std::left << names[i].first;
63 std::cout << std::setw(16) << st[i] <<
"\t";
65 std::cout << names[i].second << std::endl;
67 std::cout << std::endl << std::endl;
82 for (
auto itr = request.begin(); itr < request.end(); itr++)
97 std::vector<MetroCollect::MetricsSource::FieldInfo> fields(metricsArray.
fieldCount());
98 for (
size_t i = 0; i < fields.size(); i++)
101 std::vector<std::pair<std::string, std::string>> names;
102 names.reserve(fields.size());
103 std::stringstream ss;
104 for (
const auto& field : fields) {
105 ss.str(std::string());
106 for (
const auto& part : field.name)
108 names.push_back(std::pair{ss.str(), field.unit});
120 std::vector<std::pair<std::chrono::duration<double, std::milli>, std::vector<MetroCollect::DiffValueType>>>
values;
121 std::vector<std::pair<std::string, std::string>>
names;
122 std::chrono::time_point<std::chrono::system_clock>
start;
130 void set(
size_t iterations, std::vector<std::pair<std::string, std::string>> metricsNames) {
131 this->iterationCount = iterations;
132 this->names = metricsNames;
133 this->values.clear();
134 this->values.resize(iterations, {std::chrono::duration<double, std::milli>::zero(), std::vector<MetroCollect::DiffValueType>(metricsNames.size())});
135 this->start = std::chrono::system_clock::now();
140 std::copy(diff.
begin(), diff.
end(), this->values[
i].second.begin());
162 int main(
int argc,
char* argv[]) {
164 size_t iterations = 10;
165 const char* file =
"output.csv";
169 samplingInterval = std::chrono::milliseconds(std::atol(argv[1]));
171 iterations = std::atol(argv[2]);
186 std::ofstream output;
189 output <<
"name,unit";
190 for (
size_t j = 0; j < iterations; j++)
191 output <<
"," << d.
values[j].first.count();
193 for (
size_t i = 0; i < d.
names.size(); i++) {
194 output << d.
names[i].first <<
"," << d.
names[i].second;
195 for (
size_t j = 0; j < iterations; j++)
196 output <<
"," << d.
values[j].second[i];
static constexpr std::chrono::milliseconds defaultSamplingInterval
Default parameter option.
Struct to store all final metric stats.
void setRequestedMetrics(const MetricsArray< Statistics::Stats > &requestedMetrics) noexcept
Sets the list of request metrics.
Iterator begin() noexcept
Returns an iterator to the first element of the container.
void metricsContollerCollectedMetricsStats(const MetroCollect::MetricsController &, const MetroCollect::MetricsController::MetricsStats &) override
Function called every time the MetricsController has computed statistics.
Small struct to implement MetricsController delegate.
auto getAllFieldNames(const MetroCollect::MetricsArray< T > &metricsArray)
Get fields name of all metrics.
void metricsContollerCollectedMetricsValues(const MetroCollect::MetricsController &, const MetroCollect::MetricsDiffArray &diff, const MetroCollect::MetricsDataArray &, const MetroCollect::MetricsDataArray &) override
Function called every time the MetricsController has collected new values.
Generic class to store and manage metrics.
Stats
Bitwise type te select statistics.
void setSamplingInterval(std::chrono::milliseconds interval) noexcept
Sets the metrics sampling interval.
const std::chrono::system_clock::time_point & endTime() const noexcept
Get time of latest metrics.
std::vector< std::pair< std::chrono::duration< double, std::milli >, std::vector< MetroCollect::DiffValueType > > > values
Array of all collected metrics and their relative timestamps.
void collectMetrics()
Launch metric collection loop.
void setConvertToUnitsPerSeconds(bool convertToUnitsPerSecond) noexcept
Sets whether to convert metric differences to units per second.
void printMetricsStats(const std::vector< std::pair< std::string, std::string >> &names, const MetroCollect::MetricsController::MetricsStats &s)
Print metric stats on screen.
std::chrono::time_point< std::chrono::system_clock > start
Start time of metric collection.
auto generateMetrics()
Generate metric request to give to the MetricsController.
size_t iterationCount
Number of iterations remaining to be done.
SourceInterests makeSourceInterests(bool value)
Construct a new shared pointer to a SourceInterests object.
void forEach(Function func)
Execute a function for each stats array.
bool metricsContollerShouldStopCollectingMetrics(const MetroCollect::MetricsController &) override
Function called after each iteration to ask the delegate whether the controller should stop collectin...
void set(size_t iterations, std::vector< std::pair< std::string, std::string >> metricsNames)
Update members.
void setProcessingWindow(size_t length, size_t overlap) noexcept
Sets the processing window parameters used to compute statistics.
const MetricsSource::FieldInfo fieldInfoAtIndex(size_t index) const noexcept
Get details about a specific metric field.
Class to fetch metrics from the kernel and store them.
void setSendValues(bool sendValues) noexcept
Sets whether the controller alerts the delegate after collecting new values.
Iterator end() noexcept
Returns an iterator to the element following the last element of the container.
void printMetricsValues(const std::vector< std::pair< std::string, std::string >> &names, const MetroCollect::MetricsArray< T > &m1, const MetroCollect::MetricsArray< S > &m2, const MetroCollect::MetricsArray< U > &d)
Print metrics on screen.
static constexpr std::array< std::string_view, count > names
Names of available statistics.
int main(int argc, char *argv[])
MetroCollectFile main function.
Abstract delegate of MetricsController.
size_t fieldCount() const noexcept
Returns the total number of available metrics.
MetricsStatsArray< DiffValueType > min
Array of minimums.
std::vector< std::pair< std::string, std::string > > names
Name of collected metrics.
Class to control the collection of metrics.
Class to compute and store metric values variations.
size_t size() const noexcept
Returns the size of the underlying array.