-
Notifications
You must be signed in to change notification settings - Fork 8
/
example.go
78 lines (67 loc) · 1.18 KB
/
example.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//go:build linux
// +build linux
package main
import (
"errors"
"fmt"
"log"
"github.com/daangn/autopprof"
"github.com/daangn/autopprof/report"
)
type mm struct {
m map[int64]string
}
func main() {
err := autopprof.Start(autopprof.Option{
Reporter: report.NewSlackReporter(
&report.SlackReporterOption{
App: "YOUR_APP_NAME",
Token: "YOUR_TOKEN_HERE",
Channel: "#REPORT_CHANNEL",
},
),
})
if errors.Is(err, autopprof.ErrUnsupportedPlatform) {
// You can just skip the autopprof.
log.Println(err)
} else if err != nil {
log.Fatalln(err)
}
defer autopprof.Stop()
eatMemory()
go func() {
for {
iterative(1000)
}
}()
go func() {
for {
recursive(15)
}
}()
for {
fmt.Println("main")
}
}
func eatMemory() {
m := make(map[int64]string, 20000000)
for i := 0; i < 20000000; i++ {
m[int64(i)] = "eating heap memory"
}
_ = mm{m: m}
}
// Iterative fibonacci func implementation.
func iterative(n int) int64 {
var a, b int64 = 0, 1
for i := 0; i < n; i++ {
a, b = b, a+b
}
return a
}
// Recursive fibonacci func implementation.
func recursive(n int) int64 {
if n <= 1 {
return int64(n)
}
return recursive(n-1) + recursive(n-2)
}