@@ -85,7 +85,8 @@ def setup_logger(name, log_file, level=logging.INFO):
8585 return logger
8686
8787# first file logger
88- actionlogger = setup_logger ('pipeline_action_logger' , ('pipeline_action_' + str (os .getpid ()) + '.log' , args .action_logfile )[args .action_logfile != None ], level = logging .DEBUG )
88+ actionlogger_file = ('pipeline_action_' + str (os .getpid ()) + '.log' , args .action_logfile )[args .action_logfile != None ]
89+ actionlogger = setup_logger ('pipeline_action_logger' , actionlogger_file , level = logging .DEBUG )
8990
9091# second file logger
9192metriclogger = setup_logger ('pipeline_metric_logger' , ('pipeline_metric_' + str (os .getpid ()) + '.log' , args .action_logfile )[args .action_logfile != None ])
@@ -1808,5 +1809,46 @@ def speedup_ROOT_Init():
18081809 exit (code )
18091810 actionlogger .info ("Running in cgroup" )
18101811
1811- executor = WorkflowExecutor (args .workflowfile ,jmax = int (args .maxjobs ),args = args )
1812- exit (executor .execute ())
1812+
1813+ # This starts the fanotify fileaccess monitoring process
1814+ # if asked for
1815+ o2dpg_filegraph_exec = os .getenv ("O2DPG_PRODUCE_FILEGRAPH" ) # switches filegraph monitoring on and contains the executable name
1816+ if o2dpg_filegraph_exec :
1817+ env = os .environ .copy ()
1818+ env ["FILEACCESS_MON_ROOTPATH" ] = os .getcwd ()
1819+ env ["MAXMOTHERPID" ] = f"{ os .getpid ()} "
1820+
1821+ fileaccess_log_file_name = f"pipeline_fileaccess_{ os .getpid ()} .log"
1822+ fileaccess_log_file = open (fileaccess_log_file_name , "w" )
1823+ fileaccess_monitor_proc = subprocess .Popen (
1824+ [o2dpg_filegraph_exec ],
1825+ stdout = fileaccess_log_file ,
1826+ stderr = subprocess .STDOUT ,
1827+ env = env )
1828+ else :
1829+ fileaccess_monitor_proc = None
1830+
1831+ try :
1832+ # This is core workflow runner invocation
1833+ executor = WorkflowExecutor (args .workflowfile ,jmax = int (args .maxjobs ),args = args )
1834+ rc = executor .execute ()
1835+ finally :
1836+ if fileaccess_monitor_proc :
1837+ fileaccess_monitor_proc .terminate () # sends SIGTERM
1838+ try :
1839+ fileaccess_monitor_proc .wait (timeout = 5 )
1840+ except subprocess .TimeoutExpired :
1841+ fileaccess_monitor_proc .kill () # force kill if not stopping
1842+ # now produce the final filegraph output
1843+ o2dpg_root = os .getenv ("O2DPG_ROOT" )
1844+ analyse_cmd = [
1845+ sys .executable , # runs with same Python interpreter
1846+ f"{ o2dpg_root } /UTILS/FileIOGraph/analyse_FileIO.py" ,
1847+ "--actionFile" , actionlogger_file ,
1848+ "--monitorFile" , fileaccess_log_file_name ,
1849+ "-o" , f"pipeline_fileaccess_report_{ os .getpid ()} .json" ,
1850+ "--basedir" , os .getcwd () ]
1851+ print (f"Producing FileIOGraph with command { analyse_cmd } " )
1852+ subprocess .run (analyse_cmd , check = True )
1853+
1854+ sys .exit (rc )
0 commit comments