Logo Search packages:      
Sourcecode: zope-parsedxml version File versions

profPyXMLParse.py

import getopt
import os
import profile
import pstats
import sys
import Products.ParsedXML
from xml.dom.ext.reader import PyExpat

FILE = os.path.join(sys.modules['Products.ParsedXML'].__path__[0],
    'tests', 'xml', '4ohn4ktj.xml')
PROFILEDATA = "@parsefile.prof"

def parsefile(filename, namespaces):
    if not namespaces:
        print "PyXML reader only parses with namespaces"
        sys.exit(2)
    reader = PyExpat.Reader()
    return reader.fromUri(filename)

_getattr_counts = {}

def main():
    namespaces = 1
    profiledata = None
    proflines = 20
    filename = FILE
    opts, args = getopt.getopt(sys.argv[1:], "nd:p:")
    for opt, arg in opts:
        if opt == "-n":
            namespaces = not namespaces
        elif opt == "-p":
            proflines = int(arg)
        elif opt == "-d":
            profiledata = arg
    if len(args) >= 2:
        print "One file at a time, please!"
        sys.exit(2)
    elif args:
        filename = args[0]

    profile.run('parsefile(%s, %s)' % (`filename`, namespaces),
                profiledata or PROFILEDATA)
    p = pstats.Stats(profiledata or PROFILEDATA)
    p.strip_dirs().sort_stats('time').print_stats(proflines)
    #p.print_callers(proflines)
    #p.strip_dirs().sort_stats('cum').print_stats(proflines)
    if not profiledata:
        os.unlink(PROFILEDATA)


if __name__ == "__main__":
    main()

Generated by  Doxygen 1.6.0   Back to index