From 5bd25acc9f2d0f337537ce4b69a3166b38d6b1e8 Mon Sep 17 00:00:00 2001 From: ale <ale@incal.net> Date: Sat, 11 Oct 2014 11:31:41 +0100 Subject: [PATCH] properly initialize stats --- cmd/radiobench/radiobench.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cmd/radiobench/radiobench.go b/cmd/radiobench/radiobench.go index 3ace6c6e..abf3d148 100644 --- a/cmd/radiobench/radiobench.go +++ b/cmd/radiobench/radiobench.go @@ -13,9 +13,8 @@ import ( ) var ( - numConns int - - stats = &Stats{} + numConns = flag.Int("n", 3, "number of parallel connections") + stats = NewStats() retryTime = 2 * time.Second ) @@ -26,6 +25,12 @@ type Stats struct { lock sync.Mutex } +func NewStats() *Stats { + return &Stats{ + HttpStatus: make(map[int]int), + } +} + func (s *Stats) HttpError(resp *http.Response) { s.lock.Lock() defer s.lock.Unlock() @@ -50,11 +55,6 @@ func (s *Stats) Dump() { log.Printf("errs=%d http_errs=%d http_status=%v", s.Errors, s.HttpErrors, s.HttpStatus) } -func init() { - flag.IntVar(&numConns, "n", 3, "number of parallel connections") - flag.IntVar(&numConns, "num-clients", 3, "number of parallel connections") -} - func readstream(id int, streamUrl string) error { resp, err := http.Get(streamUrl) if err != nil { @@ -135,7 +135,7 @@ func main() { go dumpStats() var wg sync.WaitGroup - for i := 0; i < numConns; i++ { + for i := 0; i < *numConns; i++ { wg.Add(1) go func(id int) { worker(id, streamUrl) -- GitLab