Upgrade to Pro — share decks privately, control downloads, hide ads and more …

PSI - Python System Information - MelbournePUG ...

PSI - Python System Information - MelbournePUG Lightning Talk

Introduces PSI, the open source Python System Information project I had been working on.

Presented as a lightning talk at MelbournePUG, August 2009

Chris Miles

August 11, 2009
Tweet

More Decks by Chris Miles

Other Decks in Programming

Transcript

  1. 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 An API to provide a consistent interface to system information across all supported platforms Wednesday, 12 August 2009
  2. PSI GOALS Common API across all supported platforms Direct interface

    to system information Snapshot of run-time statistics Unit tests Wednesday, 12 August 2009
  3. PSI HISTORY Created by Chris Miles in Nov 2006 First

    public release in Sept 2007 supporting OS X, Solaris and Linux Mostly stagnent in 2008 Floris Bruynooghe & Erick Tryzelaar joined the project at the start of 2009 and refactored/re-wrote a lot of the core code, fixing bugs & memory leaks and improving the project significantly. Wednesday, 12 August 2009
  4. PSI HISTORY AIX support was added (early 2009) Python 3

    compatibility! (early 2009) Next major release (0.3b1) (May 2009) Source moved from Trac/svn to bitbucket.org & mercurial (May 2009) Wednesday, 12 August 2009
  5. PSI WHAT INFORMATION? Current version: Architecture/platform details System load averages,

    up time & boot time Run-time process information Filesystem usage details Platforms: Solaris, Linux, Mac OS X, AIX Wednesday, 12 August 2009
  6. PSI WHAT INFORMATION? Future versions: CPU usage Memory/swap size and

    usage Network info & I/O statistics Any other info we can pull out of the kernel Wednesday, 12 August 2009
  7. PSI WHAT INFORMATION? Future versions: Enumerate system resources: CPUs, disks,

    peripherals, etc More platforms: Windows, FreeBSD, etc Wednesday, 12 August 2009
  8. PSI >>> import psi >>> a = psi.arch.arch_type() >>> a

    psi.arch.ArchDarwin() >>> a.nodename 'laptop' >>> a.release '9.7.0' >>> a.version 'Darwin Kernel Version 9.7.0: Tue Mar 31 22:52:17 PDT 2009; root:xnu-1228.12.14~1/RELEASE_I386' >>> a.machine 'i386' Wednesday, 12 August 2009
  9. PSI >>> p = psi.process.Process(60983) >>> p.command 'python3.0' >>> p.exe

    '/usr/local/bin/python3.0' >>> p.args ('python3.0',) >>> p.ruid 501L >>> p.start_time psi.TimeSpec(tv_sec=1249292691, tv_nsec=630663000) >>> "%0.1f MB" % (p.rss/1024.0/1024.0) '8.2 MB' >>> "%0.1f MB" % (p.vsz/1024.0/1024.0) '80.5 MB' Wednesday, 12 August 2009
  10. PSI >>> ps = psi.process.ProcessTable() >>> len(ps) 144 >>> ps.keys()

    [0L, 1L, 17L, 69136L, 60433L, 18L, 19L, 20L, 21L, 56342L, 23L, 59417L, 28L, 47134L, 47135L, 91L, 60965L, 60454L, 39L, 40L, 44L, 45L, 46L, 75823L, 48L, 49L, 51L, 75828L, 75829L, 54L, 60983L, 74297L, 58L, 59L, … ] >>> p = ps[74297L] >>> p.exe '/System/Library/CoreServices/Dock.app/Contents/MacOS/Dock' >>> p.args ('/System/Library/CoreServices/Dock.app/Contents/MacOS/Dock', '-psn_0_3797919') Wednesday, 12 August 2009
  11. PSI Load Averages: 0.20, 0.22, 0.24 Host: laptop PID #TH

    USER GROUP RSS VSZ %CPU COMMAND 61041 1 root wheel 6500 80760 10.0% Python 305 1 root chris 6616 91820 4.5% pmTool 49902 22 chris chris 52152 567124 3.5% iTerm 57224 7 chris chris 102332 560960 2.7% firefox-bin 300 5 chris chris 5608 526960 2.2% Activity Monitor 56703 20 chris chris 51520 554092 2.0% iTunes 110 5 root wheel 162596 709804 1.9% WindowServer 56974 1 chris chris 10436 459812 0.7% VPNClient 59277 15 chris chris 27460 111956 0.4% python2.4 74297 4 chris chris 24380 525864 0.4% Dock 74343 6 chris chris 10824 439848 0.2% DashboardClient PSITOP Wednesday, 12 August 2009