add debug/profile package (#920)

* add debug/profile package

* set service+version for profile
This commit is contained in:
Asim Aslam
2019-11-06 19:36:04 +00:00
committed by GitHub
parent 254045e9f3
commit ce080d76c6
4 changed files with 168 additions and 6 deletions

View File

@@ -10,6 +10,8 @@ import (
"github.com/micro/go-micro/client"
"github.com/micro/go-micro/config/cmd"
"github.com/micro/go-micro/debug/handler"
"github.com/micro/go-micro/debug/profile"
"github.com/micro/go-micro/debug/profile/pprof"
"github.com/micro/go-micro/metadata"
"github.com/micro/go-micro/plugin"
"github.com/micro/go-micro/server"
@@ -147,6 +149,20 @@ func (s *service) Run() error {
),
)
// start the profiler
// TODO: set as an option to the service, don't just use pprof
if prof := os.Getenv("MICRO_DEBUG_PROFILE"); len(prof) > 0 {
service := s.opts.Server.Options().Name
version := s.opts.Server.Options().Version
profiler := pprof.NewProfile(
profile.Name(service + "." + version),
)
if err := profiler.Start(); err != nil {
return err
}
defer profiler.Stop()
}
if err := s.Start(); err != nil {
return err
}