Add infrastructure stats for network emulation layer

Bug: b/240540204
Change-Id: I66dfd25775faa9d1bc7e75a932a36e8aa97c0f57
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/282320
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#38613}
This commit is contained in:
Artem Titov
2022-11-11 23:14:30 +01:00
committed by WebRTC LUCI CQ
parent 6b0aea07ab
commit b41568b6fd
14 changed files with 350 additions and 164 deletions

View File

@ -18,8 +18,10 @@
namespace webrtc {
std::unique_ptr<NetworkEmulationManager> CreateNetworkEmulationManager(
TimeMode mode) {
return std::make_unique<test::NetworkEmulationManagerImpl>(mode);
TimeMode time_mode,
EmulatedNetworkStatsGatheringMode stats_gathering_mode) {
return std::make_unique<test::NetworkEmulationManagerImpl>(
time_mode, stats_gathering_mode);
}
} // namespace webrtc

View File

@ -19,7 +19,9 @@ namespace webrtc {
// Returns a non-null NetworkEmulationManager instance.
std::unique_ptr<NetworkEmulationManager> CreateNetworkEmulationManager(
TimeMode mode = TimeMode::kRealTime);
TimeMode time_mode = TimeMode::kRealTime,
EmulatedNetworkStatsGatheringMode stats_gathering_mode =
EmulatedNetworkStatsGatheringMode::kDefault);
} // namespace webrtc

View File

