Methods for copy and combine stats structs is needed for PM Signed-off-by: Anders Selhammer <anders.selham...@est.tech> --- stats.c | 19 +++++++++++++++++++ stats.h | 14 ++++++++++++++ 2 files changed, 33 insertions(+)
diff --git a/stats.c b/stats.c index 41136f0..1ec88d5 100644 --- a/stats.c +++ b/stats.c @@ -59,6 +59,25 @@ void stats_add_value(struct stats *stats, double value) stats->sum_diff_sqr += (value - old_mean) * (value - stats->mean); } +void stats_copy(struct stats *to, struct stats *from) +{ + memcpy(to, from, sizeof(*to)); +} + +void stats_combine(struct stats *to, struct stats *from) +{ + if (!from->num) { + return; + } + to->min = (to->num && to->min < from->min) ? to->min : from->min; + to->max = (to->num && to->max > from->max) ? to->max : from->max; + to->mean = (to->mean * to->num + from->mean * from->num) / + (to->num + from->num); + to->num += from->num; + to->sum_sqr += from->sum_sqr; + to->sum_diff_sqr += from->sum_diff_sqr; +} + unsigned int stats_get_num_values(struct stats *stats) { return stats->num; diff --git a/stats.h b/stats.h index 541a376..6e09f7b 100644 --- a/stats.h +++ b/stats.h @@ -43,6 +43,20 @@ void stats_destroy(struct stats *stats); void stats_add_value(struct stats *stats, double value); /** + * Copy from one stats struct to another. + * @param to Pointer to stats obtained via @ref stats_create(). + * @param from Pointer to stats obtained via @ref stats_create(). + */ +void stats_copy(struct stats *to, struct stats *from); + +/** + * Combine from one stats struct into another. + * @param to Pointer to stats obtained via @ref stats_create(). + * @param from Pointer to stats obtained via @ref stats_create(). + */ +void stats_combine(struct stats *to, struct stats *from); + +/** * Get the number of values collected in the stats so far. * @param stats Pointer to stats obtained via @ref stats_create(). * @return The number of values. -- 1.8.3.1 ------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel