File tree 5 files changed +111
-2
lines changed
5 files changed +111
-2
lines changed Original file line number Diff line number Diff line change @@ -9,4 +9,5 @@ Golang Demo
9
9
- [ phantomjs] ( phantomjs ) go 使用 phantomjs 案例
10
10
- [ robotgo] ( robotgo ) Golang 跨平台自动化系统,控制键盘鼠标位图和读取屏幕,窗口句柄以及全局事件监听
11
11
- [ gse] ( gse ) Go 语言高效分词, 支持英文、中文、日文等
12
- - [ gpy] ( gpy ) 汉语拼音转换工具 Go 版。
12
+ - [ gpy] ( gpy ) 汉语拼音转换工具 Go 版。
13
+ - [ debugcharts] ( debugcharts ) Very simple charts with some debug data for Go programs
Original file line number Diff line number Diff line change
1
+ # [ debugcharts] ( https://github.com/mkevac/debugcharts )
2
+
3
+ ## 安装方法:
4
+ ```
5
+ go get -v -u github.com/mkevac/debugcharts
6
+ ```
7
+
8
+ ## 使用方法:
9
+ ```
10
+ import _ "github.com/mkevac/debugcharts"
11
+ ```
12
+
13
+ ## 使用案例:
14
+ ```
15
+ package main
16
+
17
+ import (
18
+ "fmt"
19
+ "log"
20
+ "net/http"
21
+ "runtime"
22
+ "time"
23
+
24
+ _ "net/http/pprof"
25
+
26
+ "github.com/gorilla/handlers"
27
+ _ "github.com/mkevac/debugcharts"
28
+ )
29
+
30
+ func dummyCPUUsage() {
31
+ var a uint64
32
+ var t = time.Now()
33
+ for {
34
+ t = time.Now()
35
+ a += uint64(t.Unix())
36
+ }
37
+ }
38
+
39
+ func dummyAllocations() {
40
+ var d []uint64
41
+
42
+ for {
43
+ for i := 0; i < 2*1024*1024; i++ {
44
+ d = append(d, 42)
45
+ }
46
+ time.Sleep(time.Second * 10)
47
+ fmt.Println(len(d))
48
+ d = make([]uint64, 0)
49
+ runtime.GC()
50
+ time.Sleep(time.Second * 10)
51
+ }
52
+ }
53
+
54
+ func main() {
55
+ go dummyAllocations()
56
+ go dummyCPUUsage()
57
+ go func() {
58
+ log.Fatal(http.ListenAndServe(":8080", handlers.CompressHandler(http.DefaultServeMux)))
59
+ }()
60
+ log.Printf("you can now open http://localhost:8080/debug/charts/ in your browser")
61
+ select {}
62
+ }
63
+ ```
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "log"
5
+ _ "net/http/pprof"
6
+
7
+ _ "github.com/mkevac/debugcharts"
8
+ "github.com/astaxie/beego"
9
+ "net/http"
10
+ "github.com/gorilla/handlers"
11
+ )
12
+
13
+ func main () {
14
+ go func () {
15
+ log .Fatal (http .ListenAndServe (":9090" , handlers .CompressHandler (http .DefaultServeMux )))
16
+ }()
17
+
18
+ log .Printf ("you can now open http://localhost:8080/debug/charts/ in your browser" )
19
+ beego .Run ()
20
+ }
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "log"
5
+ _ "net/http/pprof"
6
+
7
+ _ "github.com/mkevac/debugcharts"
8
+ "github.com/gin-gonic/gin"
9
+ "net/http"
10
+ "github.com/gorilla/handlers"
11
+ )
12
+
13
+ func main () {
14
+ go func () {
15
+ log .Fatal (http .ListenAndServe (":9090" , handlers .CompressHandler (http .DefaultServeMux )))
16
+ }()
17
+ r := gin .Default ()
18
+ r .GET ("/" , func (c * gin.Context ) {
19
+ c .JSON (200 , gin.H {
20
+ "message" : "pong" ,
21
+ })
22
+ })
23
+ r .Run () // listen and serve on 0.0.0.0:8080
24
+ log .Printf ("you can now open http://localhost:8080/debug/charts/ in your browser" )
25
+ }
Original file line number Diff line number Diff line change 9
9
10
10
_ "net/http/pprof"
11
11
12
- "github.com/gorilla/handlers"
13
12
_ "github.com/mkevac/debugcharts"
13
+ "github.com/gorilla/handlers"
14
14
)
15
15
16
16
func dummyCPUUsage () {
You can’t perform that action at this time.
0 commit comments