Skip to content

Commit

Permalink
Fixed stats copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonito committed Apr 8, 2019
1 parent eb3f63d commit b9af48c
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 21 deletions.
9 changes: 5 additions & 4 deletions internal/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type CompletionHandler func()
// Session contains common elements to perform send/receive
type Session struct {
Done chan struct{}
NetworkStats stats.Stats
NetworkStats *stats.Stats
sdpInput io.Reader
sdpOutput io.Writer
peerConnection *webrtc.PeerConnection
Expand All @@ -32,9 +32,10 @@ func New(sdpInput io.Reader, sdpOutput io.Writer) Session {
sdpOutput = os.Stdout
}
return Session{
sdpInput: sdpInput,
sdpOutput: sdpOutput,
Done: make(chan struct{}),
sdpInput: sdpInput,
sdpOutput: sdpOutput,
Done: make(chan struct{}),
NetworkStats: stats.New(),
}
}

Expand Down
10 changes: 6 additions & 4 deletions pkg/session/bench/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ type Session struct {
testDurationError time.Duration

startPhase2 chan struct{}
uploadNetworkStats stats.Stats
uploadNetworkStats *stats.Stats
downloadDone chan bool
downloadNetworkStats stats.Stats
downloadNetworkStats *stats.Stats
}

// New creates a new sender session
Expand All @@ -42,8 +42,10 @@ func new(s internalSess.Session, isMaster bool) *Session {
testDuration: testDurationDefault,
testDurationError: testDurationErrorDefault,

startPhase2: make(chan struct{}),
downloadDone: make(chan bool),
startPhase2: make(chan struct{}),
downloadDone: make(chan bool),
uploadNetworkStats: stats.New(),
downloadNetworkStats: stats.New(),
}
}

Expand Down
17 changes: 9 additions & 8 deletions pkg/session/sender/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,20 @@ type Session struct {
doneCheck bool

// Stats/infos
readingStats stats.Stats
readingStats *stats.Stats
}

// New creates a new sender session
func new(s internalSess.Session, f io.Reader) *Session {
return &Session{
sess: s,
stream: f,
initialized: false,
dataBuff: make([]byte, senderBuffSize),
stopSending: make(chan struct{}, 1),
output: make(chan outputMsg, senderBuffSize*10),
doneCheck: false,
sess: s,
stream: f,
initialized: false,
dataBuff: make([]byte, senderBuffSize),
stopSending: make(chan struct{}, 1),
output: make(chan outputMsg, senderBuffSize*10),
doneCheck: false,
readingStats: stats.New(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/stats/bytes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func Test_Bytes(t *testing.T) {
},
}

s := Stats{}
s := New()
for _, cur := range tests {
assert.Equal(cur.before, s.Bytes())
s.AddBytes(cur.add)
Expand Down
2 changes: 1 addition & 1 deletion pkg/stats/ctrl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func Test_ControlFlow(t *testing.T) {
assert := assert.New(t)
s := Stats{}
s := New()

// Everything should be 0 at the beginning
assert.Equal(true, s.timeStart.IsZero())
Expand Down
4 changes: 2 additions & 2 deletions pkg/stats/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func Test_Bandwidth(t *testing.T) {
assert := assert.New(t)
s := Stats{}
s := New()

now := time.Now()
tests := []struct {
Expand Down Expand Up @@ -66,7 +66,7 @@ func Test_Bandwidth(t *testing.T) {

func Test_Duration(t *testing.T) {
assert := assert.New(t)
s := Stats{}
s := New()

// Should be 0
assert.Equal(time.Duration(0), s.Duration())
Expand Down
9 changes: 8 additions & 1 deletion pkg/stats/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

// Stats provide a way to track statistics infos
type Stats struct {
lock sync.RWMutex
lock *sync.RWMutex
nbBytes uint64
timeStart time.Time
timeStop time.Time
Expand All @@ -17,6 +17,13 @@ type Stats struct {
timePaused time.Duration
}

// New creates a new Stats
func New() *Stats {
return &Stats{
lock: &sync.RWMutex{},
}
}

func (s *Stats) String() string {
s.lock.RLock()
defer s.lock.RUnlock()
Expand Down

0 comments on commit b9af48c

Please sign in to comment.