forked from arl/statsviz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mux.go
41 lines (32 loc) · 839 Bytes
/
mux.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"math/rand"
"net/http"
"strconv"
"time"
"github.com/arl/statsviz"
"github.com/gorilla/mux"
)
func main() {
// Force the GC to work to make the plots "move".
go work()
// Create a Gorilla router and register statsviz handlers.
r := mux.NewRouter()
r.Methods("GET").Path("/debug/statsviz/ws").Name("GET /debug/statsviz/ws").HandlerFunc(statsviz.Ws)
r.Methods("GET").PathPrefix("/debug/statsviz/").Name("GET /debug/statsviz/").Handler(statsviz.Index)
mux := http.NewServeMux()
mux.Handle("/", r)
http.ListenAndServe(":8080", mux)
}
func work() {
// Generate some allocations
m := map[string][]byte{}
for {
b := make([]byte, 512+rand.Intn(16*1024))
m[strconv.Itoa(len(m)%(10*100))] = b
if len(m)%(10*100) == 0 {
m = make(map[string][]byte)
}
time.Sleep(10 * time.Millisecond)
}
}