xref: /aosp_15_r20/external/federated-compute/fcp/client/stats.h (revision 14675a029014e728ec732f129a32e299b2da0601)
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef FCP_CLIENT_STATS_H_
17 #define FCP_CLIENT_STATS_H_
18 
19 #include <cstdint>
20 
21 #include "absl/time/time.h"
22 
23 namespace fcp {
24 namespace client {
25 
26 struct NetworkStats {
27   // The estimated number of bytes downloaded from the network ("over the
28   // wire").
29   int64_t bytes_downloaded = 0;
30   // The estimated number of bytes uploaded to the network ("over the
31   // wire").
32   int64_t bytes_uploaded = 0;
33   // The best estimate of the duration of wall clock time spent waiting for
34   // network requests to finish (but, for example, excluding any idle time spent
35   // waiting between issuing polling requests).
36   absl::Duration network_duration = absl::ZeroDuration();
37 
38   // Returns the difference between two sets of network stats.
39   NetworkStats operator-(const NetworkStats& other) const {
40     return {.bytes_downloaded = bytes_downloaded - other.bytes_downloaded,
41             .bytes_uploaded = bytes_uploaded - other.bytes_uploaded,
42             .network_duration = network_duration - other.network_duration};
43   }
44 
45   NetworkStats operator+(const NetworkStats& other) const {
46     return {.bytes_downloaded = bytes_downloaded + other.bytes_downloaded,
47             .bytes_uploaded = bytes_uploaded + other.bytes_uploaded,
48             .network_duration = network_duration + other.network_duration};
49   }
50 };
51 
52 inline bool operator==(const NetworkStats& s1, const NetworkStats& s2) {
53   return
54 
55       s1.bytes_downloaded == s2.bytes_downloaded &&
56       s1.bytes_uploaded == s2.bytes_uploaded &&
57       s1.network_duration == s2.network_duration;
58 }
59 
60 struct ExampleStats {
61   int example_count = 0;
62   int64_t example_size_bytes = 0;
63 };
64 
65 inline bool operator==(const ExampleStats& s1, const ExampleStats& s2) {
66   return s1.example_count == s2.example_count &&
67          s1.example_size_bytes == s2.example_size_bytes;
68 }
69 
70 }  // namespace client
71 }  // namespace fcp
72 
73 #endif  // FCP_CLIENT_STATS_H_
74