]> git.proxmox.com Git - mirror_ovs.git/blame - lib/stopwatch.h
cirrus: Use FreeBSD 12.2.
[mirror_ovs.git] / lib / stopwatch.h
CommitLineData
aed45bef
MM
1/* Copyright (c) 2017 Red Hat, Inc.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef STOPWATCH_H
17#define STOPWATCH_H 1
18
19#include <stdbool.h>
20
21enum stopwatch_units {
22 SW_MS,
23 SW_US,
24 SW_NS,
25};
26
89189388
JS
27struct stopwatch_stats {
28 unsigned long long count; /* Total number of samples. */
463ec406 29 enum stopwatch_units unit; /* Unit of following values. */
89189388
JS
30 unsigned long long max; /* Maximum value. */
31 unsigned long long min; /* Minimum value. */
32 double pctl_95; /* 95th percentile. */
463ec406
JP
33 double ewma_50; /* Exponentially weighted moving average
34 (alpha 0.50). */
35 double ewma_1; /* Exponentially weighted moving average
36 (alpha 0.01). */
89189388
JS
37};
38
aed45bef
MM
39/* Create a new stopwatch.
40 * The "units" are not used for any calculations but are printed when
41 * statistics are requested.
42 */
43void stopwatch_create(const char *name, enum stopwatch_units units);
44
45/* Start a stopwatch. */
46void stopwatch_start(const char *name, unsigned long long ts);
47
48/* Stop a stopwatch. The elapsed time will be used for updating statistics
49 * for this stopwatch.
50 */
51void stopwatch_stop(const char *name, unsigned long long ts);
52
89189388
JS
53/* Retrieve statistics calculated from collected samples */
54bool stopwatch_get_stats(const char *name, struct stopwatch_stats *stats);
55
0e124db8
JS
56/* Block until all enqueued samples have been processed. */
57void stopwatch_sync(void);
58
aed45bef 59#endif /* stopwatch.h */