From 3f911250c6bf67fb35924f19c2ef1819e05329c3 Mon Sep 17 00:00:00 2001 From: Dan Jenkins Date: Thu, 8 Aug 2024 08:55:59 +0100 Subject: [PATCH] make it so we track all in and out data --- client/dataChannel.go | 21 ++++++++++++--------- cmd/iceperf/main.go | 2 +- stats/stats.go | 10 ++++++++++ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/client/dataChannel.go b/client/dataChannel.go index d925147..6982696 100644 --- a/client/dataChannel.go +++ b/client/dataChannel.go @@ -177,10 +177,11 @@ func (cp *ConnectionPair) createOfferer(config webrtc.Configuration) { dc.OnClose(func() { - dcBytesSentTotal, iceTransportSentBytesTotal, _ := getBytesSent(pc, dc) + dcBytesSentTotal, iceTransportSentBytesTotal, iceTransportReceivedBytesTotal, _ := getBytesSent(pc, dc) cp.stats.SetOffererDcBytesSentTotal(float64(dcBytesSentTotal)) cp.stats.SetOffererIceTransportBytesSentTotal(float64(iceTransportSentBytesTotal)) + cp.stats.SetOffererIceTransportBytesReceivedTotal(float64(iceTransportReceivedBytesTotal)) cp.LogOfferer.Info("Sent total", "dcSentBytesTotal", dcBytesSentTotal, "cpSentBytesTotal", iceTransportSentBytesTotal) @@ -252,7 +253,7 @@ func (cp *ConnectionPair) createAnswerer(config webrtc.Configuration) { cp.LogAnswerer.Info("Received first Packet", "latencyFirstPacketInMs", time.Since(cp.sentInitialMessageViaDC).Milliseconds()) hasReceivedData = true } - totalBytesReceivedTmp, _, ok := getBytesReceived(pc, dc) + totalBytesReceivedTmp, _, _, ok := getBytesReceived(pc, dc) if ok { totalBytesReceived = totalBytesReceivedTmp // cp.LogAnswerer.Info("Received Bytes So Far", "dcReceivedBytes", totalBytesReceivedTmp, @@ -266,10 +267,12 @@ func (cp *ConnectionPair) createAnswerer(config webrtc.Configuration) { dc.OnClose(func() { - dcBytesReceivedTotal, iceTransportBytesReceivedTotal, _ := getBytesReceived(pc, dc) + dcBytesReceivedTotal, iceTransportBytesReceivedTotal, iceTransportBytesSentTotal, _ := getBytesReceived(pc, dc) cp.stats.SetAnswererDcBytesReceivedTotal(float64(dcBytesReceivedTotal)) cp.stats.SetAnswererIceTransportBytesReceivedTotal(float64(iceTransportBytesReceivedTotal)) + cp.stats.SetAnswererIceTransportBytesSentTotal(float64(iceTransportBytesSentTotal)) + cp.LogAnswerer.Info("Received total", "dcReceivedBytesTotal", dcBytesReceivedTotal, "iceTransportReceivedBytesTotal", iceTransportBytesReceivedTotal) @@ -280,28 +283,28 @@ func (cp *ConnectionPair) createAnswerer(config webrtc.Configuration) { cp.AnswerPC = pc } -func getBytesReceived(pc *webrtc.PeerConnection, dc *webrtc.DataChannel) (uint64, uint64, bool) { +func getBytesReceived(pc *webrtc.PeerConnection, dc *webrtc.DataChannel) (uint64, uint64, uint64, bool) { stats := pc.GetStats() dcStats, ok := stats.GetDataChannelStats(dc) if !ok { - return 0, 0, ok + return 0, 0, 0, ok } iceTransportStats := stats["iceTransport"].(webrtc.TransportStats) - return dcStats.BytesReceived, iceTransportStats.BytesReceived, ok + return dcStats.BytesReceived, iceTransportStats.BytesReceived, iceTransportStats.BytesSent, ok } -func getBytesSent(pc *webrtc.PeerConnection, dc *webrtc.DataChannel) (uint64, uint64, bool) { +func getBytesSent(pc *webrtc.PeerConnection, dc *webrtc.DataChannel) (uint64, uint64, uint64, bool) { stats := pc.GetStats() dcStats, ok := stats.GetDataChannelStats(dc) if !ok { - return 0, 0, ok + return 0, 0, 0, ok } iceTransportStats := stats["iceTransport"].(webrtc.TransportStats) - return dcStats.BytesSent, iceTransportStats.BytesSent, ok + return dcStats.BytesSent, iceTransportStats.BytesSent, iceTransportStats.BytesReceived, ok } diff --git a/cmd/iceperf/main.go b/cmd/iceperf/main.go index 862c91f..dac3b5d 100644 --- a/cmd/iceperf/main.go +++ b/cmd/iceperf/main.go @@ -79,7 +79,7 @@ func runService(ctx *cli.Context) error { } lvl := new(slog.LevelVar) - lvl.Set(slog.LevelInfo) + lvl.Set(slog.LevelError) // Configure the logger diff --git a/stats/stats.go b/stats/stats.go index d597c9f..aff3657 100644 --- a/stats/stats.go +++ b/stats/stats.go @@ -14,8 +14,10 @@ type Stats struct { OffererTimeToReceiveCandidate float64 `json:"offererTimeToReceiveCandidate"` OffererDcBytesSentTotal float64 `json:"offererDcBytesSentTotal"` OffererIceTransportBytesSentTotal float64 `json:"offererIceTransportBytesSentTotal"` + OffererIceTransportBytesReceivedTotal float64 `json:"offererIceTransportBytesReceivedTotal"` AnswererDcBytesReceivedTotal float64 `json:"answererDcBytesReceivedTotal"` AnswererIceTransportBytesReceivedTotal float64 `json:"answererIceTransportBytesReceivedTotal"` + AnswererIceTransportBytesSentTotal float64 `json:"answererIceTransportBytesSentTotal"` LatencyFirstPacket float64 `json:"latencyFirstPacket"` Throughput map[int64]float64 `json:"throughput"` ThroughputMax float64 `json:"throughputMax"` @@ -82,6 +84,10 @@ func (s *Stats) SetOffererIceTransportBytesSentTotal(io float64) { s.OffererIceTransportBytesSentTotal = io } +func (s *Stats) SetOffererIceTransportBytesReceivedTotal(io float64) { + s.OffererIceTransportBytesReceivedTotal = io +} + func (s *Stats) SetAnswererDcBytesReceivedTotal(a float64) { s.AnswererDcBytesReceivedTotal = a } @@ -90,6 +96,10 @@ func (s *Stats) SetAnswererIceTransportBytesReceivedTotal(ia float64) { s.AnswererIceTransportBytesReceivedTotal = ia } +func (s *Stats) SetAnswererIceTransportBytesSentTotal(ia float64) { + s.AnswererIceTransportBytesSentTotal = ia +} + func (s *Stats) SetLatencyFirstPacket(l float64) { s.LatencyFirstPacket = l }