Skip to content

Commit

Permalink
fix tracing output
Browse files Browse the repository at this point in the history
  • Loading branch information
bdevcich committed Dec 15, 2023
1 parent 11f8d37 commit fb79568
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
24 changes: 21 additions & 3 deletions daemons/compute/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ import (
"github.com/takama/daemon"
"google.golang.org/grpc"

"net/http"
_ "net/http/pprof"

pb "github.com/NearNodeFlash/nnf-dm/daemons/compute/client-go/api"

"github.com/NearNodeFlash/nnf-dm/daemons/compute/server/auth"
Expand Down Expand Up @@ -101,9 +104,24 @@ func (service *Service) Manage() (msg string, err error) {
return fmt.Sprintf("Failed to set permissions on socket %s", *socketAddr), err
}

// Enable CPU profiling with pprof
if len(options.CpuProfile) > 0 {
filename := options.CpuProfile + "-" + time.Now().UTC().Format(time.RFC3339)
// Print out tunable parameters
stdlog.Printf("GOMAXPROCS: %s\n", os.Getenv("GOMAXPROCS"))
stdlog.Printf("GOGC: %s\n", os.Getenv("GOGC"))
stdlog.Printf("GOMEMLIMIT: %s\n", os.Getenv("GOMEMLIMIT"))

// Enable HTTP tracing. See https://pkg.go.dev/net/http/pprof for more details.
if options.Tracing {
go func() {
url := "localhost:6061"
stdlog.Printf("HTTP Tracing enabled at %s\n", url)
stdlog.Printf("HTTP Tracing output: %s", http.ListenAndServe(url, nil))
}()
}

// Enable CPU profiling with pprof. Daemon must be stopped for contents to be written to the
// file. See https://pkg.go.dev/runtime/pprof for more details.
if options.CpuProfile {
filename := fmt.Sprintf("/tmp/nnf-dm-cpu-%s.prof", time.Now().UTC().Format(time.RFC3339))
f, err := os.Create(filename)
if err != nil {
return fmt.Sprintf("could not create CPU profile"), err
Expand Down
12 changes: 8 additions & 4 deletions daemons/compute/server/servers/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ type ServerOptions struct {
name string
nodeName string
sysConfig string
CpuProfile string
CpuProfile bool
Tracing bool
simulated bool

k8sQPS int
Expand All @@ -50,7 +51,8 @@ func GetOptions() (*ServerOptions, error) {
nodeName: os.Getenv("NNF_NODE_NAME"),
tokenFile: os.Getenv("NNF_DATA_MOVEMENT_SERVICE_TOKEN_FILE"),
certFile: os.Getenv("NNF_DATA_MOVEMENT_SERVICE_CERT_FILE"),
CpuProfile: os.Getenv("NNF_DATA_MOVEMENT_SERVICE_CPU_PROFILE"),
CpuProfile: false,
Tracing: false,
simulated: false,

// These options adjust the client-side rate-limiting for k8s. The new defaults are 50 and
Expand All @@ -70,8 +72,10 @@ func GetOptions() (*ServerOptions, error) {
flag.BoolVar(&opts.simulated, "simulated", opts.simulated, "Run in simulation mode where no requests are sent to the server")
flag.IntVar(&opts.k8sQPS, "kubernetes-qps", opts.k8sQPS, "Kubernetes client queries per second (QPS)")
flag.IntVar(&opts.k8sBurst, "kubernetes-burst", opts.k8sBurst, "Kubernetes client additional concurrent calls above QPS")
flag.StringVar(&opts.CpuProfile, "cpu-profile", opts.CpuProfile,
"Enable and dump CPU profiling data to this file after daemon is stopped. Timestamp is added to end of filename.")
flag.BoolVar(&opts.CpuProfile, "cpu-profile", opts.CpuProfile,
"Enable and dump CPU profiling data to `/tmp/nnf-dm-cpu-<timestamp>.prof`. Daemon must be stopped to dump profile.")
flag.BoolVar(&opts.Tracing, "tracing", opts.Tracing,
"Enable tracing via HTTP server")
flag.Parse()
return &opts, nil
}
Expand Down

0 comments on commit fb79568

Please sign in to comment.