Changeset 8279
- Timestamp:
- Dec 12, 2011, 2:36:51 PM (12 years ago)
- Location:
- trunk/anuga_core/source/anuga
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/general_mesh.py
r8200 r8279 84 84 if verbose: log.critical('General_mesh: Building basic mesh structure ' 85 85 'in ANUGA domain') 86 86 if verbose: log.timingInfo("numTriangles, " + str(triangles.shape[0])) 87 87 88 self.triangles = num.array(triangles, num.int) 88 89 self.nodes = num.array(nodes, num.float) … … 198 199 if verbose: log.critical('Building inverted triangle structure') 199 200 self.build_inverted_triangle_structure() 201 202 if verbose: log.timingInfo("aoi, '%s'" % self.get_area()) 203 200 204 201 205 def __len__(self): -
trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/neighbour_mesh.py
r8219 r8279 194 194 #FIXME check integrity? 195 195 if verbose: log.critical('Mesh: Done') 196 if verbose: log.timingInfo("finishMesh, '%s'" % log.CurrentDateTime()) 196 197 197 198 def __repr__(self): -
trunk/anuga_core/source/anuga/pmesh/mesh_interface.py
r8124 r8279 7 7 from anuga.geometry.polygon import polylist2points_verts 8 8 import anuga.utilities.log as log 9 9 import datetime 10 10 11 11 # This is due to pmesh being a package and a module and … … 87 87 """ 88 88 89 90 if verbose: log.resource_usage_timing(log.logging.INFO, "start_") 91 if verbose: log.timingInfo("maximum_triangle_area, " + str(maximum_triangle_area)) 92 if verbose: log.timingInfo("minimum_triangle_angle, " + str(minimum_triangle_angle)) 93 if verbose: log.timingInfo("startMesh, '%s'" % log.CurrentDateTime()) 94 89 95 # Build arguments and keyword arguments for use with caching or apply. 90 96 args = (bounding_polygon, … … 121 127 args, kwargs) 122 128 129 130 123 131 return m 124 132 … … 330 338 # recompute as it has meshfile as a dependency 331 339 332 # Decide whether to store this mesh or return it 340 # Decide whether to store this mesh or return it 341 342 333 343 if filename is None: 334 344 return m 335 345 else: 336 346 if verbose: log.critical("Generating mesh to file '%s'" % filename) 347 337 348 m.generate_mesh(minimum_triangle_angle=minimum_triangle_angle, 338 349 verbose=verbose) 339 350 m.export_mesh_file(filename) 340 341 351 -
trunk/anuga_core/source/anuga/utilities/log.py
r7854 r8279 36 36 import traceback 37 37 import logging 38 import datetime 38 39 39 40 DefaultConsoleLogLevel = logging.CRITICAL 40 41 DefaultFileLogLevel = logging.INFO 41 42 TimingDelimiter ='#@# ' 42 43 43 44 ################################################################################ … … 203 204 204 205 log(msg, logging.CRITICAL) 206 207 def timingInfo(msg=''): 208 '''Shortcut for log(timingDelimiter, msg).''' 209 210 log(TimingDelimiter + msg, logging.INFO) 205 211 206 212 … … 286 292 log(msg, level) 287 293 288 289 ################################################################################ 290 294 def CurrentDateTime(): 295 return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") 296 297 298 def resource_usage_timing(level=logging.INFO, prefix =""): 299 '''Log memory usage at given log level.''' 300 301 _scale = {'KB': 1024, 'MB': 1024*1024, 'GB': 1024*1024*1024, 302 'kB': 1024, 'mB': 1024*1024, 'gB': 1024*1024*1024} 303 304 if sys.platform != 'win32': 305 _proc_status = '/proc/%d/status' % os.getpid() 306 307 def _VmB(VmKey): 308 '''Get number of virtual bytes used.''' 309 310 # get pseudo file /proc/<pid>/status 311 try: 312 t = open(_proc_status) 313 v = t.read() 314 t.close() 315 except IOError: 316 return 0.0 317 318 # get VmKey line, eg: 'VmRSS: 999 kB\n ... 319 i = v.index(VmKey) 320 v = v[i:].split(None, 3) 321 if len(v) < 3: 322 return 0.0 323 324 # convert Vm value to bytes 325 return float(v[1]) * _scale[v[2]] 326 327 def memory(since=0.0): 328 '''Get virtual memory usage in bytes.''' 329 330 return _VmB('VmSize:') - since 331 332 def resident(since=0.0): 333 '''Get resident memory usage in bytes.''' 334 335 return _VmB('VmRSS:') - since 336 337 def stacksize(since=0.0): 338 '''Get stack size in bytes.''' 339 340 return _VmB('VmStk:') - since 341 342 msg = ('Resource usage: memory=%.1fMB resident=%.1fMB stacksize=%.1fMB' 343 % (memory()/_scale['MB'], resident()/_scale['MB'], 344 stacksize()/_scale['MB'])) 345 log(msg, level) 346 timingInfo('sys_platform, ' + sys.platform) 347 timingInfo(prefix + 'memory, ' + str(memory()/_scale['MB'])) 348 timingInfo(prefix + 'resident, ' + str(resident()/_scale['MB'])) 349 timingInfo(prefix + 'stacksize, ' + str(stacksize()/_scale['MB'])) 350 else: 351 # Windows code from: http://code.activestate.com/recipes/511491/ 352 try: 353 import ctypes 354 import _winreg 355 except: 356 log(level, 'Windows resource usage not available') 357 return 358 359 kernel32 = ctypes.windll.kernel32 360 c_ulong = ctypes.c_ulong 361 c_ulonglong = ctypes.c_ulonglong 362 class MEMORYSTATUSEX(ctypes.Structure): 363 _fields_ = [('dwLength', c_ulong), 364 ('dwMemoryLoad', c_ulong), 365 ('ullTotalPhys', c_ulonglong), 366 ('ullAvailPhys', c_ulonglong), 367 ('ullTotalPageFile', c_ulonglong), 368 ('ullAvailPageFile', c_ulonglong), 369 ('ullTotalVirtual', c_ulonglong), 370 ('ullAvailVirtual', c_ulonglong), 371 ('ullAvailExtendedVirtual', c_ulonglong) 372 ] 373 374 memoryStatusEx = MEMORYSTATUSEX() 375 memoryStatusEx.dwLength = ctypes.sizeof(MEMORYSTATUSEX) 376 kernel32.GlobalMemoryStatusEx(ctypes.byref(memoryStatusEx)) 377 378 msg = ('Resource usage: total memory=%.1fMB free memory=%.1fMB' 379 % (memoryStatusEx.ullTotalPhys/_scale['MB'], 380 memoryStatusEx.ullAvailPhys/_scale['MB'])) 381 log(msg, level) 382 timingInfo('sys_platform, ' + sys.platform) 383 timingInfo(prefix + 'total_memory, ' + str(memoryStatusEx.ullTotalPhys/_scale['MB'])) 384 timingInfo(prefix + 'free_memory, ' + str(memoryStatusEx.ullAvailPhys/_scale['MB'])) 385 386 387 ################################################################################ 291 388 if __name__ == '__main__': 292 389 critical('#' * 80)
Note: See TracChangeset
for help on using the changeset viewer.