Motr  M0
stats_u.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2012-2020 Seagate Technology LLC and/or its Affiliates
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  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 
23 #include <math.h> /* sqrt */
24 #include "lib/types.h" /* UINT64_MAX */
25 #include "lib/assert.h" /* M0_PRE */
26 
27 #include "net/test/stats.h"
28 
38 static double double_get(const struct m0_uint128 *v128)
39 {
40  return v128->u_lo * 1. + v128->u_hi * ((double)UINT64_MAX + 1.);
41 }
42 
44 {
46 
47  return double_get(&stats->nts_sum);
48 }
49 
51 {
52  double sum;
53 
55 
56  sum = double_get(&stats->nts_sum);
57  return stats->nts_count == 0 ? 0. : sum / stats->nts_count;
58 }
59 
61 {
62  double mean;
63  double stddev;
64  double N;
65  double sum_sqr;
66 
68 
69  if (stats->nts_count == 0 || stats->nts_count == 1)
70  return 0.;
71 
73  N = stats->nts_count;
74  sum_sqr = double_get(&stats->nts_sum_sqr);
75  stddev = (sum_sqr - N * mean * mean) / (N - 1.);
76  stddev = stddev < 0. ? 0. : stddev;
77  stddev = sqrt(stddev);
78  return stddev;
79 }
80 
82 {
83  uint64_t seconds;
84  uint64_t nanoseconds;
85 
86  seconds = (uint64_t) floor(value / M0_TIME_ONE_SECOND);
87  nanoseconds = (uint64_t) (value - seconds * M0_TIME_ONE_SECOND);
88  return m0_time(seconds, nanoseconds);
89 }
90 
92 {
94 }
95 
97 {
99 }
100 
102 {
104 }
105 
110 /*
111  * Local variables:
112  * c-indentation-style: "K&R"
113  * c-basic-offset: 8
114  * tab-width: 8
115  * fill-column: 79
116  * scroll-step: 1
117  * End:
118  */
#define M0_PRE(cond)
static m0_time_t double2m0_time_t(double value)
Definition: stats_u.c:81
uint64_t m0_time_t
Definition: time.h:37
int const char const void * value
Definition: dir.c:325
static double double_get(const struct m0_uint128 *v128)
Definition: stats_u.c:38
static int sum
Definition: rwlock.c:53
double m0_net_test_stats_avg(const struct m0_net_test_stats *stats)
Definition: stats_u.c:50
double m0_net_test_stats_sum(const struct m0_net_test_stats *stats)
Definition: stats_u.c:43
#define N(i)
m0_time_t m0_time(uint64_t secs, long ns)
Definition: time.c:41
m0_time_t m0_net_test_stats_time_stddev(struct m0_net_test_stats *stats)
Definition: stats_u.c:101
m0_time_t m0_net_test_stats_time_avg(struct m0_net_test_stats *stats)
Definition: stats_u.c:96
uint64_t u_hi
Definition: types.h:36
#define UINT64_MAX
Definition: types.h:44
m0_time_t m0_net_test_stats_time_sum(struct m0_net_test_stats *stats)
Definition: stats_u.c:91
Definition: beck.c:130
bool m0_net_test_stats_invariant(const struct m0_net_test_stats *stats)
Definition: stats.c:52
uint64_t u_lo
Definition: types.h:37
double m0_net_test_stats_stddev(const struct m0_net_test_stats *stats)
Definition: stats_u.c:60