@ -67,8 +67,8 @@ struct EmulatedNetworkOutgoingStats {
DataSize bytes_sent = DataSize::Zero();
// Sizes of all sent packets if EmulatedEndpointConfig::stats_gatherming_mode
// was set to StatsGatheringMode::kDebug; empty otherwise.
// Sizes of all sent packets.
// Collected iff EmulatedNetworkStatsGatheringMode::kDebug is enabled.
SamplesStatsCounter sent_packets_size;
DataSize first_sent_packet_size = DataSize::Zero();
@ -90,9 +90,8 @@ struct EmulatedNetworkIncomingStats {
// Total amount of bytes in received packets.
DataSize bytes_received = DataSize::Zero();
// Sizes of all received packets if
// EmulatedEndpointConfig::stats_gatherming_mode was set to
// StatsGatheringMode::kDebug; empty otherwise.
// Sizes of all received packets.
// Collected iff EmulatedNetworkStatsGatheringMode::kDebug is enabled.
SamplesStatsCounter received_packets_size;
// Total amount of packets that were received, but no destination was found.
@ -101,9 +100,8 @@ struct EmulatedNetworkIncomingStats {
// Total amount of bytes in discarded packets.
DataSize bytes_discarded_no_receiver = DataSize::Zero();
// Sizes of all packets that were received, but no destination was found if
// EmulatedEndpointConfig::stats_gatherming_mode was set to
// StatsGatheringMode::kDebug; empty otherwise.
// Sizes of all packets that were received, but no destination was found.
// Collected iff EmulatedNetworkStatsGatheringMode::kDebug is enabled.
SamplesStatsCounter packets_discarded_no_receiver_size;
DataSize first_received_packet_size = DataSize::Zero();
@ -124,10 +122,9 @@ struct EmulatedNetworkStats {
DataSize BytesSent() const { return overall_outgoing_stats.bytes_sent; }
// Returns the timestamped sizes of all sent packets if
// EmulatedEndpointConfig::stats_gatherming_mode was set to
// StatsGatheringMode::kDebug; otherwise, the returned value will be empty.
// Returns the timestamped sizes of all sent packets.
// Returned reference is valid until the next call to a non-const method.
// Collected iff EmulatedNetworkStatsGatheringMode::kDebug is enabled.
const SamplesStatsCounter& SentPacketsSizeCounter() const {
return overall_outgoing_stats.sent_packets_size;
}
@ -162,10 +159,9 @@ struct EmulatedNetworkStats {
return overall_incoming_stats.bytes_received;
}
// Returns the timestamped sizes of all received packets if
// EmulatedEndpointConfig::stats_gatherming_mode was set to
// StatsGatheringMode::kDebug; otherwise, the returned value will be empty.
// Returns the timestamped sizes of all received packets.
// Returned reference is valid until the next call to a non-const method.
// Collected iff EmulatedNetworkStatsGatheringMode::kDebug is enabled.
const SamplesStatsCounter& ReceivedPacketsSizeCounter() const {
return overall_incoming_stats.received_packets_size;
}
@ -181,10 +177,9 @@ struct EmulatedNetworkStats {
}
// Returns counter with timestamped sizes of all packets that were received,
// but no destination was found if
// EmulatedEndpointConfig::stats_gatherming_mode was set to
// StatsGatheringMode::kDebug; otherwise, the returned value will be empty.
// but no destination was found.
// Returned reference is valid until the next call to a non-const method.
// Collected iff EmulatedNetworkStatsGatheringMode::kDebug is enabled.
const SamplesStatsCounter& PacketsDiscardedNoReceiverSizeCounter() const {
return overall_incoming_stats.packets_discarded_no_receiver_size;
}
@ -226,12 +221,25 @@ struct EmulatedNetworkStats {
incoming_stats_per_source;
// Duration between packet was received on network interface and was
// dispatched to the network in microseconds if
// EmulatedEndpointConfig::stats_gatherming_mode was set to
// StatsGatheringMode::kDebug; empty otherwise.
// dispatched to the network in microseconds.
// Collected iff EmulatedNetworkStatsGatheringMode::kDebug is enabled.
SamplesStatsCounter sent_packets_queue_wait_time_us;
};
struct EmulatedNetworkNodeStats {
// Amount of time each packet spent in the emulated network node for which
// stats were collected.
//
// Collected iff EmulatedNetworkStatsGatheringMode::kDebug is enabled.
SamplesStatsCounter packet_transport_time;
// For each packet contains its size divided on the amount of time which it
// spent in the emulated network node for which stats were collected.
//
// Collected iff EmulatedNetworkStatsGatheringMode::kDebug is enabled.
SamplesStatsCounter size_to_packet_transport_time;
};
// EmulatedEndpoint is an abstraction for network interface on device. Instances
// of this are created by NetworkEmulationManager::CreateEndpoint and
// thread safe.

View File

@ -49,15 +49,18 @@ class EmulatedNetworkNode;
// peer device to another network interface on another peer device.
class EmulatedRoute;
enum class EmulatedNetworkStatsGatheringMode {
// Gather main network stats counters. See more details on which particular
// metrics are collected in the `EmulatedNetworkStats` and
// `EmulatedNetworkNodeStats` documentation.
kDefault,
// kDefault + also gather per packet statistics. In this mode more memory
// will be used.
kDebug
};
struct EmulatedEndpointConfig {
enum class IpAddressFamily { kIpv4, kIpv6 };
enum class StatsGatheringMode {
// Gather main network stats counters.
kDefault,
// kDefault + also gather per packet statistics. In this mode more memory
// will be used.
kDebug
};
// If specified will be used to name endpoint for logging purposes.
absl::optional<std::string> name = absl::nullopt;
@ -70,7 +73,6 @@ struct EmulatedEndpointConfig {
bool start_as_enabled = true;
// Network type which will be used to represent endpoint to WebRTC.
rtc::AdapterType type = rtc::AdapterType::ADAPTER_TYPE_UNKNOWN;
StatsGatheringMode stats_gathering_mode = StatsGatheringMode::kDefault;
// Allow endpoint to send packets specifying source IP address different to
// the current endpoint IP address. If false endpoint will crash if attempt
// to send such packet will be done.
@ -327,7 +329,7 @@ class NetworkEmulationManager {
CreateEmulatedNetworkManagerInterface(
const std::vector<EmulatedEndpoint*>& endpoints) = 0;
// Passes summarized network stats for specified `endpoints` into specified
// Passes combined network stats for all specified `endpoints` into specified
// `stats_callback`. Callback will be executed on network emulation
// internal task queue.
// Deprecated.
@ -339,6 +341,13 @@ class NetworkEmulationManager {
rtc::ArrayView<EmulatedEndpoint* const> endpoints,
std::function<void(EmulatedNetworkStats)> stats_callback) = 0;
// Passes combined network stats for all specified `nodes` into specified
// `stats_callback`. Callback will be executed on network emulation
// internal task queue.
virtual void GetStats(
rtc::ArrayView<EmulatedNetworkNode* const> nodes,
std::function<void(EmulatedNetworkNodeStats)> stats_callback) = 0;
// Create a EmulatedTURNServer.
// The TURN server has 2 endpoints that need to be connected with routes,
// - GetClientEndpoint() - the endpoint that accepts TURN allocations.