aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2019-02-04 17:41:29 -0500
committerDave Barach <dave@barachs.net>2019-02-04 17:50:22 -0500
commit3117ad8aa50afba68b2fa2c7f2b6f91eeb5a555e (patch)
tree43a55223adbf30a35f3f1437c1459f516a4012f9 /src
parent288eaab5964b9211350acad8d742fae4789577fe (diff)
g2-only: add (min,max) stats to the anomaly detector
Shows up on the status line. Change-Id: I14635f7406069a4a868bdb7c8b85da941c49dbba Signed-off-by: Dave Barach <dave@barachs.net>
Diffstat (limited to 'src')
-rw-r--r--src/tools/g2/view1.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/src/tools/g2/view1.c b/src/tools/g2/view1.c
index b9d67ea3ce1..ca05b78267f 100644
--- a/src/tools/g2/view1.c
+++ b/src/tools/g2/view1.c
@@ -158,6 +158,7 @@ typedef struct v1_geometry {
/* Anomaly detection statistics */
f64 *means, *variances, *two_stddevs;
+ f64 *mins, *maxes;
u32 *matches;
} v1_geometry_t;
@@ -1640,6 +1641,8 @@ static int anomaly_statistics_init (void)
vec_reset_length (s_v1->matches);
vec_reset_length (s_v1->variances);
vec_reset_length (s_v1->two_stddevs);
+ vec_reset_length (s_v1->mins);
+ vec_reset_length (s_v1->maxes);
for (i = 0; i < g_nevents; i++) {
if (ep->code != s_anomalycode) {
@@ -1647,13 +1650,26 @@ static int anomaly_statistics_init (void)
continue;
}
pid = ep->pid;
- vec_validate_init_empty (s_v1->means, pid->pid_index, 0);
vec_validate_init_empty (s_v1->matches, pid->pid_index, 0);
+ vec_validate_init_empty (s_v1->means, pid->pid_index, 0.0);
+ vec_validate_init_empty (s_v1->mins, pid->pid_index, 0.0);
+ vec_validate_init_empty (s_v1->maxes, pid->pid_index, 0.0);
eep = get_clib_event (ep->datum);
data = clib_mem_unaligned (eep->data, u32);
fdata = data;
s_v1->means[pid->pid_index] += fdata;
s_v1->matches[pid->pid_index] += 1;
+ /* First data point? set min, max */
+ if (PREDICT_FALSE(s_v1->matches[pid->pid_index] == 1)) {
+ s_v1->mins[pid->pid_index] = fdata;
+ s_v1->maxes[pid->pid_index] = fdata;
+ } else {
+ s_v1->mins[pid->pid_index] = (fdata < s_v1->mins[pid->pid_index]) ?
+ fdata : s_v1->mins[pid->pid_index];
+ s_v1->maxes[pid->pid_index] =
+ (fdata > s_v1->maxes[pid->pid_index]) ?
+ fdata : s_v1->maxes[pid->pid_index];
+ }
ep++;
}
if (vec_len (s_v1->matches) == 0)
@@ -1747,13 +1763,17 @@ boolean anomaly_search_internal (void)
s_v1->two_stddevs[pid->pid_index]) {
u8 *s;
- s = format (0, "%.1f*stddev {mean,threshold}: ",
+ s = format (0, "%.1f*stddev {min,max,mean,threshold}: ",
s_v1->anomaly_threshold_stddevs);
for (i = 0; i < vec_len (s_v1->means); i++) {
- s = format (s, "{%.0f, %.0f} ",
- s_v1->means[i],
- s_v1->means[i]+s_v1->two_stddevs[i]);
+ if (s_v1->matches[i] > 0)
+ s = format (s, "{%.0f, %.0f, %.0f, %.0f} ",
+ s_v1->mins[i], s_v1->maxes[i],
+ s_v1->means[i],
+ s_v1->means[i]+s_v1->two_stddevs[i]);
+ else
+ s = format (s, "{no match} ");
}
message_line ((char *)s);