-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathREADME
66 lines (54 loc) · 2.66 KB
/
README
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
Go has really good profiling tools built into the standard library.
cpu profiling - stack sampling
heap profiling - small amount of allocations are sampled including call stack
block profiling - lock contentions
tracing, etc all in pprof
Ways to profile:
1. Instrument your binary during testing and benchmarking:
go test -cpuprofile -memprofile
2. import _ net/http/pprof that exposes /debug/pprof endpoints to your app
- Once those are enabled a simple command will take a sample:
go tool pprof -seconds 5 http://localhost:5000/debug/pprof/profile
3. for debugging memory leaks or something really difficult, you can
instrument things in your application where you think the issue is.
runtime.StartCPUProfile or runtime.WriteHeapProfile
go tool pprof will analyze these profiles.
### To run benchmarks
go test -bench . -benchmem -cpuprofile prof.cpu
go tool pprof stats.test prof.cpu
Fetched 1 source profiles out of 2
Main binary filename not available.
Type: cpu
Time: Nov 16, 2017 at 7:29pm (EST)
Duration: 2.24s, Total samples = 2.04s (91.11%)
Entering interactive mode (type "help" for commands, "o" for options)
(pprof) list HashPassword
Total: 2.04s
ROUTINE ======================== skeletor.BenchmarkHashPassword in /Users/Bmercer/gopath/src/skeletor/skeletor_test.go
10ms 1.78s (flat, cum) 87.25% of Total
. . 4: "skeletor/utils"
. . 5: "testing"
. . 6:)
. . 7:
. . 8:func BenchmarkHashPassword(b *testing.B) {
10ms 10ms 9: for i := 0; i < b.N; i++ {
. 1.77s 10: utils.HashPassword("password")
. . 11: }
. . 12:
. . 13:}
ROUTINE ======================== skeletor/utils.HashPassword in /Users/Bmercer/gopath/src/skeletor/utils/utils.go
70ms 1.77s (flat, cum) 86.76% of Total
. . 7: "io"
. . 8: "net/http"
. . 9:)
. . 10:
. . 11:func HashPassword(password string) string {
. 250ms 12: h := sha256.New()
20ms 110ms 13: h.Write([]byte(password))
40ms 1.40s 14: res := fmt.Sprintf("%x", h.Sum(nil))
10ms 10ms 15: return res
. . 16:}
. . 17:
. . 18:func MustEncode(w io.Writer, i interface{}) {
. . 19: if headered, ok := w.(http.ResponseWriter); ok {
. . 20: headered.Header().Set("Cache-Control", "no-cache")