Overte C++ Documentation
ConnectionStats.h
1 //
2 // ConnectionStats.h
3 // libraries/networking/src/udt
4 //
5 // Created by Clement on 7/29/15.
6 // Copyright 2015 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_ConnectionStats_h
13 #define hifi_ConnectionStats_h
14 
15 #include <chrono>
16 #include <array>
17 #include <stdint.h>
18 
19 namespace udt {
20 
21 class ConnectionStats {
22 public:
23  struct Stats {
24  enum Event {
25  SentACK,
26  ReceivedACK,
27  ProcessedACK,
28 
29  NumEvents
30  };
31 
32  using microseconds = std::chrono::microseconds;
33  using Events = std::array<int, NumEvents>;
34 
35  microseconds startTime;
36  microseconds endTime;
37 
38  // construct a vector for the events of the size of our Enum - default value is zero
39  Events events;
40 
41  // packet counts and sizes
42  uint32_t sentPackets { 0 };
43  uint32_t receivedPackets { 0 };
44  uint32_t retransmittedPackets { 0 };
45  uint32_t duplicatePackets { 0 };
46 
47  uint64_t sentUtilBytes { 0 };
48  uint64_t receivedUtilBytes { 0 };
49  uint64_t retransmittedUtilBytes { 0 };
50  uint64_t duplicateUtilBytes { 0 };
51 
52  uint64_t sentBytes { 0 };
53  uint64_t receivedBytes { 0 };
54  uint64_t retransmittedBytes { 0 };
55  uint64_t duplicateBytes { 0 };
56 
57  uint32_t sentUnreliablePackets { 0 };
58  uint32_t receivedUnreliablePackets { 0 };
59  uint64_t sentUnreliableUtilBytes { 0 };
60  uint64_t receivedUnreliableUtilBytes { 0 };
61  uint64_t sentUnreliableBytes { 0 };
62  uint64_t receivedUnreliableBytes { 0 };
63 
64  // the following stats are trailing averages in the result, not totals
65  int sendRate { 0 };
66  int receiveRate { 0 };
67  int estimatedBandwith { 0 };
68  int rtt { 0 };
69  int congestionWindowSize { 0 };
70  int packetSendPeriod { 0 };
71 
72  // TODO: Remove once Win build supports brace initialization: `Events events {{ 0 }};`
73  Stats() { events.fill(0); }
74  };
75 
76  ConnectionStats();
77 
78  Stats sample();
79 
80  void record(Stats::Event event);
81 
82  void recordSentACK(int size);
83  void recordReceivedACK(int size);
84 
85  void recordSentPackets(int payload, int total);
86  void recordReceivedPackets(int payload, int total);
87 
88  void recordRetransmittedPackets(int payload, int total);
89  void recordDuplicatePackets(int payload, int total);
90 
91  void recordUnreliableSentPackets(int payload, int total);
92  void recordUnreliableReceivedPackets(int payload, int total);
93 
94  void recordCongestionWindowSize(int sample);
95  void recordPacketSendPeriod(int sample);
96 
97 private:
98  Stats _currentSample;
99 };
100 
101 }
102 
103 class QDebug;
104 QDebug& operator<<(QDebug&& debug, const udt::ConnectionStats::Stats& stats);
105 
106 #endif // hifi_ConnectionStats_h