Skip to content

Commit

Permalink
get debug agent port from config file
Browse files Browse the repository at this point in the history
  • Loading branch information
zhijian-pro committed Oct 14, 2022
1 parent de27c67 commit 663ecb0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cmd/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"archive/zip"
"bufio"
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
Expand All @@ -35,6 +36,7 @@ import (

"github.com/juicedata/juicefs/pkg/meta"
"github.com/juicedata/juicefs/pkg/utils"
"github.com/juicedata/juicefs/pkg/vfs"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -208,6 +210,24 @@ func copyLogFile(logPath, retLogPath string, limit uint64, rootPrivileges bool)
}

func getPprofPort(pid, amp string, rootPrivileges bool) (int, error) {
content, err := os.ReadFile(filepath.Join(amp, ".config"))
if err != nil {
logger.Warnf("failed to read config file: %v", err)
}
cfg := vfs.Config{}
if err := json.Unmarshal(content, &cfg); err != nil {
logger.Warnf("failed to unmarshal config file: %v", err)
}
if cfg.Port.DebugAgent != "" {
if len(strings.Split(cfg.Port.DebugAgent, ":")) >= 2 {
if port, err := strconv.Atoi(strings.Split(cfg.Port.DebugAgent, ":")[1]); err != nil {
logger.Warnf("failed to parse debug agent port: %v", err)
} else {
return port, nil
}
}
}

var lsofArgs []string
if rootPrivileges {
lsofArgs = append(lsofArgs, "sudo")
Expand Down

0 comments on commit 663ecb0

Please sign in to comment.