增加服务启动时间字段

This commit is contained in:
boyce
2019-04-28 15:55:30 +08:00
parent e076620d47
commit f2c5f43b1f

View File

@@ -4,12 +4,14 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"runtime/pprof" "runtime/pprof"
"time"
"github.com/duanhf2012/origin/service" "github.com/duanhf2012/origin/service"
) )
type PProfService struct { type PProfService struct {
service.BaseService service.BaseService
fisttime int
} }
type ProfileData struct { type ProfileData struct {
@@ -18,11 +20,19 @@ type ProfileData struct {
} }
type Profilestruct struct { type Profilestruct struct {
Fisttime int
ProfileList []ProfileData ProfileList []ProfileData
} }
func (slf *PProfService) OnInit() error {
slf.fisttime = (int)(time.Now().UnixNano())
return nil
}
func (slf *PProfService) GetPprof() ([]byte, error) { func (slf *PProfService) GetPprof() ([]byte, error) {
var pfiles Profilestruct var pfiles Profilestruct
pfiles.Fisttime = slf.fisttime
for _, p := range pprof.Profiles() { for _, p := range pprof.Profiles() {
pfiles.ProfileList = append(pfiles.ProfileList, ProfileData{ pfiles.ProfileList = append(pfiles.ProfileList, ProfileData{
Name: p.Name(), Name: p.Name(),