예제 #1
0
def backgroundProfileFormula(cntlr, profileReportFile, maxRunTime, excludeCompileTime):
    from arelle import Locale, XPathParser, ValidateXbrlDimensions, ValidateFormula

    # build grammar before profiling (if this is the first pass, so it doesn't count in profile statistics)
    XPathParser.initializeParser(cntlr.modelManager)
    
    # load dimension defaults
    ValidateXbrlDimensions.loadDimensionDefaults(cntlr.modelManager)
    
    import cProfile, pstats, sys, time
    
    # a minimal validation class for formula validator parameters that are needed
    class Validate:
        def __init__(self, modelXbrl, maxRunTime):
            self.modelXbrl = modelXbrl
            self.parameters = None
            self.validateSBRNL = False
            self.maxFormulaRunTime = maxRunTime
        def close(self):
            self.__dict__.clear()
            
    val = Validate(cntlr.modelManager.modelXbrl, maxRunTime)
    formulaOptions = val.modelXbrl.modelManager.formulaOptions
    if excludeCompileTime:
        startedAt = time.time()
        cntlr.addToLog(_("pre-compiling formulas before profiling"))
        val.validateFormulaCompileOnly = True
        ValidateFormula.validate(val)
        del val.validateFormulaCompileOnly
        cntlr.addToLog(Locale.format_string(cntlr.modelManager.locale, 
                                            _("formula pre-compiling completed in %.2f secs"), 
                                            time.time() - startedAt))
        cntlr.addToLog(_("executing formulas for profiling"))
    else:
        cntlr.addToLog(_("compiling and executing formulas for profiling"))
    startedAt = time.time()
            
    statsFile = profileReportFile + ".bin"
    cProfile.runctx("ValidateFormula.validate(val)", globals(), locals(), statsFile)
    cntlr.addToLog(Locale.format_string(cntlr.modelManager.locale, 
                                        _("formula profiling completed in %.2f secs"), 
                                        time.time() - startedAt))
    # dereference val
    val.close()
    
    # specify a file for log
    priorStdOut = sys.stdout
    sys.stdout = open(profileReportFile, "w")

    statObj = pstats.Stats(statsFile)
    statObj.strip_dirs()
    statObj.sort_stats("time")
    statObj.print_stats()
    statObj.print_callees()
    statObj.print_callers()
    sys.stdout.flush()
    sys.stdout.close()
    del statObj
    sys.stdout = priorStdOut
    os.remove(statsFile)
예제 #2
0
def backgroundProfileFormula(cntlr, profileReportFile, maxRunTime, excludeCompileTime):
    from arelle import Locale, XPathParser, ValidateXbrlDimensions, ValidateFormula

    # build grammar before profiling (if this is the first pass, so it doesn't count in profile statistics)
    XPathParser.initializeParser(cntlr.modelManager)
    
    # load dimension defaults
    ValidateXbrlDimensions.loadDimensionDefaults(cntlr.modelManager)
    
    import cProfile, pstats, sys, time
    
    # a minimal validation class for formula validator parameters that are needed
    class Validate:
        def __init__(self, modelXbrl, maxRunTime):
            self.modelXbrl = modelXbrl
            self.parameters = None
            self.validateSBRNL = False
            self.maxFormulaRunTime = maxRunTime
        def close(self):
            self.__dict__.clear()
            
    val = Validate(cntlr.modelManager.modelXbrl, maxRunTime)
    formulaOptions = val.modelXbrl.modelManager.formulaOptions
    if excludeCompileTime:
        startedAt = time.time()
        cntlr.addToLog(_("pre-compiling formulas before profiling"))
        val.validateFormulaCompileOnly = True
        ValidateFormula.validate(val)
        del val.validateFormulaCompileOnly
        cntlr.addToLog(Locale.format_string(cntlr.modelManager.locale, 
                                            _("formula pre-compiling completed in %.2f secs"), 
                                            time.time() - startedAt))
        cntlr.addToLog(_("executing formulas for profiling"))
    else:
        cntlr.addToLog(_("compiling and executing formulas for profiling"))
    startedAt = time.time()
            
    statsFile = profileReportFile + ".bin"
    cProfile.runctx("ValidateFormula.validate(val)", globals(), locals(), statsFile)
    cntlr.addToLog(Locale.format_string(cntlr.modelManager.locale, 
                                        _("formula profiling completed in %.2f secs"), 
                                        time.time() - startedAt))
    # dereference val
    val.close()
    
    # specify a file for log
    priorStdOut = sys.stdout
    sys.stdout = open(profileReportFile, "w")

    statObj = pstats.Stats(statsFile)
    statObj.strip_dirs()
    statObj.sort_stats("time")
    statObj.print_stats()
    statObj.print_callees()
    statObj.print_callers()
    sys.stdout.flush()
    sys.stdout.close()
    del statObj
    sys.stdout = priorStdOut
    os.remove(statsFile)
