Add pprof to runc-shim

Signed-off-by: Henry Wang <henwang@amazon.com>
This commit is contained in:
Henry Wang
2024-05-03 01:05:13 +00:00
parent 8b5c218e5a
commit 243b803a19
10 changed files with 406 additions and 105 deletions

View File

@@ -76,12 +76,16 @@ func AdjustOOMScore(pid int) error {
const socketRoot = defaults.DefaultStateDir
// SocketAddress returns a socket address
func SocketAddress(ctx context.Context, socketPath, id string) (string, error) {
func SocketAddress(ctx context.Context, socketPath, id string, debug bool) (string, error) {
ns, err := namespaces.NamespaceRequired(ctx)
if err != nil {
return "", err
}
d := sha256.Sum256([]byte(filepath.Join(socketPath, ns, id)))
path := filepath.Join(socketPath, ns, id)
if debug {
path = filepath.Join(path, "debug")
}
d := sha256.Sum256([]byte(path))
return fmt.Sprintf("unix://%s/%x", filepath.Join(socketRoot, "s"), d), nil
}
@@ -286,7 +290,12 @@ func cleanupSockets(ctx context.Context) {
}
if len(socketFlag) > 0 {
_ = RemoveSocket("unix://" + socketFlag)
} else if address, err := SocketAddress(ctx, addressFlag, id); err == nil {
} else if address, err := SocketAddress(ctx, addressFlag, id, false); err == nil {
_ = RemoveSocket(address)
}
if len(debugSocketFlag) > 0 {
_ = RemoveSocket("unix://" + debugSocketFlag)
} else if address, err := SocketAddress(ctx, addressFlag, id, true); err == nil {
_ = RemoveSocket(address)
}
}