From 87bfdaeaf0184771f33e6f5d5340c94c9b5ffaa7 Mon Sep 17 00:00:00 2001 From: boyce Date: Wed, 3 Apr 2019 17:56:24 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=9C=8D=E5=8A=A1=E5=99=A8?= =?UTF-8?q?=E6=80=A7=E8=83=BD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sysservice/pprofservice.go | 61 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 sysservice/pprofservice.go diff --git a/sysservice/pprofservice.go b/sysservice/pprofservice.go new file mode 100644 index 0000000..4fda723 --- /dev/null +++ b/sysservice/pprofservice.go @@ -0,0 +1,61 @@ +package sysservice + +import ( + "encoding/json" + "fmt" + "runtime/pprof" + + "github.com/duanhf2012/origin/service" +) + +type PProfService struct { + service.BaseService +} + +type ProfileData struct { + Name string + Count int +} + +type Profilestruct struct { + ProfileList []ProfileData +} + +func (slf *PProfService) GetPprof() ([]byte, error) { + var pfiles Profilestruct + for _, p := range pprof.Profiles() { + pfiles.ProfileList = append(pfiles.ProfileList, ProfileData{ + Name: p.Name(), + Count: p.Count(), + }) + } + + return json.Marshal(pfiles) +} + +func (slf *PProfService) HTTP_DebugPProf(request *HttpRequest, resp *HttpRespone) error { + var err error + resp.Respone, err = slf.GetPprof() + if err != nil { + resp.Respone = []byte(fmt.Sprint(err)) + } + return nil +} + +func (slf *PProfService) RPC_DebugPProf(arg *string, ret *Profilestruct) error { + + for _, p := range pprof.Profiles() { + ret.ProfileList = append(ret.ProfileList, ProfileData{ + Name: p.Name(), + Count: p.Count(), + }) + } + + return nil +} + +func (slf *PProfService) HTTP_Test(request *HttpRequest, resp *HttpRespone) error { + + resp.Respone = []byte(request.Body) + return nil +}