diff options
author | Damien Lespiau <damien.lespiau@intel.com> | 2015-06-27 17:49:40 +0100 |
---|---|---|
committer | Damien Lespiau <damien.lespiau@intel.com> | 2015-06-27 19:05:41 +0100 |
commit | 66e0bf66da4b06d9495025b053d4d7fe73c86fc7 (patch) | |
tree | 3aade7289336c4766d2be7ce54617018999906c1 /lib/igt_stats.c | |
parent | 00432ff260beba0bf6535d7fd1c0275de303ed57 (diff) |
stats: Spwan igt_init_with_size() from igt_init()
It's all about good looking APIs.
Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
Diffstat (limited to 'lib/igt_stats.c')
-rw-r--r-- | lib/igt_stats.c | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/lib/igt_stats.c b/lib/igt_stats.c index 665f1c99..9032a685 100644 --- a/lib/igt_stats.c +++ b/lib/igt_stats.c @@ -97,15 +97,32 @@ static void igt_stats_ensure_capacity(igt_stats_t *stats, /** * igt_stats_init: * @stats: An #igt_stats_t instance + * + * Initializes an #igt_stats_t instance. igt_stats_fini() must be called once + * finished with @stats. + */ +void igt_stats_init(igt_stats_t *stats) +{ + memset(stats, 0, sizeof(*stats)); + + igt_stats_ensure_capacity(stats, 128); + + stats->min = U64_MAX; + stats->max = 0; +} + +/** + * igt_stats_init_with_size: + * @stats: An #igt_stats_t instance * @capacity: Number of data samples @stats can contain * - * Initializes an #igt_stats_t instance to hold @capacity samples. - * igt_stats_fini() must be called once finished with @stats. + * Like igt_stats_init() but with a size to avoid reallocating the underlying + * array(s) when pushing new values. Useful if we have a good idea of the + * number of data points we want @stats to hold. * - * We currently assume the user knows how many data samples upfront and there's - * no need to grow the array of values. + * igt_stats_fini() must be called once finished with @stats. */ -void igt_stats_init(igt_stats_t *stats, unsigned int capacity) +void igt_stats_init_with_size(igt_stats_t *stats, unsigned int capacity) { memset(stats, 0, sizeof(*stats)); |