-
Notifications
You must be signed in to change notification settings - Fork 3
/
web.go
51 lines (31 loc) · 908 Bytes
/
web.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
42
43
44
45
46
47
48
49
50
51
package main
import (
"fmt"
"github.com/kshvakov/gopinba"
"net/http"
)
var pinba *gopinba.Pinba
func simpleRequest(w http.ResponseWriter, r *http.Request) {
request := pinba.Request()
request.SetScriptName(r.URL.Path)
// exec
go pinba.Flush(request)
fmt.Fprintf(w, "simpleRequest %s", r.URL.Path)
}
func requestWithTimers(w http.ResponseWriter, r *http.Request) {
request := pinba.Request()
request.SetScriptName(r.URL.Path)
for i := 0; i < 100; i++ {
timer := request.TimerStart(&gopinba.Tags{"group": "web"})
// exec
request.TimerStop(timer)
}
go pinba.Flush(request)
fmt.Fprintf(w, "requestWithTimers %s", r.URL.Path)
}
func main() {
pinba = gopinba.New(&gopinba.Options{PinbaHost: "127.0.0.1", PinbaPort: 30002, ServerName: "go-web.local"})
http.HandleFunc("/", simpleRequest)
http.HandleFunc("/timers/", requestWithTimers)
http.ListenAndServe(":8080", nil)
}