From d35e4b5b13b5fe80d1de30abb6da7e19315685dd Mon Sep 17 00:00:00 2001 From: Li Wei Date: Thu, 13 Jun 2024 16:14:35 +0900 Subject: [PATCH] DAOS-15510 control: Debug dmg performance Skip-unit-tests: true Skip-test: true Signed-off-by: Li Wei Required-githooks: true --- src/control/cmd/daos_server/main.go | 8 ++++++ src/control/cmd/dmg/main.go | 42 ++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/src/control/cmd/daos_server/main.go b/src/control/cmd/daos_server/main.go index 0de6f55bd6b..55b6fdbb73a 100644 --- a/src/control/cmd/daos_server/main.go +++ b/src/control/cmd/daos_server/main.go @@ -10,6 +10,7 @@ import ( "context" "encoding/json" "fmt" + "log" "os" "path" @@ -24,6 +25,9 @@ import ( "github.com/daos-stack/daos/src/control/lib/hardware/hwprov" "github.com/daos-stack/daos/src/control/logging" "github.com/daos-stack/daos/src/control/pbin" + + "net/http" + _ "net/http/pprof" ) const defaultConfigFile = "daos_server.yml" @@ -171,6 +175,10 @@ func parseOpts(args []string, opts *mainOpts, log *logging.LeveledLogger) error } func main() { + go func() { + log.Println(http.ListenAndServe(":6060", nil)) + }() + log := logging.NewCommandLineLogger() opts := mainOpts{ preExecTests: []execTestFn{ diff --git a/src/control/cmd/dmg/main.go b/src/control/cmd/dmg/main.go index a088e0f8022..7335b0cb521 100644 --- a/src/control/cmd/dmg/main.go +++ b/src/control/cmd/dmg/main.go @@ -9,8 +9,11 @@ package main import ( "encoding/json" "fmt" + "log" "os" "path" + "runtime/pprof" + "strconv" flags "github.com/jessevdk/go-flags" "github.com/pkg/errors" @@ -296,19 +299,40 @@ and access control settings, along with system wide operations.` } func main() { + n := 1 + cpuprofile := os.Getenv("DAOS_DMG_CPUPROFILE") + if cpuprofile != "" { + f, err := os.Create(cpuprofile) + if err != nil { + log.Fatal(err) + } + nString := os.Getenv("DAOS_DMG_CPUPROFILE_N") + if nString == "" { + nString = "100" + } + n, err = strconv.Atoi(nString) + if err != nil { + log.Fatal(err) + } + pprof.StartCPUProfile(f) + defer pprof.StopCPUProfile() + } + var opts cliOptions log := logging.NewCommandLineLogger() - ctlInvoker := control.NewClient( - control.WithClientLogger(log), - control.WithClientComponent(build.ComponentAdmin), - ) + for i := 0; i < n; i++ { + ctlInvoker := control.NewClient( + control.WithClientLogger(log), + control.WithClientComponent(build.ComponentAdmin), + ) - if err := parseOpts(os.Args[1:], &opts, ctlInvoker, log); err != nil { - if fe, ok := errors.Cause(err).(*flags.Error); ok && fe.Type == flags.ErrHelp { - log.Info(fe.Error()) - os.Exit(0) + if err := parseOpts(os.Args[1:], &opts, ctlInvoker, log); err != nil { + if fe, ok := errors.Cause(err).(*flags.Error); ok && fe.Type == flags.ErrHelp { + log.Info(fe.Error()) + os.Exit(0) + } + exitWithError(log, err) } - exitWithError(log, err) } }