1 /* 2 * Copyright © 2015 Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 21 * IN THE SOFTWARE. 22 * 23 */ 24 25 #ifndef __IGT_STATS_H__ 26 #define __IGT_STATS_H__ 27 28 #include <stdint.h> 29 #include <stdbool.h> 30 #include <math.h> 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 /** 37 * igt_stats_t: 38 * @values_u64: An array containing pushed integer values 39 * @is_float: Whether @values_f or @values_u64 is valid 40 * @values_f: An array containing pushed float values 41 * @n_values: The number of pushed values 42 */ 43 typedef struct { 44 unsigned int n_values; 45 unsigned int is_float : 1; 46 union { 47 uint64_t *values_u64; 48 double *values_f; 49 }; 50 51 /*< private >*/ 52 unsigned int capacity; 53 unsigned int is_population : 1; 54 unsigned int mean_variance_valid : 1; 55 unsigned int sorted_array_valid : 1; 56 57 uint64_t min, max; 58 double range[2]; 59 double mean, variance; 60 61 union { 62 uint64_t *sorted_u64; 63 double *sorted_f; 64 }; 65 } igt_stats_t; 66 67 void igt_stats_init(igt_stats_t *stats); 68 void igt_stats_init_with_size(igt_stats_t *stats, unsigned int capacity); 69 void igt_stats_fini(igt_stats_t *stats); 70 bool igt_stats_is_population(igt_stats_t *stats); 71 void igt_stats_set_population(igt_stats_t *stats, bool full_population); 72 void igt_stats_push(igt_stats_t *stats, uint64_t value); 73 void igt_stats_push_float(igt_stats_t *stats, double value); 74 void igt_stats_push_array(igt_stats_t *stats, 75 const uint64_t *values, unsigned int n_values); 76 uint64_t igt_stats_get_min(igt_stats_t *stats); 77 uint64_t igt_stats_get_max(igt_stats_t *stats); 78 uint64_t igt_stats_get_range(igt_stats_t *stats); 79 void igt_stats_get_quartiles(igt_stats_t *stats, 80 double *q1, double *q2, double *q3); 81 double igt_stats_get_iqr(igt_stats_t *stats); 82 double igt_stats_get_iqm(igt_stats_t *stats); 83 double igt_stats_get_mean(igt_stats_t *stats); 84 double igt_stats_get_trimean(igt_stats_t *stats); 85 double igt_stats_get_median(igt_stats_t *stats); 86 double igt_stats_get_variance(igt_stats_t *stats); 87 double igt_stats_get_std_deviation(igt_stats_t *stats); 88 89 /** 90 * igt_mean: 91 * 92 * Structure to compute running statistical numbers. Needs to be initialized 93 * with igt_mean_init(). Read out data using igt_mean_get() and 94 * igt_mean_get_variance(). 95 */ 96 struct igt_mean { 97 /*< private >*/ 98 double mean, sq, min, max; 99 unsigned long count; 100 }; 101 102 void igt_mean_init(struct igt_mean *m); 103 void igt_mean_add(struct igt_mean *m, double v); 104 double igt_mean_get(struct igt_mean *m); 105 double igt_mean_get_variance(struct igt_mean *m); 106 107 #ifdef __cplusplus 108 } 109 #endif 110 111 #endif /* __IGT_STATS_H__ */ 112