mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-04 06:54:45 +08:00
统计服务器性能功能
This commit is contained in:
61
sysservice/pprofservice.go
Normal file
61
sysservice/pprofservice.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user