/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/win32utils.py

  • Committer: Martin Pool
  • Date: 2009-03-03 03:01:49 UTC
  • mfrom: (4070 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4073.
  • Revision ID: mbp@sourcefrog.net-20090303030149-8p8o8hszdtqa7w8f
merge trunk

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
 
126
183
 
127
184
def _get_sh_special_folder_path(csidl):
128
185
    """Call SHGetSpecialFolderPathW if available, or return None.
129
 
    
 
186
 
130
187
    Result is always unicode (or None).
131
188
    """
132
189
    if has_ctypes:
344
401
        return u'./' + path, True
345
402
    else:
346
403
        return path, False
347
 
    
 
404
 
348
405
def _undo_ensure_with_dir(path, corrected):
349
406
    if corrected:
350
407
        return path[2:]
369
426
    import glob
370
427
    expanded_file_list = []
371
428
    for possible_glob in file_list:
372
 
        
 
429
 
373
430
        # work around bugs in glob.glob()
374
431
        # - Python bug #1001604 ("glob doesn't return unicode with ...")
375
432
        # - failing expansion for */* with non-iso-8859-* chars
384
441
        else:
385
442
            glob_files = [_undo_ensure_with_dir(elem, corrected) for elem in glob_files]
386
443
            expanded_file_list += glob_files
387
 
            
388
 
    return [elem.replace(u'\\', u'/') for elem in expanded_file_list] 
 
444
 
 
445
    return [elem.replace(u'\\', u'/') for elem in expanded_file_list]
389
446
 
390
447
 
391
448
def get_app_path(appname):