]>
git.proxmox.com Git - mirror_ovs.git/blob - lib/stopwatch.h
1 /* Copyright (c) 2017 Red Hat, Inc.
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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 enum stopwatch_units
{
27 struct stopwatch_stats
{
28 unsigned long long count
; /* Total number of samples. */
29 enum stopwatch_units unit
; /* Unit of following values. */
30 unsigned long long max
; /* Maximum value. */
31 unsigned long long min
; /* Minimum value. */
32 double pctl_95
; /* 95th percentile. */
33 double ewma_50
; /* Exponentially weighted moving average
35 double ewma_1
; /* Exponentially weighted moving average
39 /* Create a new stopwatch.
40 * The "units" are not used for any calculations but are printed when
41 * statistics are requested.
43 void stopwatch_create(const char *name
, enum stopwatch_units units
);
45 /* Start a stopwatch. */
46 void stopwatch_start(const char *name
, unsigned long long ts
);
48 /* Stop a stopwatch. The elapsed time will be used for updating statistics
51 void stopwatch_stop(const char *name
, unsigned long long ts
);
53 /* Retrieve statistics calculated from collected samples */
54 bool stopwatch_get_stats(const char *name
, struct stopwatch_stats
*stats
);
56 /* Block until all enqueued samples have been processed. */
57 void stopwatch_sync(void);
59 #endif /* stopwatch.h */