2019-06-23 13:35:42 +02:00
|
|
|
/* Statistic collection.
|
|
|
|
*
|
2022-03-15 09:18:01 -04:00
|
|
|
* Author: Steffen Vogel <post@steffenvogel.de>
|
2022-03-15 09:28:57 -04:00
|
|
|
* SPDX-FileCopyrightText: 2014-2023 Institute for Automation of Complex Power Systems, RWTH Aachen University
|
2022-07-04 18:20:03 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2019-06-23 13:35:42 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <jansson.h>
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
2023-09-07 11:46:39 +02:00
|
|
|
#include <unordered_map>
|
2019-06-23 13:35:42 +02:00
|
|
|
|
2020-03-04 12:41:55 +01:00
|
|
|
#include <villas/common.hpp>
|
2019-06-23 13:35:42 +02:00
|
|
|
#include <villas/hist.hpp>
|
2021-02-16 14:15:14 +01:00
|
|
|
#include <villas/log.hpp>
|
2023-09-07 11:46:39 +02:00
|
|
|
#include <villas/signal.hpp>
|
|
|
|
#include <villas/table.hpp>
|
2019-06-23 13:35:42 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
namespace villas {
|
|
|
|
namespace node {
|
|
|
|
|
2019-06-23 13:35:42 +02:00
|
|
|
// Forward declarations
|
2021-08-10 10:12:48 -04:00
|
|
|
struct Sample;
|
|
|
|
class Node;
|
2019-06-23 13:35:42 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
} // namespace node
|
2019-06-23 13:35:42 +02:00
|
|
|
|
|
|
|
class Stats {
|
|
|
|
|
|
|
|
public:
|
2023-09-07 11:46:39 +02:00
|
|
|
using Ptr = std::shared_ptr<Stats>;
|
|
|
|
|
|
|
|
enum class Format { HUMAN, JSON, MATLAB };
|
|
|
|
|
|
|
|
enum class Metric {
|
|
|
|
SMPS_SKIPPED, // Counter for skipped samples due to hooks.
|
|
|
|
SMPS_REORDERED, // Counter for reordered samples.
|
|
|
|
|
|
|
|
// Timings
|
|
|
|
GAP_SAMPLE, // Histogram for inter sample timestamps (as sent by remote).
|
|
|
|
GAP_RECEIVED, // Histogram for inter sample arrival time (as seen by this instance).
|
|
|
|
OWD, // Histogram for one-way-delay (OWD) of received samples.
|
|
|
|
AGE, // Processing time of packets within VILLASnode.
|
|
|
|
SIGNAL_COUNT, // Number of signals per sample.
|
|
|
|
|
|
|
|
// RTP metrics
|
|
|
|
RTP_LOSS_FRACTION, // Fraction lost since last RTP SR/RR.
|
|
|
|
RTP_PKTS_LOST, // Cumul. no. pkts lost.
|
|
|
|
RTP_JITTER // Interarrival jitter.
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class Type { LAST, HIGHEST, LOWEST, MEAN, VAR, STDDEV, TOTAL };
|
2019-06-23 13:35:42 +02:00
|
|
|
|
|
|
|
protected:
|
2023-09-07 11:46:39 +02:00
|
|
|
std::unordered_map<Metric, villas::Hist> histograms;
|
2019-06-23 13:35:42 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
struct MetricDescription {
|
|
|
|
const char *name;
|
|
|
|
const char *unit;
|
|
|
|
const char *desc;
|
|
|
|
};
|
2019-06-23 13:35:42 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
struct TypeDescription {
|
|
|
|
const char *name;
|
|
|
|
enum node::SignalType signal_type;
|
|
|
|
};
|
2019-06-23 13:35:42 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
static std::shared_ptr<Table> table;
|
2019-06-23 13:35:42 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
static void setupTable();
|
2019-06-23 13:35:42 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
Logger logger;
|
2021-02-16 14:15:14 +01:00
|
|
|
|
2019-06-23 13:35:42 +02:00
|
|
|
public:
|
2023-09-07 11:46:39 +02:00
|
|
|
Stats(int buckets, int warmup);
|
2019-06-23 13:35:42 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
static enum Format lookupFormat(const std::string &str);
|
2019-06-23 13:35:42 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
static enum Metric lookupMetric(const std::string &str);
|
2019-06-23 13:35:42 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
static enum Type lookupType(const std::string &str);
|
2019-06-23 13:35:42 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void update(enum Metric id, double val);
|
2019-06-23 13:35:42 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void reset();
|
2019-06-23 13:35:42 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
json_t *toJson() const;
|
2019-06-23 13:35:42 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
static void printHeader(enum Format fmt);
|
2019-06-23 13:35:42 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void printPeriodic(FILE *f, enum Format fmt, node::Node *n) const;
|
2019-06-23 13:35:42 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
void print(FILE *f, enum Format fmt, int verbose) const;
|
2019-06-23 13:35:42 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
union node::SignalData getValue(enum Metric sm, enum Type st) const;
|
2019-06-23 13:35:42 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
const Hist &getHistogram(enum Metric sm) const;
|
2019-06-23 13:35:42 +02:00
|
|
|
|
2023-09-07 11:46:39 +02:00
|
|
|
static std::unordered_map<Metric, MetricDescription> metrics;
|
|
|
|
static std::unordered_map<Type, TypeDescription> types;
|
|
|
|
static std::vector<TableColumn> columns;
|
2019-06-23 13:35:42 +02:00
|
|
|
};
|
|
|
|
|
2023-08-28 09:34:02 +02:00
|
|
|
} // namespace villas
|