Rev 4013: (jam) Add a -Dmemory implementation for win32 in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Feb 18 04:41:45 GMT 2009


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 4013
revision-id: pqm at pqm.ubuntu.com-20090218044142-j5oegz3puzoi82m1
parent: pqm at pqm.ubuntu.com-20090218040347-uw2nm8ix8udwditt
parent: john at arbash-meinel.com-20090218033847-e5th2txcqscbe4uv
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2009-02-18 04:41:42 +0000
message:
  (jam) Add a -Dmemory implementation for win32
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/trace.py                trace.py-20050309040759-c8ed824bdcd4748a
  bzrlib/win32utils.py           win32console.py-20051021033308-123c6c929d04973d
    ------------------------------------------------------------
    revno: 4011.1.3
    revision-id: john at arbash-meinel.com-20090218033847-e5th2txcqscbe4uv
    parent: john at arbash-meinel.com-20090218032811-cbuu15u5xobpltv9
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: win32_mem
    timestamp: Tue 2009-02-17 21:38:47 -0600
    message:
      NEWS about -Dmemory and win32
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 4011.1.2
    revision-id: john at arbash-meinel.com-20090218032811-cbuu15u5xobpltv9
    parent: john at arbash-meinel.com-20090218030943-j3dhzwnijugzim61
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: win32_mem
    timestamp: Tue 2009-02-17 21:28:11 -0600
    message:
      Fix some small bugs, and prefer the ctypes form.
    modified:
      bzrlib/win32utils.py           win32console.py-20051021033308-123c6c929d04973d
    ------------------------------------------------------------
    revno: 4011.1.1
    revision-id: john at arbash-meinel.com-20090218030943-j3dhzwnijugzim61
    parent: pqm at pqm.ubuntu.com-20090216172448-vj35mjoe463c3bk2
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: win32_mem
    timestamp: Tue 2009-02-17 21:09:43 -0600
    message:
      Implement -Dmemory for win32
    modified:
      bzrlib/trace.py                trace.py-20050309040759-c8ed824bdcd4748a
      bzrlib/win32utils.py           win32console.py-20051021033308-123c6c929d04973d
=== modified file 'NEWS'
--- a/NEWS	2009-02-18 00:13:03 +0000
+++ b/NEWS	2009-02-18 04:41:42 +0000
@@ -21,6 +21,9 @@
       options to change the default tree-creation policy of shared
       repositories.  (Matthew Fuller, Marius Kruger, #145033)
 
+    * The ``-Dmemory`` flag now gives memory information on Windows.
+      (John Arbash Meinel)
+
   IMPROVEMENTS:
 
     * ``bzr branch`` now has a ``--no-tree`` option which turns off the

=== modified file 'bzrlib/trace.py'
--- a/bzrlib/trace.py	2009-01-08 17:53:46 +0000
+++ b/bzrlib/trace.py	2009-02-18 03:09:43 +0000
@@ -407,10 +407,18 @@
     pass
 
 
-_short_fields = ('VmPeak', 'VmSize', 'VmRSS')
-
 def debug_memory(message='', short=True):
     """Write out a memory dump."""
+    if sys.platform == 'win32':
+        from bzrlib import win32utils
+        win32utils.debug_memory_win32api(message=message, short=short)
+    else:
+        _debug_memory_proc(message=message, short=short)
+
+
+_short_fields = ('VmPeak', 'VmSize', 'VmRSS')
+
+def _debug_memory_proc(message='', short=True):
     try:
         status_file = file('/proc/%s/status' % os.getpid(), 'rb')
     except IOError:

=== modified file 'bzrlib/win32utils.py'
--- a/bzrlib/win32utils.py	2008-10-27 07:29:32 +0000
+++ b/bzrlib/win32utils.py	2009-02-18 03:28:11 +0000
@@ -97,6 +97,63 @@
 MAX_COMPUTERNAME_LENGTH = 31
 
 
+def debug_memory_win32api(message='', short=True):
+    """Use trace.note() to dump the running memory info."""
+    from bzrlib import trace
+    if has_ctypes:
+        class PROCESS_MEMORY_COUNTERS_EX(ctypes.Structure):
+            """Used by GetProcessMemoryInfo"""
+            _fields_ = [('cb', ctypes.c_ulong),
+                        ('PageFaultCount', ctypes.c_ulong),
+                        ('PeakWorkingSetSize', ctypes.c_size_t),
+                        ('WorkingSetSize', ctypes.c_size_t),
+                        ('QuotaPeakPagedPoolUsage', ctypes.c_size_t),
+                        ('QuotaPagedPoolUsage', ctypes.c_size_t),
+                        ('QuotaPeakNonPagedPoolUsage', ctypes.c_size_t),
+                        ('QuotaNonPagedPoolUsage', ctypes.c_size_t),
+                        ('PagefileUsage', ctypes.c_size_t),
+                        ('PeakPagefileUsage', ctypes.c_size_t),
+                        ('PrivateUsage', ctypes.c_size_t),
+                       ]
+        cur_process = ctypes.windll.kernel32.GetCurrentProcess()
+        mem_struct = PROCESS_MEMORY_COUNTERS_EX()
+        ret = ctypes.windll.psapi.GetProcessMemoryInfo(cur_process,
+            ctypes.byref(mem_struct),
+            ctypes.sizeof(mem_struct))
+        if not ret:
+            trace.note('Failed to GetProcessMemoryInfo()')
+            return
+        info = {'PageFaultCount': mem_struct.PageFaultCount,
+                'PeakWorkingSetSize': mem_struct.PeakWorkingSetSize,
+                'WorkingSetSize': mem_struct.WorkingSetSize,
+                'QuotaPeakPagedPoolUsage': mem_struct.QuotaPeakPagedPoolUsage,
+                'QuotaPagedPoolUsage': mem_struct.QuotaPagedPoolUsage,
+                'QuotaPeakNonPagedPoolUsage': mem_struct.QuotaPeakNonPagedPoolUsage,
+                'QuotaNonPagedPoolUsage': mem_struct.QuotaNonPagedPoolUsage,
+                'PagefileUsage': mem_struct.PagefileUsage,
+                'PeakPagefileUsage': mem_struct.PeakPagefileUsage,
+                'PrivateUsage': mem_struct.PrivateUsage,
+               }
+    elif has_win32api:
+        import win32process
+        # win32process does not return PrivateUsage, because it doesn't use
+        # PROCESS_MEMORY_COUNTERS_EX (it uses the one without _EX).
+        proc = win32process.GetCurrentProcess()
+        info = win32process.GetProcessMemoryInfo(proc)
+    else:
+        trace.note('Cannot debug memory on win32 without ctypes'
+                   ' or win32process')
+        return
+    trace.note('WorkingSize       %8d kB', info['WorkingSetSize'] / 1024)
+    trace.note('PeakWorking       %8d kB', info['PeakWorkingSetSize'] / 1024)
+    if short:
+        return
+    trace.note('PagefileUsage     %8d kB', info.get('PagefileUsage', 0) / 1024)
+    trace.note('PeakPagefileUsage %8d kB', info.get('PeakPagefileUsage', 0) / 1024)
+    trace.note('PrivateUsage      %8d kB', info.get('PrivateUsage', 0) / 1024)
+    trace.note('PageFaultCount    %8d', info.get('PageFaultCount', 0))
+
+
 def get_console_size(defaultx=80, defaulty=25):
     """Return size of current console.
 




More information about the bazaar-commits mailing list