forked from ardanlabs/gotraining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
trace.go
37 lines (30 loc) · 778 Bytes
/
trace.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
// All material is licensed under the Apache License Version 2.0, January 2004
// http://www.apache.org/licenses/LICENSE-2.0
// https://play.golang.org/p/aLDVeFFbxd
// Sample program to learn how to identify memory problems.
package main
import (
"net/http"
_ "net/http/pprof"
"os"
"os/signal"
)
// main is the entry point for the application.
func main() {
// Create a goroutine that leaks memory. Since the map needs
// to be constantly shuffled around, this becomes very expensive.
go func() {
m := make(map[int]int)
for i := 0; ; i++ {
m[i] = i
}
}()
// Start a listener for the pprof support.
go func() {
http.ListenAndServe(":6060", nil)
}()
// On a <ctrl> C shutdown the program.
sig := make(chan os.Signal, 1)
signal.Notify(sig)
<-sig
}