1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00
VILLASnode/include/villas/stats.hpp

133 lines
3.1 KiB
C++
Raw Permalink Normal View History

2019-06-23 13:35:42 +02:00
/** Statistic collection.
*
* @file
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
2020-01-20 17:17:00 +01:00
* @copyright 2014-2020, Institute for Automation of Complex Power Systems, EONERC
2019-06-23 13:35:42 +02:00
* @license GNU General Public License (version 3)
*
* VILLASnode
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************************/
#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>
#include <villas/signal.h>
/* Forward declarations */
struct sample;
2020-08-25 21:00:52 +02:00
struct vnode;
2019-06-23 13:35:42 +02:00
namespace villas {
class Stats {
public:
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. */
/* 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;
2019-06-23 16:13:23 +02:00
enum SignalType signal_type;
2019-06-23 13:35:42 +02:00
};
static std::shared_ptr<Table> table;
static void setupTable();
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);
2020-08-25 21:00:52 +02:00
void printPeriodic(FILE *f, enum Format fmt, struct vnode *p) const;
2019-06-23 13:35:42 +02:00
void print(FILE *f, enum Format fmt, int verbose) const;
union signal_data getValue(enum Metric sm, enum Type st) const;
const villas::Hist & getHistogram(enum Metric sm) const;
static std::unordered_map<Metric, MetricDescription> metrics;
static std::unordered_map<Type, TypeDescription> types;
static std::vector<TableColumn> columns;
};
} /* namespace villas */