qemu/include/qemu/timed-average.h
<<
>>
Prefs
   1/*
   2 * QEMU timed average computation
   3 *
   4 * Copyright (C) Nodalink, EURL. 2014
   5 * Copyright (C) Igalia, S.L. 2015
   6 *
   7 * Authors:
   8 *   BenoƮt Canet <benoit.canet@nodalink.com>
   9 *   Alberto Garcia <berto@igalia.com>
  10 *
  11 * This program is free software: you can redistribute it and/or modify
  12 * it under the terms of the GNU General Public License as published by
  13 * the Free Software Foundation, either version 2 of the License, or
  14 * (at your option) version 3 or any later version.
  15 *
  16 * This program is distributed in the hope that it will be useful,
  17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19 * GNU General Public License for more details.
  20 *
  21 * You should have received a copy of the GNU General Public License
  22 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  23 */
  24
  25#ifndef TIMED_AVERAGE_H
  26#define TIMED_AVERAGE_H
  27
  28
  29#include "qemu/timer.h"
  30
  31typedef struct TimedAverageWindow TimedAverageWindow;
  32typedef struct TimedAverage TimedAverage;
  33
  34/* All fields of both structures are private */
  35
  36struct TimedAverageWindow {
  37    uint64_t      min;             /* minimum value accounted in the window */
  38    uint64_t      max;             /* maximum value accounted in the window */
  39    uint64_t      sum;             /* sum of all values */
  40    uint64_t      count;           /* number of values */
  41    int64_t       expiration;      /* the end of the current window in ns */
  42};
  43
  44struct TimedAverage {
  45    uint64_t           period;     /* period in nanoseconds */
  46    TimedAverageWindow windows[2]; /* two overlapping windows of with
  47                                    * an offset of period / 2 between them */
  48    unsigned           current;    /* the current window index: it's also the
  49                                    * oldest window index */
  50    QEMUClockType      clock_type; /* the clock used */
  51};
  52
  53void timed_average_init(TimedAverage *ta, QEMUClockType clock_type,
  54                        uint64_t period);
  55
  56void timed_average_account(TimedAverage *ta, uint64_t value);
  57
  58uint64_t timed_average_min(TimedAverage *ta);
  59uint64_t timed_average_avg(TimedAverage *ta);
  60uint64_t timed_average_max(TimedAverage *ta);
  61uint64_t timed_average_sum(TimedAverage *ta, uint64_t *elapsed);
  62
  63#endif
  64