Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | =========== |
michael@0 | 2 | Quick links |
michael@0 | 3 | =========== |
michael@0 | 4 | |
michael@0 | 5 | * `Home page <http://code.google.com/p/psutil>`_ |
michael@0 | 6 | * `Download <http://code.google.com/p/psutil/downloads/list>`_ |
michael@0 | 7 | * `Documentation <http://code.google.com/p/psutil/wiki/Documentation>`_ |
michael@0 | 8 | |
michael@0 | 9 | ======= |
michael@0 | 10 | Summary |
michael@0 | 11 | ======= |
michael@0 | 12 | |
michael@0 | 13 | psutil is a module providing an interface for retrieving information on all |
michael@0 | 14 | running processes and system utilization (CPU, memory, disks, network, users) in |
michael@0 | 15 | a portable way by using Python, implementing many functionalities offered by |
michael@0 | 16 | command line tools such as: **ps, top, df, kill, free, lsof, free, netstat, |
michael@0 | 17 | ifconfig, nice, ionice, iostat, iotop, uptime, pidof, tty, who, taskset, pmap**. |
michael@0 | 18 | |
michael@0 | 19 | It currently supports **Linux**, **Windows**, **OSX**, **FreeBSD**, |
michael@0 | 20 | **Sun Solaris** both **32-bit** and **64-bit** with Python versions from **2.4** |
michael@0 | 21 | to **3.3** by using a single code base. |
michael@0 | 22 | |
michael@0 | 23 | ============== |
michael@0 | 24 | Example usages |
michael@0 | 25 | ============== |
michael@0 | 26 | |
michael@0 | 27 | CPU |
michael@0 | 28 | === |
michael@0 | 29 | |
michael@0 | 30 | >>> import psutil |
michael@0 | 31 | >>> psutil.cpu_times() |
michael@0 | 32 | cputimes(user=3961.46, nice=169.729, system=2150.659, idle=16900.540, |
michael@0 | 33 | iowait=629.509, irq=0.0, softirq=19.422, steal=0.0, guest=0, nice=0.0) |
michael@0 | 34 | >>> |
michael@0 | 35 | >>> for x in range(3): |
michael@0 | 36 | ... psutil.cpu_percent(interval=1) |
michael@0 | 37 | ... |
michael@0 | 38 | 4.0 |
michael@0 | 39 | 5.9 |
michael@0 | 40 | 3.8 |
michael@0 | 41 | >>> |
michael@0 | 42 | >>> for x in range(3): |
michael@0 | 43 | ... psutil.cpu_percent(interval=1, percpu=True) |
michael@0 | 44 | ... |
michael@0 | 45 | [4.0, 6.9] |
michael@0 | 46 | [7.0, 8.5] |
michael@0 | 47 | [1.2, 9.0] |
michael@0 | 48 | >>> |
michael@0 | 49 | >>> for x in range(3): |
michael@0 | 50 | ... psutil.cpu_times_percent(interval=1, percpu=False) |
michael@0 | 51 | ... |
michael@0 | 52 | cpupercent(user=1.5, nice=0.0, system=0.5, idle=96.5, iowait=1.5, irq=0.0, |
michael@0 | 53 | softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0) |
michael@0 | 54 | cpupercent(user=1.0, nice=0.0, system=0.0, idle=99.0, iowait=0.0, irq=0.0, |
michael@0 | 55 | softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0) |
michael@0 | 56 | cpupercent(user=2.0, nice=0.0, system=0.0, idle=98.0, iowait=0.0, irq=0.0, |
michael@0 | 57 | softirq=0.0, steal=0.0, guest=0.0, guest_nice=0.0) |
michael@0 | 58 | |
michael@0 | 59 | Memory |
michael@0 | 60 | ====== |
michael@0 | 61 | |
michael@0 | 62 | >>> psutil.virtual_memory() |
michael@0 | 63 | vmem(total=8374149120L, available=2081050624L, percent=75.1, used=8074080256L, |
michael@0 | 64 | free=300068864L, active=3294920704, inactive=1361616896, buffers=529895424L, |
michael@0 | 65 | cached=1251086336) |
michael@0 | 66 | >>> psutil.swap_memory() |
michael@0 | 67 | swap(total=2097147904L, used=296128512L, free=1801019392L, percent=14.1, |
michael@0 | 68 | sin=304193536, sout=677842944) |
michael@0 | 69 | >>> |
michael@0 | 70 | |
michael@0 | 71 | |
michael@0 | 72 | Disks |
michael@0 | 73 | ===== |
michael@0 | 74 | |
michael@0 | 75 | >>> psutil.disk_partitions() |
michael@0 | 76 | [partition(device='/dev/sda1', mountpoint='/', fstype='ext4', opts='rw,nosuid'), |
michael@0 | 77 | partition(device='/dev/sda2', mountpoint='/home', fstype='ext, opts='rw')] |
michael@0 | 78 | >>> |
michael@0 | 79 | >>> psutil.disk_usage('/') |
michael@0 | 80 | usage(total=21378641920, used=4809781248, free=15482871808, percent=22.5) |
michael@0 | 81 | >>> |
michael@0 | 82 | >>> psutil.disk_io_counters() |
michael@0 | 83 | iostat(read_count=719566, write_count=1082197, read_bytes=18626220032, |
michael@0 | 84 | write_bytes=24081764352, read_time=5023392, write_time=63199568) |
michael@0 | 85 | >>> |
michael@0 | 86 | |
michael@0 | 87 | |
michael@0 | 88 | Network |
michael@0 | 89 | ======= |
michael@0 | 90 | |
michael@0 | 91 | >>> psutil.net_io_counters(pernic=True) |
michael@0 | 92 | {'lo': iostat(bytes_sent=799953745, bytes_recv=799953745, |
michael@0 | 93 | packets_sent=453698, packets_recv=453698), |
michael@0 | 94 | 'eth0': iostat(bytes_sent=734324837, bytes_recv=4163935363, |
michael@0 | 95 | packets_sent=3605828, packets_recv=4096685)} |
michael@0 | 96 | >>> |
michael@0 | 97 | |
michael@0 | 98 | Other system info |
michael@0 | 99 | ================= |
michael@0 | 100 | |
michael@0 | 101 | >>> psutil.get_users() |
michael@0 | 102 | [user(name='giampaolo', terminal='pts/2', host='localhost', started=1340737536.0), |
michael@0 | 103 | user(name='giampaolo', terminal='pts/3', host='localhost', started=1340737792.0)] |
michael@0 | 104 | >>> |
michael@0 | 105 | >>> psutil.get_boot_time() |
michael@0 | 106 | 1365519115.0 |
michael@0 | 107 | |
michael@0 | 108 | |
michael@0 | 109 | Process management |
michael@0 | 110 | ================== |
michael@0 | 111 | |
michael@0 | 112 | >>> import psutil |
michael@0 | 113 | >>> psutil.get_pid_list() |
michael@0 | 114 | [1, 2, 3, 4, 5, 6, 7, 46, 48, 50, 51, 178, 182, 222, 223, 224, |
michael@0 | 115 | 268, 1215, 1216, 1220, 1221, 1243, 1244, 1301, 1601, 2237, 2355, |
michael@0 | 116 | 2637, 2774, 3932, 4176, 4177, 4185, 4187, 4189, 4225, 4243, 4245, |
michael@0 | 117 | 4263, 4282, 4306, 4311, 4312, 4313, 4314, 4337, 4339, 4357, 4358, |
michael@0 | 118 | 4363, 4383, 4395, 4408, 4433, 4443, 4445, 4446, 5167, 5234, 5235, |
michael@0 | 119 | 5252, 5318, 5424, 5644, 6987, 7054, 7055, 7071] |
michael@0 | 120 | >>> |
michael@0 | 121 | >>> p = psutil.Process(7055) |
michael@0 | 122 | >>> p.name |
michael@0 | 123 | 'python' |
michael@0 | 124 | >>> p.exe |
michael@0 | 125 | '/usr/bin/python' |
michael@0 | 126 | >>> p.getcwd() |
michael@0 | 127 | '/home/giampaolo' |
michael@0 | 128 | >>> p.cmdline |
michael@0 | 129 | ['/usr/bin/python', 'main.py'] |
michael@0 | 130 | >>> |
michael@0 | 131 | >>> str(p.status) |
michael@0 | 132 | 'running' |
michael@0 | 133 | >>> p.username |
michael@0 | 134 | 'giampaolo' |
michael@0 | 135 | >>> p.create_time |
michael@0 | 136 | 1267551141.5019531 |
michael@0 | 137 | >>> p.terminal |
michael@0 | 138 | '/dev/pts/0' |
michael@0 | 139 | >>> |
michael@0 | 140 | >>> p.uids |
michael@0 | 141 | user(real=1000, effective=1000, saved=1000) |
michael@0 | 142 | >>> p.gids |
michael@0 | 143 | group(real=1000, effective=1000, saved=1000) |
michael@0 | 144 | >>> |
michael@0 | 145 | >>> p.get_cpu_times() |
michael@0 | 146 | cputimes(user=1.02, system=0.31) |
michael@0 | 147 | >>> p.get_cpu_percent(interval=1.0) |
michael@0 | 148 | 12.1 |
michael@0 | 149 | >>> p.get_cpu_affinity() |
michael@0 | 150 | [0, 1, 2, 3] |
michael@0 | 151 | >>> p.set_cpu_affinity([0]) |
michael@0 | 152 | >>> |
michael@0 | 153 | >>> p.get_memory_percent() |
michael@0 | 154 | 0.63423 |
michael@0 | 155 | >>> |
michael@0 | 156 | >>> p.get_memory_info() |
michael@0 | 157 | meminfo(rss=7471104, vms=68513792) |
michael@0 | 158 | >>> p.get_ext_memory_info() |
michael@0 | 159 | meminfo(rss=9662464, vms=49192960, shared=3612672, text=2564096, lib=0, data=5754880, dirty=0) |
michael@0 | 160 | >>> p.get_memory_maps() |
michael@0 | 161 | [mmap(path='/lib/x86_64-linux-gnu/libutil-2.15.so', rss=16384, anonymous=8192, swap=0), |
michael@0 | 162 | mmap(path='/lib/x86_64-linux-gnu/libc-2.15.so', rss=6384, anonymous=15, swap=0), |
michael@0 | 163 | mmap(path='/lib/x86_64-linux-gnu/libcrypto.so.1.0.0', rss=34124, anonymous=1245, swap=0), |
michael@0 | 164 | mmap(path='[heap]', rss=54653, anonymous=8192, swap=0), |
michael@0 | 165 | mmap(path='[stack]', rss=1542, anonymous=166, swap=0), |
michael@0 | 166 | ...] |
michael@0 | 167 | >>> |
michael@0 | 168 | >>> p.get_io_counters() |
michael@0 | 169 | io(read_count=478001, write_count=59371, read_bytes=700416, write_bytes=69632) |
michael@0 | 170 | >>> |
michael@0 | 171 | >>> p.get_open_files() |
michael@0 | 172 | [openfile(path='/home/giampaolo/svn/psutil/somefile', fd=3)] |
michael@0 | 173 | >>> |
michael@0 | 174 | >>> p.get_connections() |
michael@0 | 175 | [connection(fd=115, family=2, type=1, laddr=('10.0.0.1', 48776), |
michael@0 | 176 | raddr=('93.186.135.91', 80), status='ESTABLISHED'), |
michael@0 | 177 | connection(fd=117, family=2, type=1, laddr=('10.0.0.1', 43761), |
michael@0 | 178 | raddr=('72.14.234.100', 80), status='CLOSING'), |
michael@0 | 179 | connection(fd=119, family=2, type=1, laddr=('10.0.0.1', 60759), |
michael@0 | 180 | raddr=('72.14.234.104', 80), status='ESTABLISHED'), |
michael@0 | 181 | connection(fd=123, family=2, type=1, laddr=('10.0.0.1', 51314), |
michael@0 | 182 | raddr=('72.14.234.83', 443), status='SYN_SENT')] |
michael@0 | 183 | >>> |
michael@0 | 184 | >>> p.get_num_threads() |
michael@0 | 185 | 4 |
michael@0 | 186 | >>> p.get_num_fds() |
michael@0 | 187 | 8 |
michael@0 | 188 | >>> p.get_threads() |
michael@0 | 189 | [thread(id=5234, user_time=22.5, system_time=9.2891), |
michael@0 | 190 | thread(id=5235, user_time=0.0, system_time=0.0), |
michael@0 | 191 | thread(id=5236, user_time=0.0, system_time=0.0), |
michael@0 | 192 | thread(id=5237, user_time=0.0707, system_time=1.1)] |
michael@0 | 193 | >>> |
michael@0 | 194 | >>> p.get_num_ctx_switches() |
michael@0 | 195 | amount(voluntary=78, involuntary=19) |
michael@0 | 196 | >>> |
michael@0 | 197 | >>> p.get_nice() |
michael@0 | 198 | 0 |
michael@0 | 199 | >>> p.set_nice(10) |
michael@0 | 200 | >>> |
michael@0 | 201 | >>> p.suspend() |
michael@0 | 202 | >>> p.resume() |
michael@0 | 203 | >>> |
michael@0 | 204 | >>> p.terminate() |
michael@0 | 205 | >>> p.wait(timeout=3) |
michael@0 | 206 | 0 |
michael@0 | 207 | >>> |
michael@0 | 208 | >>> psutil.test() |
michael@0 | 209 | USER PID %CPU %MEM VSZ RSS TTY START TIME COMMAND |
michael@0 | 210 | root 1 0.0 0.0 24584 2240 ? Jun17 00:00 init |
michael@0 | 211 | root 2 0.0 0.0 0 0 ? Jun17 00:00 kthreadd |
michael@0 | 212 | root 3 0.0 0.0 0 0 ? Jun17 00:05 ksoftirqd/0 |
michael@0 | 213 | ... |
michael@0 | 214 | giampaolo 31475 0.0 0.0 20760 3024 /dev/pts/0 Jun19 00:00 python2.4 |
michael@0 | 215 | giampaolo 31721 0.0 2.2 773060 181896 ? 00:04 10:30 chrome |
michael@0 | 216 | root 31763 0.0 0.0 0 0 ? 00:05 00:00 kworker/0:1 |
michael@0 | 217 | >>> |