Commit 022baf86 authored by Pavel Emelyanov's avatar Pavel Emelyanov

crit: The 'ps' explorer

Shows process tree from image. The output is like

    PID   PGID    SID   COMM
      1      1      1   session00
      4      4      4       session00
      7      7      7           session00
      8      4      4           session00
     11     11     11           session00
     12      4      4               session00
     13     13     13           session00
     14     14     14               session00
     15      4      4                   session00
      6      4      4       session00
     10      9      9       session00

(the above is for session00 test).
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
Appreciated-by: avagin@openvz.org
parent 075c1c9f
......@@ -2,6 +2,7 @@
import argparse
import sys
import json
import os
import pycriu
......@@ -52,7 +53,44 @@ def info(opts):
# Explorers
#
explorers = { }
class ps_item:
def __init__(self, p, core):
self.pid = p['pid']
self.ppid = p['ppid']
self.p = p
self.core = core
self.kids = []
def show_ps(p, opts, depth = 0):
print "%7d%7d%7d %s%s" % (p.pid, p.p['pgid'], p.p['sid'],
' ' * (4 * depth), p.core['tc']['comm'])
for kid in p.kids:
show_ps(kid, opts, depth + 1)
def explore_ps(opts):
pss = { }
ps_img = pycriu.images.load(dinf(opts, 'pstree.img'))
for p in ps_img['entries']:
core = pycriu.images.load(dinf(opts, 'core-%d.img' % p['pid']))
ps = ps_item(p, core['entries'][0])
pss[ps.pid] = ps
# Build tree
psr = None
for pid in pss:
p = pss[pid]
if p.ppid == 0:
psr = p
continue
pp = pss[p.ppid]
pp.kids.append(p)
print "%7s%7s%7s %s" % ('PID', 'PGID', 'SID', 'COMM')
show_ps(psr, opts)
explorers = { 'ps': explore_ps }
def explore(opts):
explorers[opts['what']](opts)
......@@ -98,7 +136,7 @@ def main():
# Explore
x_parser = subparsers.add_parser('x', help = 'explore image dir')
x_parser.add_argument('dir')
x_parser.add_argument('what', choices = [ ])
x_parser.add_argument('what', choices = [ 'ps' ])
x_parser.set_defaults(func=explore)
# Show
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment