统计服务器性能功能

This commit is contained in:
boyce
2019-04-03 17:56:24 +08:00
parent b5dd07b883
commit 87bfdaeaf0

View File

@@ -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
}