Skip to content

Commit

Permalink
Display full command-line in process tree
Browse files Browse the repository at this point in the history
This commit updates the `--ps-tree` flag ouput. We are now printing
the full command-line instead of core image `Comm` field value.
Providing more information about arguments used to start the processes.

Signed-off-by: Kouame Behouba Manasse <[email protected]>
  • Loading branch information
behouba committed Jun 19, 2023
1 parent 89aacca commit 2688e3d
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func showContainerCheckpoints(tasks []task) error {
return fmt.Errorf("failed to get process tree: %w", err)
}

renderPsTree(psTree, ci.Name)
renderPsTree(psTree, ci.Name, tasks[0].outputDir)
}
}

Expand Down Expand Up @@ -260,7 +260,7 @@ func renderDumpStats(dumpStats *statsImg.DumpStatsEntry) {
table.Render()
}

func renderPsTree(psTree *crit.PsTree, containerName string) {
func renderPsTree(psTree *crit.PsTree, containerName, checkpointDir string) {
var tree treeprint.Tree
if containerName == "" {
containerName = "Container"
Expand All @@ -271,7 +271,13 @@ func renderPsTree(psTree *crit.PsTree, containerName string) {
// processes as child nodes of the branch.
var processNodes func(treeprint.Tree, *crit.PsTree)
processNodes = func(tree treeprint.Tree, root *crit.PsTree) {
node := tree.AddMetaBranch(root.PID, root.Comm)
// Try to retrieve the full command-line from memory pages
cmdline, err := getCmdline(checkpointDir, root.PID)
if err != nil || cmdline == "" {
cmdline = root.Comm
}

node := tree.AddMetaBranch(root.PID, cmdline)
for _, child := range root.Children {
processNodes(node, child)
}
Expand Down Expand Up @@ -410,3 +416,18 @@ func iterateTarArchive(archiveInput string, callback func(r *tar.Reader, header

return nil
}

func getCmdline(checkpointDir string, pid uint32) (cmdline string, err error) {
mr, err := crit.NewMemoryReader(filepath.Join(checkpointDir, metadata.CheckpointDirectory), pid, pageSize)
if err != nil {
return
}

buffer, err := mr.GetPsArgs()
if err != nil {
return
}

cmdline = strings.Join(strings.Split(buffer.String(), "\x00"), " ")
return
}

0 comments on commit 2688e3d

Please sign in to comment.