Changeset 8279


Ignore:
Timestamp:
Dec 12, 2011, 2:36:51 PM (8 years ago)
Author:
neweyv
Message:

Additional information written to the log file. This information will assist in creating an algorithm to predict the runtime of ANUGA given various parameters.

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  
    8484        if verbose: log.critical('General_mesh: Building basic mesh structure '
    8585                                 'in ANUGA domain')
    86 
     86        if verbose: log.timingInfo("numTriangles, " + str(triangles.shape[0]))
     87       
    8788        self.triangles = num.array(triangles, num.int)
    8889        self.nodes = num.array(nodes, num.float)
     
    198199        if verbose: log.critical('Building inverted triangle structure')
    199200        self.build_inverted_triangle_structure()
     201       
     202        if verbose: log.timingInfo("aoi, '%s'" % self.get_area())
     203       
    200204
    201205    def __len__(self):
  • trunk/anuga_core/source/anuga/abstract_2d_finite_volumes/neighbour_mesh.py

    r8219 r8279  
    194194        #FIXME check integrity?
    195195        if verbose: log.critical('Mesh: Done')
     196        if verbose: log.timingInfo("finishMesh, '%s'" % log.CurrentDateTime())
    196197
    197198    def __repr__(self):
  • trunk/anuga_core/source/anuga/pmesh/mesh_interface.py

    r8124 r8279  
    77from anuga.geometry.polygon import polylist2points_verts
    88import anuga.utilities.log as log
    9 
     9import datetime
    1010
    1111# This is due to pmesh being a package and a module and
     
    8787    """
    8888   
     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   
    8995    # Build arguments and keyword arguments for use with caching or apply.
    9096    args = (bounding_polygon,
     
    121127                  args, kwargs)
    122128
     129
     130   
    123131    return m   
    124132       
     
    330338    # recompute as it has meshfile as a dependency
    331339
    332     # Decide whether to store this mesh or return it   
     340    # Decide whether to store this mesh or return it
     341   
     342   
    333343    if filename is None:
    334344        return m
    335345    else:
    336346        if verbose: log.critical("Generating mesh to file '%s'" % filename)
     347     
    337348        m.generate_mesh(minimum_triangle_angle=minimum_triangle_angle,
    338349                        verbose=verbose)
    339350        m.export_mesh_file(filename)
    340 
    341 
     351       
  • trunk/anuga_core/source/anuga/utilities/log.py

    r7854 r8279  
    3636import traceback
    3737import logging
     38import datetime
    3839
    3940DefaultConsoleLogLevel = logging.CRITICAL
    4041DefaultFileLogLevel = logging.INFO
    41 
     42TimingDelimiter ='#@# '
    4243
    4344################################################################################
     
    203204
    204205    log(msg, logging.CRITICAL)
     206
     207def timingInfo(msg=''):
     208    '''Shortcut for log(timingDelimiter, msg).'''
     209
     210    log(TimingDelimiter + msg, logging.INFO)
    205211
    206212
     
    286292        log(msg, level)
    287293
    288 
    289 ################################################################################
    290 
     294def CurrentDateTime():
     295    return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
     296
     297
     298def 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################################################################################
    291388if __name__ == '__main__':
    292389    critical('#' * 80)
Note: See TracChangeset for help on using the changeset viewer.