blob: 5faeced4ccae336ace32f1fe2ed4f235fb37c358 [file] [log] [blame]
Damien Lespiau06f5f702015-06-25 12:07:56 +01001/*
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
Damien Lespiau087a8d12015-06-26 14:31:58 +010025#ifndef __IGT_STATS_H__
26#define __IGT_STATS_H__
27
Damien Lespiau06f5f702015-06-25 12:07:56 +010028#include <stdint.h>
Damien Lespiauda123ad2015-06-26 18:04:34 +010029#include <stdbool.h>
Chris Wilson6cd15fb2016-03-09 22:39:16 +000030#include <math.h>
Damien Lespiau06f5f702015-06-25 12:07:56 +010031
Damien Lespiaua2f6fd32015-06-26 16:57:55 +010032/**
33 * igt_stats_t:
Thomas Woodf0381d12015-09-07 09:26:01 +010034 * @values_u64: An array containing pushed integer values
Daniel Vetter47558042016-07-27 14:04:17 +020035 * @is_float: Whether @values_f or @values_u64 is valid
Thomas Woodf0381d12015-09-07 09:26:01 +010036 * @values_f: An array containing pushed float values
Damien Lespiaua2f6fd32015-06-26 16:57:55 +010037 * @n_values: The number of pushed values
38 */
Damien Lespiau06f5f702015-06-25 12:07:56 +010039typedef struct {
Daniel Vetter47558042016-07-27 14:04:17 +020040 unsigned int n_values;
41 unsigned int is_float : 1;
Chris Wilson8506cdc2015-07-19 15:01:42 +010042 union {
43 uint64_t *values_u64;
44 double *values_f;
45 };
Damien Lespiaua2f6fd32015-06-26 16:57:55 +010046
47 /*< private >*/
48 unsigned int capacity;
Damien Lespiau3a5cf842015-06-26 17:02:09 +010049 unsigned int is_population : 1;
Damien Lespiau05c10f92015-06-25 23:57:49 +010050 unsigned int mean_variance_valid : 1;
Damien Lespiau1b8997b2015-06-27 15:33:58 +010051 unsigned int sorted_array_valid : 1;
Chris Wilson8506cdc2015-07-19 15:01:42 +010052
Damien Lespiau4a89a842015-06-27 09:45:42 +010053 uint64_t min, max;
Chris Wilson8506cdc2015-07-19 15:01:42 +010054 double range[2];
Damien Lespiau05c10f92015-06-25 23:57:49 +010055 double mean, variance;
Chris Wilson8506cdc2015-07-19 15:01:42 +010056
57 union {
58 uint64_t *sorted_u64;
59 double *sorted_f;
60 };
Damien Lespiau06f5f702015-06-25 12:07:56 +010061} igt_stats_t;
62
Damien Lespiau66e0bf62015-06-27 17:49:40 +010063void igt_stats_init(igt_stats_t *stats);
64void igt_stats_init_with_size(igt_stats_t *stats, unsigned int capacity);
Damien Lespiau06f5f702015-06-25 12:07:56 +010065void igt_stats_fini(igt_stats_t *stats);
Damien Lespiauda123ad2015-06-26 18:04:34 +010066bool igt_stats_is_population(igt_stats_t *stats);
Damien Lespiau3a5cf842015-06-26 17:02:09 +010067void igt_stats_set_population(igt_stats_t *stats, bool full_population);
Damien Lespiau06f5f702015-06-25 12:07:56 +010068void igt_stats_push(igt_stats_t *stats, uint64_t value);
Chris Wilson8506cdc2015-07-19 15:01:42 +010069void igt_stats_push_float(igt_stats_t *stats, double value);
Damien Lespiau3839bac2015-06-27 15:32:23 +010070void igt_stats_push_array(igt_stats_t *stats,
71 const uint64_t *values, unsigned int n_values);
Damien Lespiau4a89a842015-06-27 09:45:42 +010072uint64_t igt_stats_get_min(igt_stats_t *stats);
73uint64_t igt_stats_get_max(igt_stats_t *stats);
Damien Lespiau0e4c1752015-06-27 11:12:01 +010074uint64_t igt_stats_get_range(igt_stats_t *stats);
Damien Lespiau1b8997b2015-06-27 15:33:58 +010075void igt_stats_get_quartiles(igt_stats_t *stats,
76 double *q1, double *q2, double *q3);
Damien Lespiaufabde382015-06-27 15:49:26 +010077double igt_stats_get_iqr(igt_stats_t *stats);
Chris Wilson19135a32015-07-01 13:50:02 +010078double igt_stats_get_iqm(igt_stats_t *stats);
Damien Lespiaue55a11d2015-06-25 23:44:20 +010079double igt_stats_get_mean(igt_stats_t *stats);
Chris Wilson2d305f62015-07-01 18:52:46 +010080double igt_stats_get_trimean(igt_stats_t *stats);
Damien Lespiau1b8997b2015-06-27 15:33:58 +010081double igt_stats_get_median(igt_stats_t *stats);
Damien Lespiau05c10f92015-06-25 23:57:49 +010082double igt_stats_get_variance(igt_stats_t *stats);
Damien Lespiau515cec12015-06-25 23:59:21 +010083double igt_stats_get_std_deviation(igt_stats_t *stats);
Damien Lespiau087a8d12015-06-26 14:31:58 +010084
Daniel Vetter47558042016-07-27 14:04:17 +020085/**
86 * igt_mean:
87 *
88 * Structure to compute running statistical numbers. Needs to be initialized
89 * with igt_mean_init(). Read out data using igt_mean_get() and
90 * igt_mean_get_variance().
91 */
Chris Wilson74761382016-03-08 14:10:56 +000092struct igt_mean {
Daniel Vetter47558042016-07-27 14:04:17 +020093 /*< private >*/
Chris Wilson6cd15fb2016-03-09 22:39:16 +000094 double mean, sq, min, max;
Chris Wilson74761382016-03-08 14:10:56 +000095 unsigned long count;
96};
97
Daniel Vetter47558042016-07-27 14:04:17 +020098void igt_mean_init(struct igt_mean *m);
99void igt_mean_add(struct igt_mean *m, double v);
100double igt_mean_get(struct igt_mean *m);
101double igt_mean_get_variance(struct igt_mean *m);
Chris Wilson74761382016-03-08 14:10:56 +0000102
Damien Lespiau087a8d12015-06-26 14:31:58 +0100103#endif /* __IGT_STATS_H__ */