mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-13 05:46:16 +00:00
Merge pull request #62860 from mikedanese/rawpprof
Automatic merge from submit-queue (batch tested with PRs 63007, 62919, 62669, 62860). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. e2e: save raw profiles too #62808 ```release-note NONE ```
This commit is contained in:
commit
316b76f093
@ -19,7 +19,6 @@ package framework
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
@ -69,36 +68,44 @@ func gatherProfileOfKind(profileBaseName, kind string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to execute curl command on master through SSH: %v", err)
|
return fmt.Errorf("Failed to execute curl command on master through SSH: %v", err)
|
||||||
}
|
}
|
||||||
// Write the data to a temp file.
|
|
||||||
var tmpfile *os.File
|
|
||||||
tmpfile, err = ioutil.TempFile("", "apiserver-profile")
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("Failed to create temp file for profile data: %v", err)
|
|
||||||
}
|
|
||||||
defer os.Remove(tmpfile.Name())
|
|
||||||
if _, err := tmpfile.Write([]byte(sshResult.Stdout)); err != nil {
|
|
||||||
return fmt.Errorf("Failed to write temp file with profile data: %v", err)
|
|
||||||
}
|
|
||||||
if err := tmpfile.Close(); err != nil {
|
|
||||||
return fmt.Errorf("Failed to close temp file: %v", err)
|
|
||||||
}
|
|
||||||
// Create a graph from the data and write it to a pdf file.
|
|
||||||
var cmd *exec.Cmd
|
|
||||||
var profilePrefix string
|
var profilePrefix string
|
||||||
switch {
|
switch {
|
||||||
// TODO: Support other profile kinds if needed (e.g inuse_space, alloc_objects, mutex, etc)
|
|
||||||
case kind == "heap":
|
case kind == "heap":
|
||||||
cmd = exec.Command("go", "tool", "pprof", "-pdf", "-symbolize=none", "--alloc_space", tmpfile.Name())
|
|
||||||
profilePrefix = "ApiserverMemoryProfile_"
|
profilePrefix = "ApiserverMemoryProfile_"
|
||||||
case strings.HasPrefix(kind, "profile"):
|
case strings.HasPrefix(kind, "profile"):
|
||||||
cmd = exec.Command("go", "tool", "pprof", "-pdf", "-symbolize=none", tmpfile.Name())
|
|
||||||
profilePrefix = "ApiserverCPUProfile_"
|
profilePrefix = "ApiserverCPUProfile_"
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("Unknown profile kind provided: %s", kind)
|
return fmt.Errorf("Unknown profile kind provided: %s", kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write the data to a file.
|
||||||
|
rawprofilePath := path.Join(getProfilesDirectoryPath(), profilePrefix+profileBaseName+".pprof")
|
||||||
|
rawprofile, err := os.Create(rawprofilePath)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Failed to create file for the profile graph: %v", err)
|
||||||
|
}
|
||||||
|
defer rawprofile.Close()
|
||||||
|
|
||||||
|
if _, err := rawprofile.Write([]byte(sshResult.Stdout)); err != nil {
|
||||||
|
return fmt.Errorf("Failed to write file with profile data: %v", err)
|
||||||
|
}
|
||||||
|
if err := rawprofile.Close(); err != nil {
|
||||||
|
return fmt.Errorf("Failed to close file: %v", err)
|
||||||
|
}
|
||||||
|
// Create a graph from the data and write it to a pdf file.
|
||||||
|
var cmd *exec.Cmd
|
||||||
|
switch {
|
||||||
|
// TODO: Support other profile kinds if needed (e.g inuse_space, alloc_objects, mutex, etc)
|
||||||
|
case kind == "heap":
|
||||||
|
cmd = exec.Command("go", "tool", "pprof", "-pdf", "-symbolize=none", "--alloc_space", rawprofile.Name())
|
||||||
|
case strings.HasPrefix(kind, "profile"):
|
||||||
|
cmd = exec.Command("go", "tool", "pprof", "-pdf", "-symbolize=none", rawprofile.Name())
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("Unknown profile kind provided: %s", kind)
|
||||||
|
}
|
||||||
outfilePath := path.Join(getProfilesDirectoryPath(), profilePrefix+profileBaseName+".pdf")
|
outfilePath := path.Join(getProfilesDirectoryPath(), profilePrefix+profileBaseName+".pdf")
|
||||||
var outfile *os.File
|
outfile, err := os.Create(outfilePath)
|
||||||
outfile, err = os.Create(outfilePath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Failed to create file for the profile graph: %v", err)
|
return fmt.Errorf("Failed to create file for the profile graph: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user