ioTimeAnalysis.py

Go to the documentation of this file.
00001 import time
00002 import sys
00003 
00004 __copyright__ = """\
00005 (c). Copyright 1990-2008, Vyper Logix Corp., All Rights Reserved.
00006 
00007 Published under Creative Commons License 
00008 (http://creativecommons.org/licenses/by-nc/3.0/) 
00009 restricted to non-commercial educational use only., 
00010 
00011 See also: http://www.VyperLogix.com and http://www.pypi.info for details.
00012 
00013 THE AUTHOR VYPER LOGIX CORP DISCLAIMS ALL WARRANTIES WITH REGARD TO
00014 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
00015 FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL,
00016 INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
00017 FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
00018 NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
00019 WITH THE USE OR PERFORMANCE OF THIS SOFTWARE !
00020 
00021 USE AT YOUR OWN RISK.
00022 """
00023 
00024 _ioTime = {}
00025 _ioElapsedTime = 0
00026 
00027 def initIOTime(reason):
00028     global _ioTime
00029     if (_ioTime.has_key(reason) == False):
00030         _ioTime[reason] = [0.0]
00031 
00032 def ioBeginTime(reason):
00033     global _ioTime
00034     initIOTime(reason)
00035     _ioTime[reason].append(time.time())
00036 
00037 def ioEndTime(reason):
00038     global _ioTime
00039     initIOTime(reason)
00040     d = _ioTime[reason]
00041     d.append(time.time())
00042     diff = d.pop() - d.pop()
00043     d[0] += diff
00044     _ioTime[reason] = d
00045 
00046 def ioElapsedTime():
00047     return _ioElapsedTime
00048 
00049 def ioTimeAnalysis(iters=None):
00050     global _ioTime
00051     global _ioElapsedTime
00052 
00053     _ioElapsedTime = 0
00054     for k in _ioTime.keys():
00055         d = _ioTime[k]
00056         _tpi = ''
00057         if ( (iters) and (isinstance(iters,int)) ):
00058             _tpi = ' time/iters=(%2.10f)' % (d[0]/iters)
00059         try:
00060             print '(ioTimeAnalysis) :: Category: "%s" = (%s)%s' % (k,d[0],_tpi)
00061         except Exception, details:
00062             from vyperlogix import misc
00063             info_string = misc.formattedException(details=details)
00064             print >>sys.stderr, info_string
00065         _ioElapsedTime += d[0]
00066     return _ioElapsedTime
00067 
00068 def ioTimeAnalysisReport(iters=None,fOut=None):
00069     ioAnalysis = ioTimeAnalysis(iters)
00070     _msg = "\n\nTime spent doing I/O :: (%s)" % (str(ioAnalysis))
00071     print >>fOut, _msg
00072     return _msg
00073 
00074 if (__name__ == '__main__'):
00075     import sys
00076     print >>sys.stdout, __copyright__
00077     print >>sys.stderr, __copyright__
00078 
00079 

© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved; If you reference this document or any part of this document you must use the citation verbatim (including the link) "© Copyright 2008-2009 Vyper Logix Corp., All Right Reserved."

Notice: This source code contained in this document is NOT open source and is NOT being distributed as open source.

122,241 lines of code and growing...