mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-30 00:00:11 +01:00
stats: allow stats hook to be used with villas-hook in which case there is no node object
This commit is contained in:
parent
1bc639644e
commit
040c8e69bb
1 changed files with 68 additions and 45 deletions
|
@ -45,20 +45,14 @@ protected:
|
||||||
StatsHook *parent;
|
StatsHook *parent;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
StatsWriteHook(struct path *p, struct node *n, int fl, int prio, bool en = true) :
|
StatsWriteHook(StatsHook *pa, struct path *p, struct node *n, int fl, int prio, bool en = true) :
|
||||||
Hook(p, n, fl, prio, en)
|
Hook(p, n, fl, prio, en),
|
||||||
|
parent(pa)
|
||||||
{
|
{
|
||||||
state = State::CHECKED;
|
state = State::CHECKED;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Hook::Reason process(sample *smp)
|
virtual Hook::Reason process(sample *smp);
|
||||||
{
|
|
||||||
timespec now = time_now();
|
|
||||||
|
|
||||||
node->stats->update(Stats::Metric::AGE, time_delta(&smp->ts.received, &now));
|
|
||||||
|
|
||||||
return Reason::OK;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class StatsReadHook : public Hook {
|
class StatsReadHook : public Hook {
|
||||||
|
@ -66,9 +60,12 @@ class StatsReadHook : public Hook {
|
||||||
protected:
|
protected:
|
||||||
sample *last;
|
sample *last;
|
||||||
|
|
||||||
|
StatsHook *parent;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
StatsReadHook(struct path *p, struct node *n, int fl, int prio, bool en = true) :
|
StatsReadHook(StatsHook *pa, struct path *p, struct node *n, int fl, int prio, bool en = true) :
|
||||||
Hook(p, n, fl, prio, en)
|
Hook(p, n, fl, prio, en),
|
||||||
|
parent(pa)
|
||||||
{
|
{
|
||||||
state = State::CHECKED;
|
state = State::CHECKED;
|
||||||
}
|
}
|
||||||
|
@ -92,38 +89,14 @@ public:
|
||||||
state = State::STOPPED;
|
state = State::STOPPED;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Hook::Reason process(sample *smp)
|
virtual Hook::Reason process(sample *smp);
|
||||||
{
|
|
||||||
if (last) {
|
|
||||||
if (smp->flags & last->flags & (int) SampleFlags::HAS_TS_RECEIVED)
|
|
||||||
node->stats->update(Stats::Metric::GAP_RECEIVED, time_delta(&last->ts.received, &smp->ts.received));
|
|
||||||
|
|
||||||
if (smp->flags & last->flags & (int) SampleFlags::HAS_TS_ORIGIN)
|
|
||||||
node->stats->update(Stats::Metric::GAP_SAMPLE, time_delta(&last->ts.origin, &smp->ts.origin));
|
|
||||||
|
|
||||||
if ((smp->flags & (int) SampleFlags::HAS_TS_ORIGIN) && (smp->flags & (int) SampleFlags::HAS_TS_RECEIVED))
|
|
||||||
node->stats->update(Stats::Metric::OWD, time_delta(&smp->ts.origin, &smp->ts.received));
|
|
||||||
|
|
||||||
if (smp->flags & last->flags & (int) SampleFlags::HAS_SEQUENCE) {
|
|
||||||
int dist = smp->sequence - (int32_t) last->sequence;
|
|
||||||
if (dist != 1)
|
|
||||||
node->stats->update(Stats::Metric::SMPS_REORDERED, dist);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sample_incref(smp);
|
|
||||||
|
|
||||||
if (last)
|
|
||||||
sample_decref(last);
|
|
||||||
|
|
||||||
last = smp;
|
|
||||||
|
|
||||||
return Reason::OK;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class StatsHook : public Hook {
|
class StatsHook : public Hook {
|
||||||
|
|
||||||
|
friend StatsReadHook;
|
||||||
|
friend StatsWriteHook;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
StatsReadHook *readHook;
|
StatsReadHook *readHook;
|
||||||
StatsWriteHook *writeHook;
|
StatsWriteHook *writeHook;
|
||||||
|
@ -150,11 +123,13 @@ public:
|
||||||
uri()
|
uri()
|
||||||
{
|
{
|
||||||
/* Add child hooks */
|
/* Add child hooks */
|
||||||
readHook = new StatsReadHook(p, n, fl, prio, en);
|
readHook = new StatsReadHook(this, p, n, fl, prio, en);
|
||||||
writeHook = new StatsWriteHook(p, n, fl, prio, en);
|
writeHook = new StatsWriteHook(this, p, n, fl, prio, en);
|
||||||
|
|
||||||
vlist_push(&node->in.hooks, (void *) readHook);
|
if (node) {
|
||||||
vlist_push(&node->out.hooks, (void *) writeHook);
|
vlist_push(&node->in.hooks, (void *) readHook);
|
||||||
|
vlist_push(&node->out.hooks, (void *) writeHook);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void start()
|
virtual void start()
|
||||||
|
@ -189,6 +164,15 @@ public:
|
||||||
stats->reset();
|
stats->reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual Hook::Reason process(sample *smp)
|
||||||
|
{
|
||||||
|
// Only call readHook if it hasnt been added to the node's hook list
|
||||||
|
if (!node)
|
||||||
|
return readHook->process(smp);
|
||||||
|
|
||||||
|
return Hook::Reason::OK;
|
||||||
|
}
|
||||||
|
|
||||||
virtual void periodic()
|
virtual void periodic()
|
||||||
{
|
{
|
||||||
assert(state == State::STARTED);
|
assert(state == State::STARTED);
|
||||||
|
@ -239,12 +223,51 @@ public:
|
||||||
/* Register statistic object to path.
|
/* Register statistic object to path.
|
||||||
*
|
*
|
||||||
* This allows the path code to update statistics. */
|
* This allows the path code to update statistics. */
|
||||||
node->stats = stats;
|
if (node)
|
||||||
|
node->stats = stats;
|
||||||
|
|
||||||
state = State::PREPARED;
|
state = State::PREPARED;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Hook::Reason StatsWriteHook::process(sample *smp)
|
||||||
|
{
|
||||||
|
timespec now = time_now();
|
||||||
|
|
||||||
|
parent->stats->update(Stats::Metric::AGE, time_delta(&smp->ts.received, &now));
|
||||||
|
|
||||||
|
return Reason::OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
Hook::Reason StatsReadHook::process(sample *smp)
|
||||||
|
{
|
||||||
|
if (last) {
|
||||||
|
if (smp->flags & last->flags & (int) SampleFlags::HAS_TS_RECEIVED)
|
||||||
|
parent->stats->update(Stats::Metric::GAP_RECEIVED, time_delta(&last->ts.received, &smp->ts.received));
|
||||||
|
|
||||||
|
if (smp->flags & last->flags & (int) SampleFlags::HAS_TS_ORIGIN)
|
||||||
|
parent->stats->update(Stats::Metric::GAP_SAMPLE, time_delta(&last->ts.origin, &smp->ts.origin));
|
||||||
|
|
||||||
|
if ((smp->flags & (int) SampleFlags::HAS_TS_ORIGIN) && (smp->flags & (int) SampleFlags::HAS_TS_RECEIVED))
|
||||||
|
parent->stats->update(Stats::Metric::OWD, time_delta(&smp->ts.origin, &smp->ts.received));
|
||||||
|
|
||||||
|
if (smp->flags & last->flags & (int) SampleFlags::HAS_SEQUENCE) {
|
||||||
|
int dist = smp->sequence - (int32_t) last->sequence;
|
||||||
|
if (dist != 1)
|
||||||
|
parent->stats->update(Stats::Metric::SMPS_REORDERED, dist);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sample_incref(smp);
|
||||||
|
|
||||||
|
if (last)
|
||||||
|
sample_decref(last);
|
||||||
|
|
||||||
|
last = smp;
|
||||||
|
|
||||||
|
return Reason::OK;
|
||||||
|
}
|
||||||
|
|
||||||
/* Register hook */
|
/* Register hook */
|
||||||
static HookPlugin<StatsHook> p(
|
static HookPlugin<StatsHook> p(
|
||||||
"stats",
|
"stats",
|
||||||
|
|
Loading…
Add table
Reference in a new issue