Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Unified Diff: third_party/psutil/psutil/__init__.py

Issue 8774018: Add psutil build step to fix pyauto media issues. Upgrade psutil to 0.4.0. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Replace 'python' w/ sys.executable. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/psutil/psutil/__init__.py
diff --git a/third_party/psutil/psutil/__init__.py b/third_party/psutil/psutil/__init__.py
index 93724fca1a97788acf6dcba48a57d255d329f8cd..4d7d1a4162a4013fd429af525f385985f1af411c 100644
--- a/third_party/psutil/psutil/__init__.py
+++ b/third_party/psutil/psutil/__init__.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# $Id: __init__.py 1142 2011-10-05 18:45:49Z g.rodola $
+# $Id: __init__.py 1182 2011-10-22 11:39:15Z g.rodola $
#
# Copyright (c) 2009, Jay Loden, Giampaolo Rodola'. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
@@ -11,7 +11,7 @@ processes and gather system information in a portable way by using
Python.
"""
-__version__ = "0.3.1"
+__version__ = "0.4.0"
version_info = tuple([int(num) for num in __version__.split('.')])
__all__ = [
@@ -348,9 +348,13 @@ class Process(object):
return 0.0
# the utilization of a single CPU
single_cpu_percent = overall_percent * NUM_CPUS
- # ugly hack to avoid troubles with float precision issues
- if single_cpu_percent > 100.0:
- return 100.0
+ # on posix a percentage > 100 is legitimate
+ # http://stackoverflow.com/questions/1032357/comprehending-top-cpu-usage
+ # on windows we use this ugly hack to avoid troubles with float
+ # precision issues
+ if os.name != 'posix':
+ if single_cpu_percent > 100.0:
+ return 100.0
return round(single_cpu_percent, 1)
def get_cpu_times(self):
@@ -386,13 +390,24 @@ class Process(object):
"""
return self._platform_impl.get_open_files()
- def get_connections(self):
- """Return TCP and UPD connections opened by process as a list
- of namedtuples.
- On BSD and OSX results for third party processes (!= os.getpid())
- can differ depending on user privileges.
+ def get_connections(self, kind='inet'):
+ """Return connections opened by process as a list of namedtuples.
+ The kind parameter filters for connections that fit the following
+ criteria:
+
+ Kind Value Connections using
+ inet IPv4 and IPv6
+ inet4 IPv4
+ inet6 IPv6
+ tcp TCP
+ tcp4 TCP over IPv4
+ tcp6 TCP over IPv6
+ udp UDP
+ udp4 UDP over IPv4
+ udp6 UDP over IPv6
+ all the sum of all the possible families and protocols
"""
- return self._platform_impl.get_connections()
+ return self._platform_impl.get_connections(kind)
def is_running(self):
"""Return whether this process is running."""
@@ -675,68 +690,68 @@ def disk_partitions(all=False):
"""
return _psplatform.disk_partitions(all)
-if hasattr(_psplatform, "network_io_counters"):
+def network_io_counters(pernic=False):
+ """Return network I/O statistics as a namedtuple including
+ the following attributes:
- def network_io_counters(pernic=False):
- """Return network I/O statistics as a namedtuple including:
- - number of bytes sent
- - number of bytes received
- - number of packets sent
- - number of packets received
+ - bytes_sent: number of bytes sent
+ - bytes_recv: number of bytes received
+ - packets_sent: number of packets sent
+ - packets_recv: number of packets received
- If pernic is True return the same information for every
- network interface installed on the system as a dictionary
- with network interface names as the keys and the namedtuple
- described above as the values.
- """
- from psutil._common import ntuple_net_iostat
- rawdict = _psplatform.network_io_counters()
- if pernic:
- for nic, fields in rawdict.iteritems():
- rawdict[nic] = ntuple_net_iostat(*fields)
- return rawdict
- else:
- bytes_sent, bytes_recv, packets_sent, packets_recv = 0, 0, 0, 0
- for _, fields in rawdict.iteritems():
- bytes_sent += fields[0]
- bytes_recv += fields[1]
- packets_sent += fields[2]
- packets_recv += fields[3]
- return ntuple_net_iostat(bytes_sent, bytes_recv,
- packets_sent, packets_recv)
-
-if hasattr(_psplatform, "disk_io_counters"):
-
- def disk_io_counters(perdisk=False):
- """Return system disk I/O statistics as a namedtuple including:
- - number of bytes read
- - number of bytes written
- - number of reads
- - number of writes
- - time spent reading from disk (in nanoseconds)
- - time spent writing to disk (in nanoseconds)
-
- If perdisk is True return the same information for every
- physical disk installed on the system as a dictionary
- with partition names as the keys and the namedutuple
- described above as the values.
- """
- from psutil._common import ntuple_disk_iostat
- rawdict = _psplatform.disk_io_counters()
- if perdisk:
- for disk, fields in rawdict.iteritems():
- rawdict[disk] = ntuple_disk_iostat(*fields)
- return rawdict
- else:
- reads, writes, rbytes, wbytes, rtime, wtime = 0, 0, 0, 0, 0, 0
- for _, fields in rawdict.iteritems():
- reads += fields[0]
- writes += fields[1]
- rbytes += fields[2]
- wbytes += fields[3]
- rtime += fields[4]
- wtime += fields[5]
- return ntuple_disk_iostat(reads, writes, rbytes, wbytes, rtime, wtime)
+ If pernic is True return the same information for every
+ network interface installed on the system as a dictionary
+ with network interface names as the keys and the namedtuple
+ described above as the values.
+ """
+ from psutil._common import ntuple_net_iostat
+ rawdict = _psplatform.network_io_counters()
+ if pernic:
+ for nic, fields in rawdict.iteritems():
+ rawdict[nic] = ntuple_net_iostat(*fields)
+ return rawdict
+ else:
+ bytes_sent, bytes_recv, packets_sent, packets_recv = 0, 0, 0, 0
+ for _, fields in rawdict.iteritems():
+ bytes_sent += fields[0]
+ bytes_recv += fields[1]
+ packets_sent += fields[2]
+ packets_recv += fields[3]
+ return ntuple_net_iostat(bytes_sent, bytes_recv,
+ packets_sent, packets_recv)
+
+def disk_io_counters(perdisk=False):
+ """Return system disk I/O statistics as a namedtuple including
+ the following attributes:
+
+ - read_count: number of reads
+ - write_count: number of writes
+ - read_bytes: number of bytes read
+ - write_bytes: number of bytes written
+ - read_time: time spent reading from disk (in milliseconds)
+ - write_time: time spent writing to disk (in milliseconds)
+
+ If perdisk is True return the same information for every
+ physical disk installed on the system as a dictionary
+ with partition names as the keys and the namedutuple
+ described above as the values.
+ """
+ from psutil._common import ntuple_disk_iostat
+ rawdict = _psplatform.disk_io_counters()
+ if perdisk:
+ for disk, fields in rawdict.iteritems():
+ rawdict[disk] = ntuple_disk_iostat(*fields)
+ return rawdict
+ else:
+ reads, writes, rbytes, wbytes, rtime, wtime = 0, 0, 0, 0, 0, 0
+ for _, fields in rawdict.iteritems():
+ reads += fields[0]
+ writes += fields[1]
+ rbytes += fields[2]
+ wbytes += fields[3]
+ rtime += fields[4]
+ wtime += fields[5]
+ return ntuple_disk_iostat(reads, writes, rbytes, wbytes, rtime, wtime)
def _deprecated(replacement):

Powered by Google App Engine
This is Rietveld 408576698