2016-06-08 22:38:50 +02:00
|
|
|
/** Statistic-related hook functions.
|
|
|
|
*
|
|
|
|
* @author Steffen Vogel <stvogel@eonerc.rwth-aachen.de>
|
|
|
|
* @copyright 2014-2016, Institute for Automation of Complex Power Systems, EONERC
|
2016-06-08 23:21:42 +02:00
|
|
|
* This file is part of VILLASnode. All Rights Reserved. Proprietary and confidential.
|
2016-06-08 22:38:50 +02:00
|
|
|
* Unauthorized copying of this file, via any medium is strictly prohibited.
|
|
|
|
*********************************************************************************/
|
|
|
|
|
|
|
|
#include "hooks.h"
|
|
|
|
#include "sample.h"
|
|
|
|
#include "path.h"
|
|
|
|
#include "utils.h"
|
2016-10-22 20:42:05 -04:00
|
|
|
#include "stats.h"
|
2016-06-08 22:38:50 +02:00
|
|
|
|
|
|
|
extern struct list *hook_nodes;
|
|
|
|
|
|
|
|
REGISTER_HOOK("stats", "Collect statistics for the current path", 2, 1, hook_stats, HOOK_STATS)
|
2016-10-22 20:42:05 -04:00
|
|
|
int hook_stats(struct hook *h, int when, struct hook_info *j)
|
2016-06-08 22:38:50 +02:00
|
|
|
{
|
2016-10-30 22:52:06 -04:00
|
|
|
struct stats *s = hook_storage(h, when, sizeof(struct stats), (ctor_cb_t) stats_init, (dtor_cb_t) stats_destroy);
|
2016-10-22 20:42:05 -04:00
|
|
|
|
2016-06-08 22:38:50 +02:00
|
|
|
switch (when) {
|
|
|
|
case HOOK_READ:
|
2016-10-22 20:42:05 -04:00
|
|
|
assert(j->smps);
|
|
|
|
|
|
|
|
stats_collect(s, j->smps, j->cnt);
|
2016-06-08 22:38:50 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case HOOK_PATH_STOP:
|
2016-10-30 22:52:06 -04:00
|
|
|
stats_print(s, 1);
|
2016-06-08 22:38:50 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case HOOK_PATH_RESTART:
|
2016-10-22 20:42:05 -04:00
|
|
|
stats_reset(s);
|
2016-06-08 22:38:50 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case HOOK_PERIODIC:
|
2016-10-22 20:42:05 -04:00
|
|
|
assert(j->path);
|
|
|
|
|
|
|
|
stats_print_periodic(s, j->path);
|
2016-06-08 22:38:50 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-10-22 20:42:05 -04:00
|
|
|
return j->cnt;
|
2016-06-08 22:38:50 +02:00
|
|
|
}
|
|
|
|
|
2016-10-22 20:42:05 -04:00
|
|
|
#if 0 /* currently broken */
|
|
|
|
REGISTER_HOOK("stats_send", "Send path statistics to another node", 99, 0, hook_stats_send, HOOK_STORAGE | HOOK_DESTROY | HOOK_PERIODIC | HOOK_PATH)
|
|
|
|
int hook_stats_send(struct hook *h, int when, struct hook_info *i)
|
2016-06-08 22:38:50 +02:00
|
|
|
{
|
|
|
|
struct private {
|
|
|
|
struct node *dest;
|
|
|
|
int ratio;
|
|
|
|
} *private = hook_storage(h, when, sizeof(*private));
|
|
|
|
|
|
|
|
switch (when) {
|
2016-10-22 20:42:05 -04:00
|
|
|
case HOOK_DESTROY:
|
2016-06-08 22:38:50 +02:00
|
|
|
if (!h->parameter)
|
|
|
|
error("Missing parameter for hook '%s'", h->name);
|
|
|
|
|
|
|
|
if (!hook_nodes)
|
|
|
|
error("Missing reference to node list for hook '%s", h->name);
|
|
|
|
|
|
|
|
private->dest = list_lookup(hook_nodes, h->parameter);
|
|
|
|
if (!private->dest)
|
|
|
|
error("Invalid destination node '%s' for hook '%s'", h->parameter, h->name);
|
|
|
|
|
|
|
|
node_start(private->dest);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HOOK_PERIODIC: {
|
2016-10-22 20:42:05 -04:00
|
|
|
stats_send(s, node);
|
2016-06-08 22:38:50 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2016-10-22 20:42:05 -04:00
|
|
|
}
|
|
|
|
#endif
|