Skip to content

Commit da09348

Browse files
committed
<debugcharts><文档><基本编写>
1 parent fa2fc7a commit da09348

File tree

5 files changed

+111
-2
lines changed

5 files changed

+111
-2
lines changed

demo/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ Golang Demo
99
- [phantomjs](phantomjs) go 使用 phantomjs 案例
1010
- [robotgo](robotgo) Golang 跨平台自动化系统,控制键盘鼠标位图和读取屏幕,窗口句柄以及全局事件监听
1111
- [gse](gse) Go 语言高效分词, 支持英文、中文、日文等
12-
- [gpy](gpy) 汉语拼音转换工具 Go 版。
12+
- [gpy](gpy) 汉语拼音转换工具 Go 版。
13+
- [debugcharts](debugcharts) Very simple charts with some debug data for Go programs

demo/debugcharts/README.md

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
```

demo/debugcharts/beego/main.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
}

demo/debugcharts/gin/main.go

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
}

demo/debugcharts/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import (
99

1010
_ "net/http/pprof"
1111

12-
"github.com/gorilla/handlers"
1312
_ "github.com/mkevac/debugcharts"
13+
"github.com/gorilla/handlers"
1414
)
1515

1616
func dummyCPUUsage() {

0 commit comments

Comments
 (0)