Commit d0d3b6be by Guba Sándor

delete build folder

parent 8b66e7a7
This file is placed here by pip to indicate the source was put
here by pip.
Once this package is successfully installed this source code will be
deleted (unless you remove this file).
Intro
=====
We would like to recognize some of the people who have been instrumental in the
development of psutil.
I'm sure we are forgetting some people (feel free to email us), but here is a
short list.
It's modeled after the Linux CREDITS file where the fields are:
name (N), e-mail (E), web-address (W), country (C), description (D), (I) issues
(issue tracker is at http://code.google.com/p/psutil/issues/list).
Really thanks to all of you.
Author
======
N: Giampaolo Rodola'
C: Italy
E: g.rodola@gmail.com
W: http://www.linkedin.com/in/grodola
Contributors
============
N: Jay Loden
C: NJ, USA
E: jloden@gmail.com
D: original co-author, initial design/bootstrap and continuing bug fixes
W: http://www.jayloden.com
N: Jeremy Whitlock
E: jcscoobyrs@gmail.com
I: 125, 150, 174, 206
N: wj32
E: wj32.64@gmail.com
D: process username() and get_connections() on Windows
I: 114, 115
N: Yan Raber
C: Bologna, Italy
E: yanraber@gmail.com
D: help on Windows development
N: Justin Venus
E: justin.venus@gmail.com
D: Solaris support
I: 18
N: Dave Daeschler
C: USA
E: david.daeschler@gmail.com
D: initial design/bootstrap and continuing bug fixes
N: cjgohlke
E: cjgohlke@gmail.com
D: Windows 64 bit support
I: 107
N: Jeffery Kline
E: jeffery.kline@gmail.com
I: 130
N: Grabriel Monnerat
E: gabrielmonnerat@gmail.com
I: 146
N: Philip Roberts
E: philip.roberts@gmail.com
I: 168
N: jcscoobyrs
E: jcscoobyrs@gmail.com
I: 125
N: Sandro Tosi
E: sandro.tosi@gmail.com
I: 200, 201
N: Andrew Colin
E: andrew.colin@gmail.com
I: 248
N: Amoser
E: amoser@google.com
I: 266, 267, 340
N: Matthew Grant
E: matthewgrant5@gmail.com
I: 271
N: oweidner
E: oweidner@cct.lsu.edu
I: 275
N: Tarek Ziade
E: ziade.tarek
I: 281
N: Luca Cipriani
C: Turin, Italy
E: luca.opensource@gmail.com
I: 278
N: Maciej Lach,
E: maciej.lach@gmail.com
I: 294
N: James Pye
E: james.pye@gmail.com
I: 305, 306
N: Stanchev Emil
E: stanchev.emil
I: 314
N: Kim Gräsman
E: kim.grasman@gmail.com
D: ...also kindly donated some money.
I: 316
N: Riccardo Murri
C: Italy
I: 318
N: Florent Xicluna
E: florent.xicluna@gmail.com
I: 319
N: Michal Spondr
E: michal.spondr
I: 313
N: Jean Sebastien
E: dumbboules@gmail.com
I: 344
N: Rob Smith
W: http://www.kormoc.com/
I: 341
N: Youngsik Kim
W: https://plus.google.com/101320747613749824490/
I: 317
N: Gregory Szorc
W: https://plus.google.com/116873264322260110710/posts
I: 323
N: André Oriani
E: aoriani@gmail.com
I: 361
N: clackwell
E: clackwell@gmail.com
I: 356
N: m.malycha
E: m.malycha@gmail.com
I: 351
N: John Baldwin
E: jhb@FreeBSD.org
I: 370
N: Jan Beich
E: jbeich@tormail.org
I: 325
N: floppymaster
E: floppymaster@gmail.com
I: 380
N: Arfrever.FTA
E: Arfrever.FTA@gmail.com
I: 369, 404
N: danudey
E: danudey@gmail.com
I: 386
N: Adrien Fallou
I: 224
N: Gisle Vanem
E: gisle.vanem@gmail.com
I: 411
N: thepyr0
E: thepyr0@gmail.com
I: 414
N: John Pankov
E: john.pankov@gmail.com
I: 435
psutil is distributed under BSD license reproduced below.
Copyright (c) 2009, Jay Loden, Dave Daeschler, Giampaolo Rodola'
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the psutil authors nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
include CREDITS
include HISTORY
include LICENSE
include MANIFEST.in
include README
include TODO
include setup.py
recursive-include psutil *.py *.c *.h
recursive-include test *.py
recursive-include examples *.py
===========
Quick links
===========
* `Home page <http://code.google.com/p/psutil>`_
* `Download <https://pypi.python.org/pypi?:action=display&name=psutil#downloads>`_
* `Documentation <http://code.google.com/p/psutil/wiki/Documentation>`_
* `Forum <http://groups.google.com/group/psutil/topics>`_
* `What's new <https://psutil.googlecode.com/hg/HISTORY>`_
=======
Summary
=======
psutil is a module providing an interface for retrieving information on all
running processes and system utilization (CPU, memory, disks, network, users) in
a portable way by using Python, implementing many functionalities offered by
command line tools such as: **ps, top, df, kill, free, lsof, free, netstat,
ifconfig, nice, ionice, iostat, iotop, uptime, pidof, tty, who, taskset, pmap**.
It currently supports **Linux**, **Windows**, **OSX**, **FreeBSD**,
**Sun Solaris** both **32-bit** and **64-bit** with Python versions from **2.4**
to **3.3** by using a single code base.
==============
Example usages
==============
CPU
===
>>> import psutil
>>> psutil.cpu_times()
cputimes(user=3961.46, nice=169.729, system=2150.659, idle=16900.540,
iowait=629.509, irq=0.0, softirq=19.422, steal=0.0, guest=0, nice=0.0)
>>>
>>> for x in range(3):
... psutil.cpu_percent(interval=1)
...
4.0
5.9
3.8
>>>
>>> for x in range(3):
... psutil.cpu_percent(interval=1, percpu=True)
...
[4.0, 6.9]
[7.0, 8.5]
[1.2, 9.0]
>>>
>>> for x in range(3):
... psutil.cpu_times_percent(interval=1, percpu=False)
...
cpupercent(user=1.5, nice=0.0, system=0.5, idle=96.5, iowait=1.5, irq=0.0,
softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
cpupercent(user=1.0, nice=0.0, system=0.0, idle=99.0, iowait=0.0, irq=0.0,
softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
cpupercent(user=2.0, nice=0.0, system=0.0, idle=98.0, iowait=0.0, irq=0.0,
softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0)
Memory
======
>>> psutil.virtual_memory()
vmem(total=8374149120L, available=2081050624L, percent=75.1, used=8074080256L,
free=300068864L, active=3294920704, inactive=1361616896, buffers=529895424L,
cached=1251086336)
>>> psutil.swap_memory()
swap(total=2097147904L, used=296128512L, free=1801019392L, percent=14.1,
sin=304193536, sout=677842944)
>>>
Disks
=====
>>> psutil.disk_partitions()
[partition(device='/dev/sda1', mountpoint='/', fstype='ext4', opts='rw,nosuid'),
partition(device='/dev/sda2', mountpoint='/home', fstype='ext, opts='rw')]
>>>
>>> psutil.disk_usage('/')
usage(total=21378641920, used=4809781248, free=15482871808, percent=22.5)
>>>
>>> psutil.disk_io_counters()
iostat(read_count=719566, write_count=1082197, read_bytes=18626220032,
write_bytes=24081764352, read_time=5023392, write_time=63199568)
>>>
Network
=======
>>> psutil.net_io_counters(pernic=True)
{'lo': iostat(bytes_sent=799953745, bytes_recv=799953745,
packets_sent=453698, packets_recv=453698),
'eth0': iostat(bytes_sent=734324837, bytes_recv=4163935363,
packets_sent=3605828, packets_recv=4096685)}
>>>
Other system info
=================
>>> psutil.get_users()
[user(name='giampaolo', terminal='pts/2', host='localhost', started=1340737536.0),
user(name='giampaolo', terminal='pts/3', host='localhost', started=1340737792.0)]
>>>
>>> psutil.get_boot_time()
1365519115.0
Process management
==================
>>> import psutil
>>> psutil.get_pid_list()
[1, 2, 3, 4, 5, 6, 7, 46, 48, 50, 51, 178, 182, 222, 223, 224,
268, 1215, 1216, 1220, 1221, 1243, 1244, 1301, 1601, 2237, 2355,
2637, 2774, 3932, 4176, 4177, 4185, 4187, 4189, 4225, 4243, 4245,
4263, 4282, 4306, 4311, 4312, 4313, 4314, 4337, 4339, 4357, 4358,
4363, 4383, 4395, 4408, 4433, 4443, 4445, 4446, 5167, 5234, 5235,
5252, 5318, 5424, 5644, 6987, 7054, 7055, 7071]
>>>
>>> p = psutil.Process(7055)
>>> p.name
'python'
>>> p.exe
'/usr/bin/python'
>>> p.getcwd()
'/home/giampaolo'
>>> p.cmdline
['/usr/bin/python', 'main.py']
>>>
>>> str(p.status)
'running'
>>> p.username
'giampaolo'
>>> p.create_time
1267551141.5019531
>>> p.terminal
'/dev/pts/0'
>>>
>>> p.uids
user(real=1000, effective=1000, saved=1000)
>>> p.gids
group(real=1000, effective=1000, saved=1000)
>>>
>>> p.get_cpu_times()
cputimes(user=1.02, system=0.31)
>>> p.get_cpu_percent(interval=1.0)
12.1
>>> p.get_cpu_affinity()
[0, 1, 2, 3]
>>> p.set_cpu_affinity([0])
>>>
>>> p.get_memory_percent()
0.63423
>>>
>>> p.get_memory_info()
meminfo(rss=7471104, vms=68513792)
>>> p.get_ext_memory_info()
meminfo(rss=9662464, vms=49192960, shared=3612672, text=2564096, lib=0, data=5754880, dirty=0)
>>> p.get_memory_maps()
[mmap(path='/lib/x86_64-linux-gnu/libutil-2.15.so', rss=16384, anonymous=8192, swap=0),
mmap(path='/lib/x86_64-linux-gnu/libc-2.15.so', rss=6384, anonymous=15, swap=0),
mmap(path='/lib/x86_64-linux-gnu/libcrypto.so.1.0.0', rss=34124, anonymous=1245, swap=0),
mmap(path='[heap]', rss=54653, anonymous=8192, swap=0),
mmap(path='[stack]', rss=1542, anonymous=166, swap=0),
...]
>>>
>>> p.get_io_counters()
io(read_count=478001, write_count=59371, read_bytes=700416, write_bytes=69632)
>>>
>>> p.get_open_files()
[openfile(path='/home/giampaolo/svn/psutil/somefile', fd=3)]
>>>
>>> p.get_connections()
[connection(fd=115, family=2, type=1, laddr=('10.0.0.1', 48776),
raddr=('93.186.135.91', 80), status='ESTABLISHED'),
connection(fd=117, family=2, type=1, laddr=('10.0.0.1', 43761),
raddr=('72.14.234.100', 80), status='CLOSING'),
connection(fd=119, family=2, type=1, laddr=('10.0.0.1', 60759),
raddr=('72.14.234.104', 80), status='ESTABLISHED'),
connection(fd=123, family=2, type=1, laddr=('10.0.0.1', 51314),
raddr=('72.14.234.83', 443), status='SYN_SENT')]
>>>
>>> p.get_num_threads()
4
>>> p.get_num_fds()
8
>>> p.get_threads()
[thread(id=5234, user_time=22.5, system_time=9.2891),
thread(id=5235, user_time=0.0, system_time=0.0),
thread(id=5236, user_time=0.0, system_time=0.0),
thread(id=5237, user_time=0.0707, system_time=1.1)]
>>>
>>> p.get_num_ctx_switches()
amount(voluntary=78, involuntary=19)
>>>
>>> p.get_nice()
0
>>> p.set_nice(10)
>>>
>>> p.set_ionice(psutil.IOPRIO_CLASS_IDLE) # IO priority (Windows and Linux only)
>>> p.get_ionice()
ionice(ioclass=3, value=0)
>>>
>>> p.set_rlimit(psutil.RLIMIT_NOFILE, (5, 5)) # resource limits (Linux only)
>>> p.get_rlimit(psutil.RLIMIT_NOFILE)
(5, 5)
>>>
>>> p.suspend()
>>> p.resume()
>>>
>>> p.terminate()
>>> p.wait(timeout=3)
0
>>>
>>> psutil.test()
USER PID %CPU %MEM VSZ RSS TTY START TIME COMMAND
root 1 0.0 0.0 24584 2240 ? Jun17 00:00 init
root 2 0.0 0.0 0 0 ? Jun17 00:00 kthreadd
root 3 0.0 0.0 0 0 ? Jun17 00:05 ksoftirqd/0
...
giampaolo 31475 0.0 0.0 20760 3024 /dev/pts/0 Jun19 00:00 python2.4
giampaolo 31721 0.0 2.2 773060 181896 ? 00:04 10:30 chrome
root 31763 0.0 0.0 0 0 ? 00:05 00:00 kworker/0:1
>>>
TODO
====
A collection of ideas and notes about stuff to implement in future versions.
"#NNN" occurrences refer to bug tracker issues at:
https://code.google.com/p/psutil/issues/list
HIGHER PRIORITY
===============
* #387: system-wide connections (netstat).
* OpenBSD support.
* #371: CPU temperature (apparently OSX and Linux only; on Linux it requires
lm-sensors lib).
* #250: net ifaces speed.
* Process.name on Windows is slow:
http://stackoverflow.com/questions/6587036/
* Windows binary for Python 3.3 64-bit.
* #269: expose network ifaces RX/TW queues.
LOWER PRIORITY
==============
* #355: Android support.
* #276: GNU/Hurd support.
* NetBSD support?
* DranflyBSD support?
* AIX support?
* examples/pidof.py (same as 'pidof' cli tool)
* examples/pstree.py (same as 'pstree' cli tool)
* get_threads() should also return thread names in order to implement it
* examples/taskmgr-gui.py (using tk).
* system-wide # open file descriptors:
* https://jira.hyperic.com/browse/SIGAR-30
* http://www.netadmintools.com/part295.html
* Number of system threads.
* Windows: http://msdn.microsoft.com/en-us/library/windows/desktop/ms684824(v=vs.85).aspx
* #357: what CPU a process is on.
* thread names:
* https://code.google.com/p/plcrashreporter/issues/detail?id=65
DEBATABLE
=========
* [Linux]: process cgroups (http://en.wikipedia.org/wiki/Cgroups). They look
similar to prlimit() in terms of functionality but uglier (they should allow
limiting per-process network IO resources though, which is great). Needs
further reading.
* cpu_percent(): current default interval is 0.1 so that by default it will
produce a meaningful value. It represents a trap in case the user iterates
over multiple processes though, as it introduces a big slowdown.
Should it default to 0.0?
* Rename connection ntuple's fields 'local_address', 'remote_address' to
'laddr', 'raddr' (note in accordance with http://bugs.python.org/issue17675)
* Process per-cpus percent (XXX Windows only?), see:
https://groups.google.com/forum/?fromgroups#!topic/psutil/ErrKTxAbu50
* Should we expose OS constants (psutil.WINDOWS, psutil.OSX etc.)?
* Python 3.3. exposed different sched.h functions:
http://docs.python.org/dev/whatsnew/3.3.html#os
http://bugs.python.org/issue12655
http://docs.python.org/dev/library/os.html#interface-to-the-scheduler
It might be worth to take a look and figure out whether we can include some
of those in psutil.
Also, we can probably reimplement wait_pid() on POSIX which is currently
implemented as a busy-loop.
* Certain systems (XXX figure out which ones exactly) provide CPU times about
process children. On those systems Process.get_cpu_times() might return
a (user, system, user_children, system_children) ntuple.
* Enrich exception classes hierarchy on Python >= 3.3 / post PEP-3151 so that:
- NoSuchProcess inherits from ProcessLookupError
- AccessDenied inherits from PermissionError
- TimeoutExpired inherits from TimeoutError (debatable)
See: http://docs.python.org/3/library/exceptions.html#os-exceptions
* Process.get_threads() might grow an extra "id" parameter so that it can be
used as such:
>>> p = psutil.Process(pid)
>>> p.get_threads(id=psutil.get_current_thread_id())
thread(id=2539, user_time=0.03, system_time=0.02)
>>>
note: this leads to questions such as "should we have a custom NoSuchThread
exception? Also see issue #418.
* should psutil.TimeoutExpired exception have a 'msg' kwarg similar to
NoSuchProcess and AccessDenied? Not that we need it, but currently we
cannot raise a TimeoutExpired exception with a specific error string.
Side note: tests' call_until() should raise TimeoutExpired instead of
RuntimeError.
#/usr/bin/env python
# Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Common objects shared by all _ps* modules."""
from __future__ import division
import sys
import os
import stat
import errno
import warnings
from psutil._compat import namedtuple, long, wraps
# --- functions
def usage_percent(used, total, _round=None):
"""Calculate percentage usage of 'used' against 'total'."""
try:
ret = (used / total) * 100
except ZeroDivisionError:
ret = 0
if _round is not None:
return round(ret, _round)
else:
return ret
def memoize(f):
"""A simple memoize decorator for functions."""
cache= {}
def memf(*x):
if x not in cache:
cache[x] = f(*x)
return cache[x]
return memf
class cached_property(object):
"""A memoize decorator for class properties."""
enabled = True
def __init__(self, func):
self.func = func
def __get__(self, instance, type):
ret = self.func(instance)
if self.enabled:
instance.__dict__[self.func.__name__] = ret
return ret
# http://goo.gl/jYLvf
def deprecated(replacement=None):
"""A decorator which can be used to mark functions as deprecated."""
def outer(fun):
msg = "psutil.%s is deprecated" % fun.__name__
if replacement is not None:
msg += "; use %s instead" % replacement
if fun.__doc__ is None:
fun.__doc__ = msg
@wraps(fun)
def inner(*args, **kwargs):
warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
return fun(*args, **kwargs)
return inner
return outer
def isfile_strict(path):
"""Same as os.path.isfile() but does not swallow EACCES / EPERM
exceptions, see:
http://mail.python.org/pipermail/python-dev/2012-June/120787.html
"""
try:
st = os.stat(path)
except OSError:
err = sys.exc_info()[1]
if err.errno in (errno.EPERM, errno.EACCES):
raise
return False
else:
return stat.S_ISREG(st.st_mode)
# --- constants
STATUS_RUNNING = "running"
STATUS_SLEEPING = "sleeping"
STATUS_DISK_SLEEP = "disk-sleep"
STATUS_STOPPED = "stopped"
STATUS_TRACING_STOP = "tracing-stop"
STATUS_ZOMBIE = "zombie"
STATUS_DEAD = "dead"
STATUS_WAKE_KILL = "wake-kill"
STATUS_WAKING = "waking"
STATUS_IDLE = "idle" # BSD
STATUS_LOCKED = "locked" # BSD
STATUS_WAITING = "waiting" # BSD
CONN_ESTABLISHED = "ESTABLISHED"
CONN_SYN_SENT = "SYN_SENT"
CONN_SYN_RECV = "SYN_RECV"
CONN_FIN_WAIT1 = "FIN_WAIT1"
CONN_FIN_WAIT2 = "FIN_WAIT2"
CONN_TIME_WAIT = "TIME_WAIT"
CONN_CLOSE = "CLOSE"
CONN_CLOSE_WAIT = "CLOSE_WAIT"
CONN_LAST_ACK = "LAST_ACK"
CONN_LISTEN = "LISTEN"
CONN_CLOSING = "CLOSING"
CONN_NONE = "NONE"
# --- Process.get_connections() 'kind' parameter mapping
import socket
from socket import AF_INET, SOCK_STREAM, SOCK_DGRAM
AF_INET6 = getattr(socket, 'AF_INET6', None)
AF_UNIX = getattr(socket, 'AF_UNIX', None)
conn_tmap = {
"all" : ([AF_INET, AF_INET6, AF_UNIX], [SOCK_STREAM, SOCK_DGRAM]),
"tcp" : ([AF_INET, AF_INET6], [SOCK_STREAM]),
"tcp4" : ([AF_INET], [SOCK_STREAM]),
"udp" : ([AF_INET, AF_INET6], [SOCK_DGRAM]),
"udp4" : ([AF_INET], [SOCK_DGRAM]),
"inet" : ([AF_INET, AF_INET6], [SOCK_STREAM, SOCK_DGRAM]),
"inet4": ([AF_INET], [SOCK_STREAM, SOCK_DGRAM]),
"inet6": ([AF_INET6], [SOCK_STREAM, SOCK_DGRAM]),
}
if AF_INET6 is not None:
conn_tmap.update({
"tcp6" : ([AF_INET6], [SOCK_STREAM]),
"udp6" : ([AF_INET6], [SOCK_DGRAM]),
})
if AF_UNIX is not None:
conn_tmap.update({
"unix" : ([AF_UNIX], [SOCK_STREAM, SOCK_DGRAM]),
})
del AF_INET, AF_INET6, AF_UNIX, SOCK_STREAM, SOCK_DGRAM, socket
# --- namedtuples
# system
nt_sysmeminfo = namedtuple('usage', 'total used free percent')
# XXX - would 'available' be better than 'free' as for virtual_memory() nt?
nt_swapmeminfo = namedtuple('swap', 'total used free percent sin sout')
nt_diskinfo = namedtuple('usage', 'total used free percent')
nt_partition = namedtuple('partition', 'device mountpoint fstype opts')
nt_net_iostat = namedtuple('iostat',
'bytes_sent bytes_recv packets_sent packets_recv errin errout dropin dropout')
nt_disk_iostat = namedtuple('iostat', 'read_count write_count read_bytes write_bytes read_time write_time')
nt_user = namedtuple('user', 'name terminal host started')
# processes
nt_meminfo = namedtuple('meminfo', 'rss vms')
nt_cputimes = namedtuple('cputimes', 'user system')
nt_openfile = namedtuple('openfile', 'path fd')
nt_thread = namedtuple('thread', 'id user_time system_time')
nt_uids = namedtuple('user', 'real effective saved')
nt_gids = namedtuple('group', 'real effective saved')
nt_io = namedtuple('io', 'read_count write_count read_bytes write_bytes')
nt_ionice = namedtuple('ionice', 'ioclass value')
nt_ctxsw = namedtuple('amount', 'voluntary involuntary')
class nt_connection(namedtuple('connection',
'fd family type laddr raddr status')):
__slots__ = ()
@property
def local_address(self):
warnings.warn("'local_address' field is deprecated; use 'laddr'" \
"instead", category=DeprecationWarning, stacklevel=2)
return self.laddr
@property