Slide 1

Slide 1 text

PSI Python System Information Lightning Talk - PyCon UK 2007 Chris Miles

Slide 2

Slide 2 text

PSI WHAT IS IT ? A Python package to provide direct access to run- time system information A Python C extension to extract system information directly from system calls & kernel hooks A module to provide a consistent interface to system information across all supported platforms

Slide 3

Slide 3 text

PSI WHAT INFORMATION? Current version: Architecture/platform details System load averages Run-time process information Snapshot of all processes Platforms: Solaris, Linux, Mac OS X

Slide 4

Slide 4 text

PSI WHAT INFORMATION? Future versions: CPU usage Memory/swap size and usage Network info & I/O statistics Filesystem usage & I/O statistics Any other info we can pull out of the kernel

Slide 5

Slide 5 text

PSI WHAT INFORMATION? Future versions: Enumerate system resources: CPUs, disks, peripherals, etc More platforms: Windows, FreeBSD, etc

Slide 6

Slide 6 text

EXAMPLES

Slide 7

Slide 7 text

PSI >>> import psi >>> a = psi.arch.arch_type() >>> a >>> isinstance(a, psi.arch.ArchDarwin) True >>> a.nodename 'laptop' >>> a.release '8.9.1' >>> a.version 'Darwin Kernel Version 8.9.1: Thu Feb 22 20:55:00 PST 2007; root:xnu-792.18.15~1/RELEASE_I386' >>> a.machine 'i386'

Slide 8

Slide 8 text

PSI >>> p = psi.process.Process(11738) >>> p.command 'Python' >>> p.command_path '/Library/Frameworks/Python.framework/Versions/2.5/ Resources/Python.app/Contents/MacOS/Python' >>> p.user 'chris' >>> p.start_datetime datetime.datetime(2007, 9, 1, 10, 58, 51) >>> p.parent >>> p.parent.command 'bash' >>> "%0.1f MB" % (p.resident_size/1024.0/1024.0) '9.7 MB' >>> "%0.1f MB" % (p.virtual_size/1024.0/1024.0) '43.5 MB'

Slide 9

Slide 9 text

PSI >>> ps = psi.process.ProcessTable() >>> ps.count 115 >>> ps.pids (0, 1, 27, 31, 39, 40, 41, 42, 43, 44, 45, 46, 47, 49, 50, 51, 56, 59, 63, 66, 67, 69, 71, 72, 89, 117, 122, 134, 136, 149, 155, 156, 159, 162, 172, 175, 176, 177, 179, 180, 182, 183, 190, 194, 214, 229, 238, 242, 245, 246, 248, 251, 256, 257, 264, 265, 267, 268, 270, 271, 272, 273, 274, 286, 392, 401, 402, 403, 1135, 1258, 1442, 1589, 1703, 1704, 1705, 1706, 1707, 1708, 1709, 1710, 1712, 1713, 1714, 1715, 1716, 1717, 1718, 1719, 1720, 1721, 2575, 2577, 2578, 2616, 2631, 2632, 9118, 9903, 10159, 10990, 12444, 12596, 13122, 13582, 13840, 13904, 13973, 13974, 13976, 14404, 14579, 14580, 14587, 14627, 14719) >>> p = ps.processes[114] >>> p.command 'TextMate'

Slide 10

Slide 10 text

PSI cmmbp[~/src/psi/psi/trunk/examples] sudo python process_details.py $$ Python 2.5.0 / PSI 0.2a1 / Darwin 8.10.1 Process information: Process ID : 27592 Parent Process ID : 27587 Process name : bash Full command : /bin/bash Process owner : chris (501) Process group : chris (501) Number of threads : 1 Started : 2007-09-07 08:46:14 Status : PROCESS_STATUS_SRUN Flags : PROCESS_FLAG_P_CONTROLT, PROCESS_FLAG_P_EXEC Terminal device : /dev/ttyp1

Slide 11

Slide 11 text

PSI Environment : {'TERM': 'xterm-color', 'SHELL': '/bin/bash', 'SSH_AUTH_SOCK': '/tmp/501/SSHKeychain.socket', 'SECURITYSESSIONID': '888d90', 'GL_RESOURCES': '/usr/libexec/oah/Shims', '__CF_USER_TEXT_ENCODING': '0x1F5:0:0', 'PWD': '/Users/chris', 'CVS_RSH': 'ssh', 'LOGNAME': 'chris', 'USER': 'chris', 'HOME': '/Users/chris', 'PATH': '/usr/bin:/bin:/usr/sbin:/sbin', 'OAH750_CFG_FU_STACK_SIZE': '0', 'TERM_PROGRAM': 'iTerm.app'} CPU Use: CPU seconds used : 0.11 (User: 0.04) (System: 0.07) Recent CPU used : 0.00% Priority : 32 Nice level : 0 Memory Use: Resident memory used: 1988 KB Virtual memory used : 27888 KB

Slide 12

Slide 12 text

PSI PID #TH USER GROUP RSS VSZ %CPU COMMAND 25624 20 chris chris 81500 502188 4.5% Skype 28361 11 chris chris 41460 414188 2.7% Mail 93 4 root wheel 108500 1000368 2.7% WindowServer 28194 15 chris chris 345360 938420 1.8% Google Earth 25623 8 chris chris 43192 464648 0.7% Adium 28527 1 root wheel 39088 72892 0.5% Python 28442 6 chris chris 15876 389696 0.4% iTerm 13303 3 chris chris 5616 387372 0.3% Activity Monitor 381 8 chris chris 31752 447000 0.3% SystemUIServer 27628 8 chris chris 116652 548840 0.2% Safari 23265 14 chris chris 8104 59860 0.1% Python 241 5 root wheel 1264 30496 0.1% automount 81 1 root wheel 476 27252 0.1% update 28521 2 chris wheel 4896 358692 0.0% LAServer

Slide 13

Slide 13 text

PSI http://www.psychofx.com/psi/ GET IT