Skip to content

Commit

Permalink
DAOS-15510 control: Debug dmg performance
Browse files Browse the repository at this point in the history
Skip-unit-tests: true
Skip-test: true
Signed-off-by: Li Wei <wei.g.li@intel.com>
Required-githooks: true
  • Loading branch information
liw committed Jun 18, 2024
1 parent bf9ac88 commit d35e4b5
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
8 changes: 8 additions & 0 deletions src/control/cmd/daos_server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"context"
"encoding/json"
"fmt"
"log"
"os"
"path"

Expand All @@ -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"
Expand Down Expand Up @@ -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{
Expand Down
42 changes: 33 additions & 9 deletions src/control/cmd/dmg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
}

0 comments on commit d35e4b5

Please sign in to comment.