Will be used for testing the module.

Signed-off-by: Jakub Sitnicki <j...@redhat.com>
---
 lib/performance.c | 34 ++++++++++++++++++++++++++++++++++
 lib/performance.h | 13 +++++++++++++
 2 files changed, 47 insertions(+)

diff --git a/lib/performance.c b/lib/performance.c
index e37dcd169..8af124d1d 100644
--- a/lib/performance.c
+++ b/lib/performance.c
@@ -215,6 +215,40 @@ add_sample(struct performance *perf, double new_sample)
     calc_average(&perf->long_term, new_sample);
 }
 
+static bool
+performance_get_stats_protected(const char *name,
+                                struct performance_stats *stats)
+{
+    struct performance *perf;
+
+    perf = shash_find_data(&performances, name);
+    if (!perf) {
+        return false;
+    }
+
+    stats->count = perf->samples;
+    stats->unit = perf->units;
+    stats->max = perf->max;
+    stats->min = perf->min;
+    stats->pctl_95 = perf->pctl.percentile;
+    stats->ewma_50 = perf->short_term.average;
+    stats->ewma_1 = perf->long_term.average;
+
+    return true;
+}
+
+bool
+performance_get_stats(const char *name, struct performance_stats *stats)
+{
+    bool found = false;
+
+    ovs_mutex_lock(&performances_lock);
+    found = performance_get_stats_protected(name, stats);
+    ovs_mutex_unlock(&performances_lock);
+
+    return found;
+}
+
 static void
 performance_print(struct performance *perf, const char *name,
                   struct ds *s)
diff --git a/lib/performance.h b/lib/performance.h
index f039689e8..09ca844b9 100644
--- a/lib/performance.h
+++ b/lib/performance.h
@@ -24,6 +24,16 @@ enum performance_units {
     PERF_NS,
 };
 
+struct performance_stats {
+    unsigned long long count;    /* Total number of samples. */
+    enum performance_units unit; /* Unit of following values. */
+    unsigned long long max;      /* Maximum value. */
+    unsigned long long min;      /* Minimum value. */
+    double pctl_95;              /* 95th percentile. */
+    double ewma_50;              /* Exponentially weighted moving average 
(alpha 0.50). */
+    double ewma_1;               /* Exponentially weighted moving average 
(alpha 0.01). */
+};
+
 /* Create a new performance measurement.
  * The "units" are not used for any calculations but are printed when
  * statistics are requested.
@@ -39,4 +49,7 @@ bool performance_start_sample(const char *name, unsigned long 
long ts);
  */
 bool performance_end_sample(const char *name, unsigned long long ts);
 
+/* Retrieve statistics calculated from collected samples */
+bool performance_get_stats(const char *name, struct performance_stats *stats);
+
 #endif /* performance.h */
-- 
2.14.3

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to