Skip to content

Commit

Permalink
err output
Browse files Browse the repository at this point in the history
Signed-off-by: Connor1996 <[email protected]>
  • Loading branch information
Connor1996 committed Oct 30, 2023
1 parent fa0bf2e commit 70d35a4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ require (
github.com/pingcap/kvproto v0.0.0-20200411081810-b85805c9476c
github.com/pingcap/log v0.0.0-20210906054005-afc726e70354
github.com/pingcap/tipb v0.0.0-20220718022156-3e2483c20a9e
github.com/pkg/errors v0.9.1
github.com/rs/cors v1.7.0
github.com/samber/lo v1.37.0
github.com/shhdgit/testfixtures/v3 v3.6.2-0.20211219171712-c4f264d673d3
Expand Down Expand Up @@ -92,6 +91,7 @@ require (
github.com/mattn/go-sqlite3 v1.14.15 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/stretchr/objx v0.2.0 // indirect
github.com/swaggo/files v0.0.0-20210815190702-a29dd2bc99b2 // indirect
Expand Down
30 changes: 22 additions & 8 deletions pkg/apiserver/profiling/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,30 @@ func (f *tikvFetcher) fetch(op *fetchOptions) ([]byte, error) {
if strings.HasSuffix(op.path, "heap") {
cmd := exec.Command("perl", "/dev/stdin", "--raw", "http://"+op.ip+":"+strconv.Itoa(op.port)+op.path) //nolint:gosec
cmd.Stdin = strings.NewReader(jeprof)
stderr, _ := cmd.StderrPipe()
stdout, err := cmd.StdoutPipe()
if err != nil {
return nil, err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return nil, err
}
// use jeprof to fetch tikv heap profile
data, err := cmd.Output()
err = cmd.Start()
if err != nil {
return nil, err
}
data, err := io.ReadAll(stdout)
if err != nil {
return nil, err
}
errMsg, err := io.ReadAll(stderr)
if err != nil {
return nil, err
}
err = cmd.Wait()
if err != nil {
if stderr != nil {
errMsg, _ := io.ReadAll(stderr)
return nil, fmt.Errorf("failed to fetch tikv heap profile: %s", errMsg)
} else {
return nil, fmt.Errorf("failed to fetch tikv heap profile: %s", err)
}
return nil, fmt.Errorf("failed to fetch tikv heap profile: %s", errMsg)
}
return data, nil
}
Expand Down

0 comments on commit 70d35a4

Please sign in to comment.