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