#NEWLINE# def backgroundProfileFormula( cntlr , profileReportFile , maxRunTime , excludeCompileTime ) : #NEWLINE# #INDENT# from arelle import Locale , XPathParser , ValidateXbrlDimensions , ValidateFormula #NEWLINE# XPathParser . initializeParser ( cntlr . modelManager ) #NEWLINE# ValidateXbrlDimensions . loadDimensionDefaults ( cntlr . modelManager ) #NEWLINE# import cProfile , pstats , sys , time #NEWLINE# class Validate ( ) : #NEWLINE# #INDENT# def __init__( self , modelXbrl , maxRunTime ) : #NEWLINE# #INDENT# self . modelXbrl = modelXbrl #NEWLINE# self . parameters = None #NEWLINE# self . validateSBRNL = False #NEWLINE# self . maxFormulaRunTime = maxRunTime #NEWLINE# #UNINDENT# def close( self ) : #NEWLINE# #INDENT# self . __dict__ . clear ( ) #NEWLINE# #UNINDENT# #UNINDENT# val = Validate ( cntlr . modelManager . modelXbrl , maxRunTime ) #NEWLINE# formulaOptions = val . modelXbrl . modelManager . formulaOptions #NEWLINE# if excludeCompileTime : #NEWLINE# #INDENT# startedAt = time . time ( ) #NEWLINE# cntlr . addToLog ( _ ( 'pre-compiling formulas before profiling' ) ) #NEWLINE# val . validateFormulaCompileOnly = True #NEWLINE# ValidateFormula . validate ( val ) #NEWLINE# del val . validateFormulaCompileOnly #NEWLINE# cntlr . addToLog ( Locale . format_string ( cntlr . modelManager . locale , _ ( 'formula pre-compiling completed in %.2f secs' ) , ( time . time ( ) - startedAt ) ) ) #NEWLINE# cntlr . addToLog ( _ ( 'executing formulas for profiling' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# cntlr . addToLog ( _ ( 'compiling and executing formulas for profiling' ) ) #NEWLINE# #UNINDENT# startedAt = time . time ( ) #NEWLINE# statsFile = ( profileReportFile + '.bin' ) #NEWLINE# cProfile . runctx ( 'ValidateFormula.validate(val)' , globals ( ) , locals ( ) , statsFile ) #NEWLINE# cntlr . addToLog ( Locale . format_string ( cntlr . modelManager . locale , _ ( 'formula profiling completed in %.2f secs' ) , ( time . time ( ) - startedAt ) ) ) #NEWLINE# val . close ( ) #NEWLINE# priorStdOut = sys . stdout #NEWLINE# sys . stdout = open ( profileReportFile , 'w' ) #NEWLINE# statObj = pstats . Stats ( statsFile ) #NEWLINE# statObj . strip_dirs ( ) #NEWLINE# statObj . sort_stats ( 'time' ) #NEWLINE# statObj . print_stats ( ) #NEWLINE# statObj . print_callees ( ) #NEWLINE# statObj . print_callers ( ) #NEWLINE# sys . stdout . flush ( ) #NEWLINE# sys . stdout . close ( ) #NEWLINE# del statObj #NEWLINE# sys . stdout = priorStdOut #NEWLINE# os . remove ( statsFile )