2019-06-23 13:35:42 +02:00
|
|
|
/** Statistic collection.
|
|
|
|
*
|
|
|
|
* @file
|
2022-12-14 17:41:58 +01:00
|
|
|
* @author Steffen Vogel <post@steffenvogel.de>
|
2022-03-15 09:28:57 -04:00
|
|
|
* @copyright 2014-2022, Institute for Automation of Complex Power Systems, EONERC
|
2022-07-04 18:20:03 +02:00
|
|
|
* @license Apache 2.0
|
2019-06-23 13:35:42 +02:00
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <jansson.h>
|
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
2020-03-04 12:41:55 +01:00
|
|
|
#include <villas/common.hpp>
|
2019-06-23 13:35:42 +02:00
|
|
|
#include <villas/hist.hpp>
|
|
|
|
#include <villas/table.hpp>
|
2021-08-10 10:12:48 -04:00
|
|
|
#include <villas/signal.hpp>
|
2021-02-16 14:15:14 +01:00
|
|
|
#include <villas/log.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
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
}
|
2019-06-23 13:35:42 +02:00
|
|
|
|
|
|
|
class Stats {
|
|
|
|
|
|
|
|
public:
|
2021-08-10 10:12:48 -04:00
|
|
|
using Ptr = std::shared_ptr<Stats>;
|
|
|
|
|
2019-06-23 13:35:42 +02:00
|
|
|
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. */
|
2021-11-10 05:30:49 -05:00
|
|
|
SIGNAL_COUNT, /**< Number of signals per sample. */
|
2019-06-23 13:35:42 +02:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
std::unordered_map<Metric, villas::Hist> histograms;
|
|
|
|
|
|
|
|
struct MetricDescription {
|
|
|
|
const char *name;
|
|
|
|
const char *unit;
|
|
|
|
const char *desc;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct TypeDescription {
|
|
|
|
const char *name;
|
2021-08-10 10:12:48 -04:00
|
|
|
enum node::SignalType signal_type;
|
2019-06-23 13:35:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static std::shared_ptr<Table> table;
|
|
|
|
|
|
|
|
static void setupTable();
|
|
|
|
|
2021-02-16 14:15:14 +01:00
|
|
|
Logger logger;
|
|
|
|
|
2019-06-23 13:35:42 +02:00
|
|
|
public:
|
|
|
|
|
|
|
|
Stats(int buckets, int warmup);
|
|
|
|
|
|
|
|
static
|
|
|
|
enum Format lookupFormat(const std::string &str);
|
|
|
|
|
|
|
|
static
|
|
|
|
enum Metric lookupMetric(const std::string &str);
|
|
|
|
|
|
|
|
static
|
|
|
|
enum Type lookupType(const std::string &str);
|
|
|
|
|
|
|
|
void update(enum Metric id, double val);
|
|
|
|
|
|
|
|
void reset();
|
|
|
|
|
|
|
|
json_t * toJson() const;
|
|
|
|
|
|
|
|
static
|
|
|
|
void printHeader(enum Format fmt);
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
void printPeriodic(FILE *f, enum Format fmt, node::Node *n) const;
|
2019-06-23 13:35:42 +02:00
|
|
|
|
|
|
|
void print(FILE *f, enum Format fmt, int verbose) const;
|
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
union node::SignalData getValue(enum Metric sm, enum Type st) const;
|
2019-06-23 13:35:42 +02:00
|
|
|
|
2021-08-10 10:12:48 -04:00
|
|
|
const Hist & getHistogram(enum Metric sm) const;
|
2019-06-23 13:35:42 +02:00
|
|
|
|
|
|
|
static std::unordered_map<Metric, MetricDescription> metrics;
|
|
|
|
static std::unordered_map<Type, TypeDescription> types;
|
|
|
|
static std::vector<TableColumn> columns;
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace villas */
|