~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/win32utils.py

  • Committer: Jelmer Vernooij
  • Date: 2009-02-18 12:48:23 UTC
  • mfrom: (4016 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4017.
  • Revision ID: jelmer@samba.org-20090218124823-acyczvvcfq9ztg3s
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
MAX_COMPUTERNAME_LENGTH = 31
98
98
 
99
99
 
 
100
def debug_memory_win32api(message='', short=True):
 
101
    """Use trace.note() to dump the running memory info."""
 
102
    from bzrlib import trace
 
103
    if has_ctypes:
 
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),
 
117
                       ]
 
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))
 
123
        if not ret:
 
124
            trace.note('Failed to GetProcessMemoryInfo()')
 
125
            return
 
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,
 
136
               }
 
137
    elif has_win32api:
 
138
        import win32process
 
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)
 
143
    else:
 
144
        trace.note('Cannot debug memory on win32 without ctypes'
 
145
                   ' or win32process')
 
146
        return
 
147
    trace.note('WorkingSize       %8d kB', info['WorkingSetSize'] / 1024)
 
148
    trace.note('PeakWorking       %8d kB', info['PeakWorkingSetSize'] / 1024)
 
149
    if short:
 
150
        return
 
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))
 
155
 
 
156
 
100
157
def get_console_size(defaultx=80, defaulty=25):
101
158
    """Return size of current console.
102
159