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

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

Issue 8159001: Update third_party/psutil and fix the licence issue with it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove the suppression and unnecessary files. Created 9 years, 2 months 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
« no previous file with comments | « third_party/psutil/psutil/_psmswindows.py ('k') | third_party/psutil/psutil/_psposix.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/psutil/psutil/_psosx.py
diff --git a/third_party/psutil/psutil/_psosx.py b/third_party/psutil/psutil/_psosx.py
index f8c867e611dfe946ef6a02881c8e328b719e1a11..543124c077d3b3ba41de1b65fad12875c1be14d6 100644
--- a/third_party/psutil/psutil/_psosx.py
+++ b/third_party/psutil/psutil/_psosx.py
@@ -1,60 +1,84 @@
#!/usr/bin/env python
#
-# $Id: _psosx.py 794 2010-11-12 13:29:52Z g.rodola $
+# $Id: _psosx.py 1142 2011-10-05 18:45:49Z 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
+# found in the LICENSE file.
+
+"""OSX platform implementation."""
import errno
import os
-try:
- from collections import namedtuple
-except ImportError:
- from psutil.compat import namedtuple # python < 2.6
-
import _psutil_osx
+import _psutil_posix
import _psposix
-from psutil.error import AccessDenied, NoSuchProcess
+from psutil.error import AccessDenied, NoSuchProcess, TimeoutExpired
+from psutil._compat import namedtuple
+from psutil._common import *
+
+__extra__all__ = []
# --- constants
NUM_CPUS = _psutil_osx.get_num_cpus()
-TOTAL_PHYMEM = _psutil_osx.get_total_phymem()
+BOOT_TIME = _psutil_osx.get_system_boot_time()
+_TERMINAL_MAP = _psposix._get_terminal_map()
+_cputimes_ntuple = namedtuple('cputimes', 'user nice system idle')
# --- functions
-def avail_phymem():
- "Return the amount of physical memory available on the system, in bytes."
- return _psutil_osx.get_avail_phymem()
-
-def used_phymem():
- "Return the amount of physical memory currently in use on the system, in bytes."
- return TOTAL_PHYMEM - _psutil_osx.get_avail_phymem()
-
-def total_virtmem():
- "Return the amount of total virtual memory available on the system, in bytes."
- return _psutil_osx.get_total_virtmem()
-
-def avail_virtmem():
- "Return the amount of virtual memory currently in use on the system, in bytes."
- return _psutil_osx.get_avail_virtmem()
-
-def used_virtmem():
- """Return the amount of used memory currently in use on the system, in bytes."""
- return _psutil_osx.get_total_virtmem() - _psutil_osx.get_avail_virtmem()
+def phymem_usage():
+ """Physical system memory as a (total, used, free) tuple."""
+ total = _psutil_osx.get_total_phymem()
+ free = _psutil_osx.get_avail_phymem()
+ used = total - free
+ percent = usage_percent(used, total, _round=1)
+ return ntuple_sysmeminfo(total, used, free, percent)
+
+def virtmem_usage():
+ """Virtual system memory as a (total, used, free) tuple."""
+ total = _psutil_osx.get_total_virtmem()
+ free = _psutil_osx.get_avail_virtmem()
+ used = total - free
+ percent = usage_percent(used, total, _round=1)
+ return ntuple_sysmeminfo(total, used, free, percent)
def get_system_cpu_times():
- """Return a dict representing the following CPU times:
- user, nice, system, idle."""
- values = _psutil_osx.get_system_cpu_times()
- return dict(user=values[0], nice=values[1], system=values[2], idle=values[3])
-
-def get_pid_list():
- """Returns a list of PIDs currently running on the system."""
- return _psutil_osx.get_pid_list()
-
-def pid_exists(pid):
- """Check For the existence of a unix pid."""
- return _psposix.pid_exists(pid)
+ """Return system CPU times as a namedtuple."""
+ user, nice, system, idle = _psutil_osx.get_system_cpu_times()
+ return _cputimes_ntuple(user, nice, system, idle)
+
+def get_system_per_cpu_times():
+ """Return system CPU times as a named tuple"""
+ ret = []
+ for cpu_t in _psutil_osx.get_system_per_cpu_times():
+ user, nice, system, idle = cpu_t
+ item = _cputimes_ntuple(user, nice, system, idle)
+ ret.append(item)
+ return ret
+
+def disk_partitions(all=False):
+ retlist = []
+ partitions = _psutil_osx.get_disk_partitions()
+ for partition in partitions:
+ device, mountpoint, fstype = partition
+ if device == 'none':
+ device = ''
+ if not all:
+ if not os.path.isabs(device) \
+ or not os.path.exists(device):
+ continue
+ ntuple = ntuple_partition(device, mountpoint, fstype)
+ retlist.append(ntuple)
+ return retlist
+
+get_pid_list = _psutil_osx.get_pid_list
+pid_exists = _psposix.pid_exists
+get_disk_usage = _psposix.get_disk_usage
+network_io_counters = _psutil_osx.get_network_io_counters
+disk_io_counters = _psutil_osx.get_disk_io_counters
# --- decorator
@@ -75,11 +99,17 @@ def wrap_exceptions(callable):
return wrapper
-class OSXProcess(object):
+_status_map = {
+ _psutil_osx.SIDL : STATUS_IDLE,
+ _psutil_osx.SRUN : STATUS_RUNNING,
+ _psutil_osx.SSLEEP : STATUS_SLEEPING,
+ _psutil_osx.SSTOP : STATUS_STOPPED,
+ _psutil_osx.SZOMB : STATUS_ZOMBIE,
+}
+
+class Process(object):
"""Wrapper class around underlying C implementation."""
- _meminfo_ntuple = namedtuple('meminfo', 'rss vms')
- _cputimes_ntuple = namedtuple('cputimes', 'user system')
__slots__ = ["pid", "_process_name"]
def __init__(self, pid):
@@ -111,25 +141,33 @@ class OSXProcess(object):
return _psutil_osx.get_process_ppid(self.pid)
@wrap_exceptions
- def get_process_uid(self):
- """Return process real user id."""
- return _psutil_osx.get_process_uid(self.pid)
+ def get_process_uids(self):
+ real, effective, saved = _psutil_osx.get_process_uids(self.pid)
+ return ntuple_uids(real, effective, saved)
@wrap_exceptions
- def get_process_gid(self):
- """Return process real group id."""
- return _psutil_osx.get_process_gid(self.pid)
+ def get_process_gids(self):
+ real, effective, saved = _psutil_osx.get_process_gids(self.pid)
+ return ntuple_gids(real, effective, saved)
+
+ @wrap_exceptions
+ def get_process_terminal(self):
+ tty_nr = _psutil_osx.get_process_tty_nr(self.pid)
+ try:
+ return _TERMINAL_MAP[tty_nr]
+ except KeyError:
+ return None
@wrap_exceptions
def get_memory_info(self):
"""Return a tuple with the process' RSS and VMS size."""
rss, vms = _psutil_osx.get_memory_info(self.pid)
- return self._meminfo_ntuple(rss, vms)
+ return ntuple_meminfo(rss, vms)
@wrap_exceptions
def get_cpu_times(self):
user, system = _psutil_osx.get_cpu_times(self.pid)
- return self._cputimes_ntuple(user, system)
+ return ntuple_cputimes(user, system)
@wrap_exceptions
def get_process_create_time(self):
@@ -142,16 +180,54 @@ class OSXProcess(object):
"""Return the number of threads belonging to the process."""
return _psutil_osx.get_process_num_threads(self.pid)
+ @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()
+ """Return files opened by process."""
+ if self.pid == 0:
+ raise AccessDenied(self.pid, self._process_name)
+ files = []
+ rawlist = _psutil_osx.get_process_open_files(self.pid)
+ for path, fd in rawlist:
+ if os.path.isfile(path):
+ ntuple = ntuple_openfile(path, fd)
+ files.append(ntuple)
+ return files
+ @wrap_exceptions
def get_connections(self):
"""Return etwork connections opened by a process as a list of
namedtuples."""
- lsof = _psposix.LsofParser(self.pid, self._process_name)
- return lsof.get_process_connections()
+ retlist = _psutil_osx.get_process_connections(self.pid)
+ return [ntuple_connection(*conn) for conn in retlist]
+
+ @wrap_exceptions
+ def process_wait(self, timeout=None):
+ try:
+ return _psposix.wait_pid(self.pid, timeout)
+ except TimeoutExpired:
+ raise TimeoutExpired(self.pid, self._process_name)
+
+ @wrap_exceptions
+ def get_process_nice(self):
+ return _psutil_posix.getpriority(self.pid)
+
+ @wrap_exceptions
+ def set_process_nice(self, value):
+ return _psutil_posix.setpriority(self.pid, value)
-PlatformProcess = OSXProcess
+ @wrap_exceptions
+ def get_process_status(self):
+ code = _psutil_osx.get_process_status(self.pid)
+ if code in _status_map:
+ return _status_map[code]
+ return constant(-1, "?")
+ @wrap_exceptions
+ def get_process_threads(self):
+ """Return the number of threads belonging to the process."""
+ rawlist = _psutil_osx.get_process_threads(self.pid)
+ retlist = []
+ for thread_id, utime, stime in rawlist:
+ ntuple = ntuple_thread(thread_id, utime, stime)
+ retlist.append(ntuple)
+ return retlist
« no previous file with comments | « third_party/psutil/psutil/_psmswindows.py ('k') | third_party/psutil/psutil/_psposix.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698