예제 #3
0
def profilerCommandLineRun(cntlr, options, sourceZipStream=None, **kwargs):
    from arelle import Locale
    import cProfile, pstats, sys, time
    profileReportFile = getattr(options, "profilerReportFile", None)
    if profileReportFile and not getattr(cntlr, "blockNestedProfiling", False):
        startedAt = time.time()
        cntlr.addToLog(_("invoking command processing under profiler"))
        statsFile = profileReportFile + ".bin"
        cntlr.blockNestedProfiling = True
        cProfile.runctx("cntlr.run(options, sourceZipStream)", globals(), locals(), statsFile)
        cntlr.addToLog(Locale.format_string(cntlr.modelManager.locale, 
                                            _("profiled command processing completed in %.2f secs"), 
                                            time.time() - startedAt))
        # specify a file for log
        priorStdOut = sys.stdout
        sys.stdout = open(profileReportFile, "w")
    
        statObj = pstats.Stats(statsFile)
        statObj.strip_dirs()
        statObj.sort_stats("time")
        statObj.print_stats()
        statObj.print_callees()
        statObj.print_callers()
        sys.stdout.flush()
        sys.stdout.close()
        del statObj
        sys.stdout = priorStdOut
        os.remove(statsFile)
        del cntlr.blockNestedProfiling
        sys.exit() # raise SYSTEM_EXIT to stop outer execution
예제 #4
0
def profilerCommandLineRun(cntlr, options, sourceZipStream=None, **kwargs):
    from arelle import Locale
    import cProfile, pstats, sys, time
    profileReportFile = getattr(options, "profilerReportFile", None)
    if profileReportFile and not getattr(cntlr, "blockNestedProfiling", False):
        startedAt = time.time()
        cntlr.addToLog(_("invoking command processing under profiler"))
        statsFile = profileReportFile + ".bin"
        cntlr.blockNestedProfiling = True
        cProfile.runctx("cntlr.run(options, sourceZipStream)", globals(),
                        locals(), statsFile)
        cntlr.addToLog(
            Locale.format_string(
                cntlr.modelManager.locale,
                _("profiled command processing completed in %.2f secs"),
                time.time() - startedAt))
        # specify a file for log
        priorStdOut = sys.stdout
        sys.stdout = open(profileReportFile, "w")

        statObj = pstats.Stats(statsFile)
        statObj.strip_dirs()
        statObj.sort_stats("time")
        statObj.print_stats()
        statObj.print_callees()
        statObj.print_callers()
        sys.stdout.flush()
        sys.stdout.close()
        del statObj
        sys.stdout = priorStdOut
        os.remove(statsFile)
        del cntlr.blockNestedProfiling
        sys.exit()  # raise SYSTEM_EXIT to stop outer execution
예제 #5
0
def savePickle(cntlr, modelXbrl, pickleFile):
    if modelXbrl.fileSource.isArchive:
        return
    import io, time, pickle
    from arelle import Locale
    startedAt = time.time()

    fh = io.open(pickleFile, u"wb")
    try:
        pickle.dump(modelXbrl, fh)
    except Exception, ex:
        cntlr.addToLog(u"Exception " + unicode(ex))
    fh.close()
    
    cntlr.addToLog(Locale.format_string(cntlr.modelManager.locale, 
                                        _(u"profiled command processing completed in %.2f secs"), 
                                        time.time() - startedAt))

def savePickleMenuEntender(cntlr, menu):
    # Extend menu with an item for the save infoset plugin
    menu.add_command(label=u"Save pickled modelXbrl", 
                     underline=0, 
                     command=lambda: savePickleMenuCommand(cntlr) )

def savePickleMenuCommand(cntlr):
    # save Infoset menu item has been invoked
    from arelle.ModelDocument import Type
    if cntlr.modelManager is None or cntlr.modelManager.modelXbrl is None or cntlr.modelManager.modelXbrl.modelDocument.type != Type.INSTANCE:
        cntlr.addToLog(u"No instance loaded.")
        return