grpc
src
core
lib
iomgr
iomgr/time_averaged_stats.h
Go to the documentation of this file.
1
/*
2
*
3
* Copyright 2015 gRPC authors.
4
*
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
8
*
9
* http://www.apache.org/licenses/LICENSE-2.0
10
*
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
16
*
17
*/
18
19
#ifndef GRPC_CORE_LIB_IOMGR_TIME_AVERAGED_STATS_H
20
#define GRPC_CORE_LIB_IOMGR_TIME_AVERAGED_STATS_H
21
22
/* This tracks a time-decaying weighted average. It works by collecting
23
batches of samples and then mixing their average into a time-decaying
24
weighted mean. It is designed for batch operations where we do many adds
25
before updating the average. */
26
27
struct
grpc_time_averaged_stats
{
28
/* The initial average value. This is the reported average until the first
29
grpc_time_averaged_stats_update_average call. If a positive regress_weight
30
is used, we also regress towards this value on each update. */
31
double
init_avg
;
32
/* The sample weight of "init_avg" that is mixed in with each call to
33
grpc_time_averaged_stats_update_average. If the calls to
34
grpc_time_averaged_stats_add_sample stop, this will cause the average to
35
regress back to the mean. This should be non-negative. Set it to 0 to
36
disable the bias. A value of 1 has the effect of adding in 1 bonus sample
37
with value init_avg to each sample period. */
38
double
regress_weight
;
39
/* This determines the rate of decay of the time-averaging from one period
40
to the next by scaling the aggregate_total_weight of samples from prior
41
periods when combining with the latest period. It should be in the range
42
[0,1]. A higher value adapts more slowly. With a value of 0.5, if the
43
batches each have k samples, the samples_in_avg_ will grow to 2 k, so the
44
weighting of the time average will eventually be 1/3 new batch and 2/3
45
old average. */
46
double
persistence_factor
;
47
48
/* The total value of samples since the last UpdateAverage(). */
49
double
batch_total_value
;
50
/* The number of samples since the last UpdateAverage(). */
51
double
batch_num_samples
;
52
/* The time-decayed sum of batch_num_samples_ over previous batches. This is
53
the "weight" of the old aggregate_weighted_avg_ when updating the
54
average. */
55
double
aggregate_total_weight
;
56
/* A time-decayed average of the (batch_total_value_ / batch_num_samples_),
57
computed by decaying the samples_in_avg_ weight in the weighted average. */
58
double
aggregate_weighted_avg
;
59
};
60
/* See the comments on the members above for an explanation of init_avg,
61
regress_weight, and persistence_factor. */
62
void
grpc_time_averaged_stats_init
(
grpc_time_averaged_stats
*
stats
,
63
double
init_avg,
double
regress_weight,
64
double
persistence_factor);
65
/* Add a sample to the current batch. */
66
void
grpc_time_averaged_stats_add_sample
(
grpc_time_averaged_stats
*
stats
,
67
double
value
);
68
/* Complete a batch and compute the new estimate of the average sample
69
value. */
70
double
grpc_time_averaged_stats_update_average
(
grpc_time_averaged_stats
*
stats
);
71
72
#endif
/* GRPC_CORE_LIB_IOMGR_TIME_AVERAGED_STATS_H */
grpc_time_averaged_stats::batch_num_samples
double batch_num_samples
Definition:
iomgr/time_averaged_stats.h:51
grpc_time_averaged_stats_update_average
double grpc_time_averaged_stats_update_average(grpc_time_averaged_stats *stats)
Definition:
iomgr/time_averaged_stats.cc:41
grpc_time_averaged_stats::regress_weight
double regress_weight
Definition:
iomgr/time_averaged_stats.h:38
grpc_time_averaged_stats::init_avg
double init_avg
Definition:
iomgr/time_averaged_stats.h:31
grpc_time_averaged_stats
Definition:
iomgr/time_averaged_stats.h:27
grpc_time_averaged_stats::aggregate_total_weight
double aggregate_total_weight
Definition:
iomgr/time_averaged_stats.h:55
grpc_time_averaged_stats::batch_total_value
double batch_total_value
Definition:
iomgr/time_averaged_stats.h:49
gen_stats_data.stats
list stats
Definition:
gen_stats_data.py:58
value
const char * value
Definition:
hpack_parser_table.cc:165
grpc_time_averaged_stats_init
void grpc_time_averaged_stats_init(grpc_time_averaged_stats *stats, double init_avg, double regress_weight, double persistence_factor)
Definition:
iomgr/time_averaged_stats.cc:23
grpc_time_averaged_stats::aggregate_weighted_avg
double aggregate_weighted_avg
Definition:
iomgr/time_averaged_stats.h:58
grpc_time_averaged_stats::persistence_factor
double persistence_factor
Definition:
iomgr/time_averaged_stats.h:46
grpc_time_averaged_stats_add_sample
void grpc_time_averaged_stats_add_sample(grpc_time_averaged_stats *stats, double value)
Definition:
iomgr/time_averaged_stats.cc:35
grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:36