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

Unified Diff: third_party/psutil/psutil/_psbsd.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: Disable Mac builds. 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/_psbsd.py
diff --git a/third_party/psutil/psutil/_psbsd.py b/third_party/psutil/psutil/_psbsd.py
index b437a6a500445e727e7384ac22e87abf594e9ed7..63def97a50e4e56ac8fb8cdb5d3cb0c61641b529 100644
--- a/third_party/psutil/psutil/_psbsd.py
+++ b/third_party/psutil/psutil/_psbsd.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# $Id: _psbsd.py 1142 2011-10-05 18:45:49Z g.rodola $
+# $Id: _psbsd.py 1206 2011-10-26 21:13:51Z 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
@@ -59,6 +59,23 @@ def get_system_per_cpu_times():
item = _cputimes_ntuple(user, nice, system, idle, irq)
ret.append(item)
return ret
+
+# XXX
+# Ok, this is very dirty.
+# On FreeBSD < 8 we cannot gather per-cpu information, see:
+# http://code.google.com/p/psutil/issues/detail?id=226
+# If NUM_CPUS > 1, on first call we return single cpu times to avoid a
+# crash at psutil import time.
+# Next calls will fail with NotImplementedError
+if not hasattr(_psutil_bsd, "get_system_per_cpu_times"):
+ def get_system_per_cpu_times():
+ if NUM_CPUS == 1:
+ return [get_system_cpu_times]
+ if get_system_per_cpu_times.__called__:
+ raise NotImplementedError("supported only starting from FreeBSD 8")
+ get_system_per_cpu_times.__called__ = True
+ return [get_system_cpu_times]
+get_system_per_cpu_times.__called__ = False
def disk_partitions(all=False):
retlist = []
@@ -78,7 +95,8 @@ def disk_partitions(all=False):
get_pid_list = _psutil_bsd.get_pid_list
pid_exists = _psposix.pid_exists
get_disk_usage = _psposix.get_disk_usage
-network_io_counters = _psutil_osx.get_network_io_counters
+network_io_counters = _psutil_bsd.get_network_io_counters
+disk_io_counters = _psutil_bsd.get_disk_io_counters
def wrap_exceptions(method):
@@ -145,6 +163,13 @@ class Process(object):
"""Return process parent pid."""
return _psutil_bsd.get_process_ppid(self.pid)
+ # XXX - available on FreeBSD >= 8 only
+ if hasattr(_psutil_bsd, "get_process_cwd"):
+ @wrap_exceptions
+ def get_process_cwd(self):
+ """Return process current working directory."""
+ return _psutil_bsd.get_process_cwd(self.pid)
+
@wrap_exceptions
def get_process_uids(self):
"""Return real, effective and saved user ids."""
@@ -190,17 +215,32 @@ class Process(object):
retlist.append(ntuple)
return retlist
+ @wrap_exceptions
def get_open_files(self):
- """Return files opened by process by parsing lsof output."""
- lsof = _psposix.LsofParser(self.pid, self._process_name)
- return lsof.get_process_open_files()
-
- def get_connections(self):
+ """Return files opened by process as a list of namedtuples."""
+ # XXX - C implementation available on FreeBSD >= 8 only
+ # else fallback on lsof parser
+ if hasattr(_psutil_bsd, "get_process_open_files"):
+ rawlist = _psutil_bsd.get_process_open_files(self.pid)
+ return [ntuple_openfile(path, fd) for path, fd in rawlist]
+ else:
+ lsof = _psposix.LsofParser(self.pid, self._process_name)
+ return lsof.get_process_open_files()
+
+ def get_connections(self, kind='inet'):
"""Return network connections opened by a process as a list of
namedtuples by parsing lsof output.
"""
+ if kind not in conn_tmap:
+ raise ValueError("invalid %r kind argument; choose between %s"
+ % (kind, ', '.join([repr(x) for x in conn_tmap])))
+ families, types = conn_tmap[kind]
+ ret = []
lsof = _psposix.LsofParser(self.pid, self._process_name)
- return lsof.get_process_connections()
+ for conn in lsof.get_process_connections():
+ if conn.family in families and conn.type in types:
+ ret.append(conn)
+ return ret
@wrap_exceptions
def process_wait(self, timeout=None):

Powered by Google App Engine
This is Rietveld 408576698