Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ test-386:
GOARCH=386 GOMAXPROCS=4 go test
GOARCH=386 GOMAXPROCS=8 go test

test-arm:
GOARCH=arm GOARM=6 GOMAXPROCS=1 go test
GOARCH=arm GOARM=6 GOMAXPROCS=2 go test
GOARCH=arm GOARM=6 GOMAXPROCS=4 go test

bench-1-goprocs:
GOMAXPROCS=1 go test -test.bench=".*"

Expand Down
113 changes: 113 additions & 0 deletions conn_stats_arm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// Separate implementation for arm, since it has broken support for atomics.
// See https://github.com/valyala/gorpc/issues/5 for details.

// +build arm

package gorpc

import (
"sync"
)

// Snapshot returns connection statistics' snapshot.
//
// Use stats returned from ConnStats.Snapshot() on live Client and / or Server,
// since the original stats can be updated by concurrently running goroutines.
func (cs *ConnStats) Snapshot() *ConnStats {
cs.lock.Lock()
snapshot := *cs
cs.lock.Unlock()

snapshot.lock = sync.Mutex{}
return &snapshot
}

// Reset resets all the stats counters.
func (cs *ConnStats) Reset() {
cs.lock.Lock()
cs.RPCCalls = 0
cs.RPCTime = 0
cs.BytesWritten = 0
cs.BytesRead = 0
cs.WriteCalls = 0
cs.WriteErrors = 0
cs.ReadCalls = 0
cs.ReadErrors = 0
cs.DialCalls = 0
cs.DialErrors = 0
cs.AcceptCalls = 0
cs.AcceptErrors = 0
cs.lock.Unlock()
}

func (cs *ConnStats) incRPCCalls() {
cs.lock.Lock()
cs.RPCCalls++
cs.lock.Unlock()
}

func (cs *ConnStats) incRPCTime(dt uint64) {
cs.lock.Lock()
cs.RPCTime += dt
cs.lock.Unlock()
}

func (cs *ConnStats) addBytesWritten(n uint64) {
cs.lock.Lock()
cs.BytesWritten += n
cs.lock.Unlock()
}

func (cs *ConnStats) addBytesRead(n uint64) {
cs.lock.Lock()
cs.BytesRead += n
cs.lock.Unlock()
}

func (cs *ConnStats) incReadCalls() {
cs.lock.Lock()
cs.ReadCalls++
cs.lock.Unlock()
}

func (cs *ConnStats) incReadErrors() {
cs.lock.Lock()
cs.ReadErrors++
cs.lock.Unlock()
}

func (cs *ConnStats) incWriteCalls() {
cs.lock.Lock()
cs.WriteCalls++
cs.lock.Unlock()
}

func (cs *ConnStats) incWriteErrors() {
cs.lock.Lock()
cs.WriteErrors++
cs.lock.Unlock()
}

func (cs *ConnStats) incDialCalls() {
cs.lock.Lock()
cs.DialCalls++
cs.lock.Unlock()
}

func (cs *ConnStats) incDialErrors() {
cs.lock.Lock()
cs.DialErrors++
cs.lock.Unlock()
}

func (cs *ConnStats) incAcceptCalls() {
cs.lock.Lock()
cs.AcceptCalls++
cs.lock.Unlock()
}

func (cs *ConnStats) incAcceptErrors() {
cs.lock.Lock()
cs.AcceptErrors++
cs.lock.Unlock()
}
2 changes: 1 addition & 1 deletion conn_stats_generic.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build !386
// +build !386,!arm

package gorpc

Expand Down