97
97
MAX_COMPUTERNAME_LENGTH = 31
100
def debug_memory_win32api(message='', short=True):
101
"""Use trace.note() to dump the running memory info."""
102
from bzrlib import trace
104
class PROCESS_MEMORY_COUNTERS_EX(ctypes.Structure):
105
"""Used by GetProcessMemoryInfo"""
106
_fields_ = [('cb', ctypes.c_ulong),
107
('PageFaultCount', ctypes.c_ulong),
108
('PeakWorkingSetSize', ctypes.c_size_t),
109
('WorkingSetSize', ctypes.c_size_t),
110
('QuotaPeakPagedPoolUsage', ctypes.c_size_t),
111
('QuotaPagedPoolUsage', ctypes.c_size_t),
112
('QuotaPeakNonPagedPoolUsage', ctypes.c_size_t),
113
('QuotaNonPagedPoolUsage', ctypes.c_size_t),
114
('PagefileUsage', ctypes.c_size_t),
115
('PeakPagefileUsage', ctypes.c_size_t),
116
('PrivateUsage', ctypes.c_size_t),
118
cur_process = ctypes.windll.kernel32.GetCurrentProcess()
119
mem_struct = PROCESS_MEMORY_COUNTERS_EX()
120
ret = ctypes.windll.psapi.GetProcessMemoryInfo(cur_process,
121
ctypes.byref(mem_struct),
122
ctypes.sizeof(mem_struct))
124
trace.note('Failed to GetProcessMemoryInfo()')
126
info = {'PageFaultCount': mem_struct.PageFaultCount,
127
'PeakWorkingSetSize': mem_struct.PeakWorkingSetSize,
128
'WorkingSetSize': mem_struct.WorkingSetSize,
129
'QuotaPeakPagedPoolUsage': mem_struct.QuotaPeakPagedPoolUsage,
130
'QuotaPagedPoolUsage': mem_struct.QuotaPagedPoolUsage,
131
'QuotaPeakNonPagedPoolUsage': mem_struct.QuotaPeakNonPagedPoolUsage,
132
'QuotaNonPagedPoolUsage': mem_struct.QuotaNonPagedPoolUsage,
133
'PagefileUsage': mem_struct.PagefileUsage,
134
'PeakPagefileUsage': mem_struct.PeakPagefileUsage,
135
'PrivateUsage': mem_struct.PrivateUsage,
139
# win32process does not return PrivateUsage, because it doesn't use
140
# PROCESS_MEMORY_COUNTERS_EX (it uses the one without _EX).
141
proc = win32process.GetCurrentProcess()
142
info = win32process.GetProcessMemoryInfo(proc)
144
trace.note('Cannot debug memory on win32 without ctypes'
147
trace.note('WorkingSize %8d kB', info['WorkingSetSize'] / 1024)
148
trace.note('PeakWorking %8d kB', info['PeakWorkingSetSize'] / 1024)
151
trace.note('PagefileUsage %8d kB', info.get('PagefileUsage', 0) / 1024)
152
trace.note('PeakPagefileUsage %8d kB', info.get('PeakPagefileUsage', 0) / 1024)
153
trace.note('PrivateUsage %8d kB', info.get('PrivateUsage', 0) / 1024)
154
trace.note('PageFaultCount %8d', info.get('PageFaultCount', 0))
100
157
def get_console_size(defaultx=80, defaulty=25):
101
158
"""Return size of current console.