Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Network.h
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Framework_SystemPerformance_Instruments_Network_h_
5#define _Stroika_Framework_SystemPerformance_Instruments_Network_h_ 1
6
7#include "Stroika/Frameworks/StroikaPreComp.h"
8
9#include <optional>
10
11#include "Stroika/Foundation/Containers/Collection.h"
12#include "Stroika/Foundation/Containers/Set.h"
13#include "Stroika/Foundation/DataExchange/ObjectVariantMapper.h"
15
16#include "Stroika/Frameworks/SystemPerformance/Instrument.h"
17
18/*
19 * \file
20 *
21 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
22 *
23 * TODO:
24 * @todo http://stroika-bugs.sophists.com/browse/STK-479 - Add (elaborated) TCPStats - like we have in Process TCPStats
25 */
26
27namespace Stroika::Frameworks::SystemPerformance::Instruments::Network {
28
29 using Containers::Collection;
30 using DataExchange::ObjectVariantMapper;
31
32 /**
33 * Note that the total values are 'total ever' while the OS has been running, and the rate values are
34 * averaged over the collection interval.
35 */
36 struct IOStatistics {
37 /**
38 * bytes
39 * The total number of bytes of data transmitted or received by the interface.
40 */
41 optional<uint64_t> fTotalBytesSent;
42 optional<uint64_t> fTotalBytesReceived;
43
44 /**
45 * @todo TBD
46 */
47 optional<double> fBytesPerSecondSent;
48 optional<double> fBytesPerSecondReceived;
49
50 /**
51 * @todo TBD
52 */
53 optional<uint64_t> fTotalTCPSegments;
54 optional<double> fTCPSegmentsPerSecond;
55
56 /**
57 * @todo TBD
58 */
60 optional<double> fTCPRetransmittedSegmentsPerSecond;
61
62 /**
63 * packets
64 * The total number of packets of data transmitted or received by the interface.
65 */
66 optional<uint64_t> fTotalPacketsSent;
67 optional<uint64_t> fTotalPacketsReceived;
68
69 /**
70 * @todo TBD
71 */
72 optional<double> fPacketsPerSecondSent;
73 optional<double> fPacketsPerSecondReceived;
74
75 /**
76 * errs
77 * The total number of transmit or receive errors detected by the device driver.
78 */
79 optional<uint64_t> fTotalErrors;
80
81 /**
82 * drop
83 * The total number of packets dropped by the device driver.
84 */
85 optional<uint64_t> fTotalPacketsDropped;
86
87 /**
88 * Utility to accomulate statistics. This simply sums each member, and if one side or the other was missing, it starts at zero.
89 * If both sides missing, the result stays missing.
90 */
91 nonvirtual IOStatistics& operator+= (const IOStatistics& rhs);
92
93 /**
94 * @see Characters::ToString ();
95 */
96 nonvirtual String ToString () const;
97 };
98
99 /**
100 */
101 struct InterfaceInfo {
102
103 /**
104 */
105 using Interface = Foundation::IO::Network::Interface;
106
107 /**
108 * This sub-object contains most of the configuration information about the interface.
109 *
110 * @todo replace most of whats below
111 */
112 Interface fInterface;
113
114 /**
115 * Per interface I/O transfer statistics.
116 */
117 IOStatistics fIOStatistics;
118
119 /**
120 * @see Characters::ToString ();
121 */
122 nonvirtual String ToString () const;
123 };
124
125 /**
126 * A single captured network status measurement.
127 */
128 struct Info {
129 optional<Collection<InterfaceInfo>> fInterfaces;
130
131 /**
132 * Conceptually fSummaryIOStatistics is just the sum of the stats for each fInterfaces member, but
133 * it maybe fetched via a different OS API, and may differ.
134 */
135 optional<IOStatistics> fSummaryIOStatistics;
136
137 /**
138 * @see Characters::ToString ();
139 */
140 nonvirtual String ToString () const;
141 };
142
143 /**
144 * To control the behavior of the instrument.
145 *
146 * @todo add option controlling if we return details and if we return summary
147 */
148 struct Options {
149 /**
150 * To compute averages, the instrument may keep around some earlier snapshots of data. This time interval is regulated by how often
151 * the capture is called (typically the Captureset::'run interval'. However, this value can be used to override that partly, and provide
152 * a minimum time for averaging.
153 *
154 * If you call capture more frequently than this interval, some (averaged) items maybe missing from the result.
155 *
156 * \pre fMinimumAveragingInterval > 0
157 */
159 };
160
161 /**
162 * This class is designed to be object-sliced into just the SystemPerformance::Instrument
163 *
164 * \note Constructing the instrument does no capturing (so sb quick/cheap) - capturing starts when you
165 * first call i.Capture()
166 */
168 public:
169 Instrument (const Options& options = Options{});
170
171 public:
172 /**
173 * For Instruments::Network::Info, etc types.
174 */
176 };
177
178}
179
180namespace Stroika::Frameworks::SystemPerformance {
181
182 /*
183 * Specialization to improve performance
184 */
185 template <>
187
188}
189
190/*
191 ********************************************************************************
192 ***************************** Implementation Details ***************************
193 ********************************************************************************
194 */
195
196#endif /*_Stroika_Framework_SystemPerformance_Instruments_Network_h_*/
chrono::duration< double > DurationSeconds
chrono::duration<double> - a time span (length of time) measured in seconds, but high precision.
Definition Realtime.h:57
String is like std::u32string, except it is much easier to use, often much more space efficient,...
Definition String.h:201
ObjectVariantMapper can be used to map C++ types to and from variant-union types, which can be transp...
An Instrument is a stateful object from which you can Capture () a series of measurements about a sys...
Definition Instrument.h:69
nonvirtual T CaptureOneMeasurement(Range< TimePointSeconds > *measurementTimeOut=nullptr)
nonvirtual IOStatistics & operator+=(const IOStatistics &rhs)
Definition Network.cpp:95