Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 71486a2

Browse files
authored
Merge pull request studygolang#53 from meission/master
update add pprof for studygolang
2 parents 0851a95 + b2266d2 commit 71486a2

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

config/env.sample.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[global]
22
env = dev
33

4+
pprof = 127.0.0.1:8096
45
log_level = DEBUG
56
domain = xxx
67

src/server/studygolang/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ func main() {
5454
go logic.Book.ClearRedisUser()
5555

5656
go ServeBackGround()
57+
// go pprof
58+
Pprof(ConfigFile.MustValue("global", "pprof", "127.0.0.1:8096"))
5759

5860
e := echo.New()
5961

src/server/studygolang/pprof.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2018 The StudyGolang Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
// http://studygolang.com
5+
// Author: meission [email protected]
6+
7+
package main
8+
9+
import (
10+
"net/http"
11+
"net/http/pprof"
12+
)
13+
14+
// Pprof start http pprof.
15+
func Pprof(addr string) {
16+
ps := http.NewServeMux()
17+
ps.HandleFunc("/debug/pprof/", pprof.Index)
18+
ps.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
19+
ps.HandleFunc("/debug/pprof/profile", pprof.Profile)
20+
ps.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
21+
go func() {
22+
if err := http.ListenAndServe(addr, ps); err != nil {
23+
panic(err)
24+
}
25+
}()
26+
}

0 commit comments

Comments
 (0)