Skip to content

Commit

Permalink
make it so we track all in and out data
Browse files Browse the repository at this point in the history
  • Loading branch information
danjenkins committed Aug 8, 2024
1 parent 350cf2a commit 3f91125
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
21 changes: 12 additions & 9 deletions client/dataChannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion cmd/iceperf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit 3f91125

Please sign in to comment.