()
| 60 | } |
| 61 | |
| 62 | func (s *JSONStats) computeRates() { |
| 63 | ticker := time.NewTicker(time.Second) |
| 64 | defer ticker.Stop() |
| 65 | for range ticker.C { |
| 66 | cur := s.framesReceived.Load() |
| 67 | prev := s.lastFrames.Swap(cur) |
| 68 | s.framesPerSecond.Store(cur - prev) |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | func (s *JSONStats) handleRequest(w http.ResponseWriter, _ *http.Request) { |
| 73 | snap := snapshot{ |