-
Notifications
You must be signed in to change notification settings - Fork 5
Home
Tim Cuthbertson edited this page Feb 5, 2015
·
11 revisions
ls -1 / | piep 'root=set(pp) | pp = sh("mount").splitlines() \
| p.split() | p[2] | p[1:] | "/" not in p | bool \
| root.difference(set(pp)) | "/"+p \
| sh("du","-hs", *pp, stderr=open(os.devnull), stdout=sys.stdout)'
Explanation:
-
root=set(pp)
: convert input (ls -1 /
) into into a set, for later -
| pp = sh("mount").splitlines()
: runmount
, and save its lines as the newpp
-
| p.split() | p[2] | p[1:] | "/" not in p
: grab the path component, trim off the leading slash and remove any paths that have more than one slash -
| bool
: filter out the empty result -
| root.difference(set(pp))
: setpp
to the difference of the storedroot
variable and the currentpp
value -
| "/"+p
: add back leading slash -
| sh("du","-hs", *pp, stderr=open(os.devnull), stdout=sys.stdout)
: rundu -hs
on all paths. Print directly to stdout, and ignore stderr
Requires xmgrace
program
env PYTHONUNBUFFERED=1 piep -m itertools -m time \
-e PID=$(pgrep 'process-name') \
-e 'START=time.time()' \
-e 'def delay(n,x): time.sleep(n); return x' -n \
'pp = itertools.repeat(None) | delay(1,time.time()) \
| x = int(p - START) | y = sh("ps","-o","rss=","-p", str(PID)) \
| y = int(str(y)) / 1000 \
| ["g0.s0 point {}, {}".format(x,y), "autoscale", "redraw"] \
| pp.merge() \
| itertools.chain(["yaxis label \"RSS (mb)\"", "xaxis label \"time (s)\""], pp)' \
| xmgrace -barebones -dpipe -
Explanation:
- Command line:
-
env PYTHONUNBUFFERED=1
: write each output line immediately -
piep -m itertools -m time
: importitertools
andtime
modules -
-e PID=$(pgrep 'process-name')
: lookup PID for the given process name (you can also just use a raw number if you know it) -
-e 'START=time.time()'
: setSTART
time (seconds) -
-e 'def delay(n,x): time.sleep(n); return x'
: create a small helper function which sleeps before returning the given value -
-n
: no-input (this is a self-constructing pipe) - Pipeline:
-
pp = itertools.repeat(None)
: create an infinite stream ofNone
elements -
| delay(1,time.time())
: Sleep for 1 second and then return the current time -
| x = int(p - START)
: Setx
to the seconds since monitoring started -
| y = sh("ps","-o","rss=","-p", str(PID))
: Sety
to the current memory usage (rss
) of the targetpid
-
| y = int(str(y)) / 1000
: convertps
output into a number, and divide it by 1000 to getmb
-
| ["g0.s0 point {}, {}".format(x,y), "autoscale", "redraw"]
: format eachx
&y
value for thexmgrace
program, including instructions to rescale & redraw the graph after each point -
| pp.merge()
: Merge each array value into one long sequence -
| itertools.chain(["yaxis label \"RSS (mb)\"", "xaxis label \"time (s)\""], pp)'
: prefix the output with a header to set axis labels - Graphing:
-
| xmgrace -barebones -dpipe -
: pipe everything intoxmgrace
, which will do the actual graphing