iomgr/time_averaged_stats.cc
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 
20 
22 
24  double init_avg, double regress_weight,
25  double persistence_factor) {
26  stats->init_avg = init_avg;
27  stats->regress_weight = regress_weight;
28  stats->persistence_factor = persistence_factor;
29  stats->batch_total_value = 0;
30  stats->batch_num_samples = 0;
31  stats->aggregate_total_weight = 0;
32  stats->aggregate_weighted_avg = init_avg;
33 }
34 
36  double value) {
37  stats->batch_total_value += value;
38  ++stats->batch_num_samples;
39 }
40 
43  /* Start with the current batch: */
44  double weighted_sum = stats->batch_total_value;
45  double total_weight = stats->batch_num_samples;
46  if (stats->regress_weight > 0) {
47  /* Add in the regression towards init_avg_: */
48  weighted_sum += stats->regress_weight * stats->init_avg;
49  total_weight += stats->regress_weight;
50  }
51  if (stats->persistence_factor > 0) {
52  /* Add in the persistence: */
53  const double prev_sample_weight =
54  stats->persistence_factor * stats->aggregate_total_weight;
55  weighted_sum += prev_sample_weight * stats->aggregate_weighted_avg;
56  total_weight += prev_sample_weight;
57  }
58  stats->aggregate_weighted_avg =
59  (total_weight > 0) ? (weighted_sum / total_weight) : stats->init_avg;
60  stats->aggregate_total_weight = total_weight;
61  stats->batch_num_samples = 0;
62  stats->batch_total_value = 0;
63  return stats->aggregate_weighted_avg;
64 }
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
Definition: iomgr/time_averaged_stats.h:27
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
gen_stats_data.stats
list stats
Definition: gen_stats_data.py:58
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
value
const char * value
Definition: hpack_parser_table.cc:165
time_averaged_stats.h
port_platform.h


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:36