#log# Automatic Logger file. *** THIS MUST BE THE FIRST LINE ***
#log# DO NOT CHANGE THIS LINE OR THE TWO BELOW
#log# opts = Struct({'__allownew': True,
 'logfile': 'ipython_log.py',
 'profile': 'pysh',
 'pylab': 1})
#log# args = []
#log# It is safe to make manual edits below here.
#log#-----------------------------------------------------------------------

# Start IPython with:  ipython -pylab -p pysh
# To replay this file: ipython -pylab -p pysh -logplay <filename>

# Capture some system statistics with "ps".
# Type this at the prompt: $raw=ps --no-headers eo %cpu,vsz,%mem
_ip.magic("%sc raw=ps --no-headers eo %cpu,vsz,%mem ")

# Each row of the array contains the %cpu, vsz and %mem of a process.  
pdata = [[float(ii) for ii in jj.split()] for jj in raw.split('\n')]

# How many processes do we have?
nprocesses = len(pdata)

# Now pdata[0] is %cpu, pdata[1] is vsz, and pdata[2] is %mem.
pdata = transpose(pdata)

# Here is a command (commented out) for a simple scatter graph: the
# higher up the patch, the greater the %cpu; the larger the patch, the
# greater the vsz.  The first argument (variable x) just assigns a
# value from 0 to nprocesses-1 to each process.

#scatter(range(nprocesses), pdata[0], pdata[1], alpha=0.75)

# There is an option to save the plot on the figure window toolbar.
# If you keep the window open, new plots will overlay previous ones.

# What is the maximum %mem value?
maxmem = max(pdata[2])

# A more complex scatter graph. Same as above, but the redder the
# patch, the greater %mem.
scatter(range(32), pdata[0], pdata[1],
        color=[[ii/maxmem, 0, 1.0-ii/maxmem, 0.5] for ii in pdata[2]])

# Put black dots at the centers of the patches.
scatter(range(32), pdata[0], color="black", alpha=0.5)

# Generate a grid.
grid()
