diff --git a/ipsframework/component.py b/ipsframework/component.py index e297476c..7bc8117a 100755 --- a/ipsframework/component.py +++ b/ipsframework/component.py @@ -7,16 +7,6 @@ import weakref from copy import copy -try: - if os.environ['IPS_TIMING'] == '1': - try: - import pytau - except ImportError: - raise - IPS_TIMING = True -except KeyError: - pass - class Component: """ @@ -28,9 +18,6 @@ def __init__(self, services, config): """ Set up config values and reference to services. """ - # pytau.setNode(1) - # timer = pytau.profileTimer("component.__init__", "", str(os.getpid())) - # pytau.start(timer) self.component_id = None self.invocation_q = None self.services = weakref.proxy(services) @@ -42,11 +29,8 @@ def __init__(self, services, config): setattr(self, i, config[i]) except Exception as e: print('Error setting Component parameter : ', i, ' - ', e) - # pytau.stop(timer) raise - # pytau.stop(timer) - def __copy__(self): cls = self.__class__ result = cls.__new__(cls) @@ -61,16 +45,11 @@ def __initialize__(self, component_id, invocation_q, start_time=0.0): """ Establish connection to *invocation_q*. """ - # timer = pytau.profileTimer("component.__initialize__", "", str(os.getpid())) - # pytau.start(timer) self.component_id = component_id self.invocation_q = invocation_q self.start_time = start_time # setattr(sys, 'exit', sys.exit) - # pytau.stop(timer) - return - def __my_exit__(self, arg=0): """ Produce message and exception about exit. @@ -86,8 +65,6 @@ def __run__(self): Wait for incoming commands delivered via the *invocation_q*, and dispatch the incoming methods accordingly. """ - # timer = pytau.profileTimer(self.component_id.__str__() + ".__run__", "", str(os.getpid())) - # pytau.start(timer) tmp = sys.exit sys.exit = self.__my_exit__ @@ -131,7 +108,6 @@ def __run__(self): (errno, strerror) = oserr.args self.services.exception('Error creating directory %s : %s', workdir, strerror) - # pytau.stop(timer) raise os.chdir(workdir) self.services.debug('Running - CompID = %s', @@ -140,9 +116,6 @@ def __run__(self): if (self.services.profile): self.services.debug('Instrumenting - CompID = %s', self.component_id.get_serialization()) - pytau.setNode(int(self.component_id.get_seq_num())) - pytau.dbPurge() - self.services._make_timers() self.services._init_event_service() while True: @@ -175,7 +148,6 @@ def __run__(self): call_id, Message.SUCCESS, retval) self.services.fwk_in_q.put(response_msg) - # pytau.stop(timer) def init(self, timestamp=0.0, **keywords): """ @@ -241,7 +213,6 @@ def terminate(self, status): Clean up services and call :py:obj:`sys_exit`. """ # print self.services.full_comp_id, ": terminate() method called" - self.services._cleanup() # self.services.debug('###(1) %s %s', str(self), str(self.__dict__)) if (status == Message.SUCCESS): diff --git a/ipsframework/configurationManager.py b/ipsframework/configurationManager.py index 97d6a88e..9954c47f 100755 --- a/ipsframework/configurationManager.py +++ b/ipsframework/configurationManager.py @@ -51,7 +51,6 @@ def __init__(self, sim_name): self.process_list = [] self.fwk_logger = None - # @TauWrap(TIMERS['__init__']) # SIMYAN: accept a compset_list to find specific configuration files for # the components def __init__(self, fwk, config_file_list, platform_file_name, compset_list): @@ -61,9 +60,6 @@ def __init__(self, fwk, config_file_list, platform_file_name, compset_list): file, and the configuration files are read in. """ # ref to framework - # self.timers = make_timers() - # start(self.timers['__init__']) - # pytau.start(self.timers['__init__']) self.fwk = fwk self.event_mgr = None self.data_mgr = None @@ -137,19 +133,14 @@ def __getattr__(self, attr): self.myTopic = None self.log_daemon = ipsLogging.ipsLogger(self.log_dynamic_sim_queue) self.log_process = None - # pytau.stop(self.timers['__init__']) - # stop(self.timers['__init__']) # CM initialize - # @TauWrap(TIMERS['initialize']) def initialize(self, data_mgr, resource_mgr, task_mgr, ftb): """ Parse the platform and simulation configuration files using the :py:obj:`ConfigObj` module. Create and initialize simulation(s) and their components, framework components and loggers. """ - # pytau.start(self.timers['initialize']) - # start(self.timers['initialize']) local_debug = False self.event_mgr = None # eventManager(self) self.data_mgr = data_mgr @@ -177,14 +168,10 @@ def initialize(self, data_mgr, resource_mgr, task_mgr, ftb): except IOError: self.fwk.exception('Error opening config file: %s', self.platform_file) - # pytau.stop(self.timers['initialize']) - # stop(self.timers['initialize']) raise except SyntaxError: self.fwk.exception('Error parsing config file: %s', self.platform_file) - # pytau.stop(self.timers['initialize']) - # stop(self.timers['initialize']) raise # get mandatory values for kw in self.platform_keywords: @@ -193,8 +180,6 @@ def initialize(self, data_mgr, resource_mgr, task_mgr, ftb): except KeyError: self.fwk.exception('Missing required parameter %s in platform config file', kw) - # pytau.stop(self.timers['initialize']) - # stop(self.timers['initialize']) raise # Make sure the HOST variable is defined try: @@ -351,13 +336,9 @@ def initialize(self, data_mgr, resource_mgr, task_mgr, ftb): except IOError: self.fwk.exception('Error opening config file %s: ', conf_file) - # pytau.stop(self.timers['initialize']) - # stop(self.timers['initialize']) raise except SyntaxError: self.fwk.exception('Error parsing config file %s: ', conf_file) - # pytau.stop(self.timers['initialize']) - # stop(self.timers['initialize']) raise except Exception: self.fwk.exception('Error(s) during parsing of supplied config file %s: ', conf_file) @@ -370,8 +351,6 @@ def initialize(self, data_mgr, resource_mgr, task_mgr, ftb): except KeyError: self.fwk.exception('Missing required parameters SIM_NAME, SIM_ROOT or LOG_FILE\ in configuration file %s', conf_file) - # pytau.stop(self.timers['initialize']) - # stop(self.timers['initialize']) raise # SIMYAN allow for a container file with default .zip extension @@ -383,18 +362,12 @@ def initialize(self, data_mgr, resource_mgr, task_mgr, ftb): if (sim_name in sim_name_list): self.fwk.exception('Error: Duplicate SIM_NAME in configuration files') - # pytau.stop(self.timers['initialize']) - # stop(self.timers['initialize']) sys.exit(1) if (sim_root in sim_root_list): self.fwk.exception('Error: Duplicate SIM_ROOT in configuration files') - # pytau.stop(self.timers['initialize']) - # stop(self.timers['initialize']) sys.exit(1) if (log_file in log_file_list): self.fwk.exception('Error: Duplicate LOG_FILE in configuration files') - # pytau.stop(self.timers['initialize']) - # stop(self.timers['initialize']) sys.exit(1) if 'SIMULATION_CONFIG_FILE' not in conf: conf['SIMULATION_CONFIG_FILE'] = conf_file @@ -426,8 +399,6 @@ def initialize(self, data_mgr, resource_mgr, task_mgr, ftb): except AttributeError: self.fwk.exception('Invalid LOG_LEVEL value %s in config file %s ', log_level, conf_file) - # pytau.stop(self.timers['initialize']) - # stop(self.timers['initialize']) raise socketHandler = ipsLogging.IPSLogSocketHandler(new_sim.log_pipe_name) new_sim.fwk_logger = logging.getLogger(sim_name + '_FRAMEWORK') @@ -459,20 +430,15 @@ def initialize(self, data_mgr, resource_mgr, task_mgr, ftb): # ***** commenting out portal stuff for now self._initialize_fwk_components() - # pytau.stop(self.timers['initialize']) - # stop(self.timers['initialize']) # do later - subscribe to events, set up event publishing structure # publish "CM initialized" event - # @TauWrap(TIMERS['_initialize_fwk_components']) def _initialize_fwk_components(self): """ Initialize 'components' that are part of the framework infrastructure. Those components (for now) communicate using the event bus and are not part of the normal framework-mediated RPC inter-compponent interactions """ - # pytau.start(self.timers['_initialize_fwk_components']) - # start(self.timers['_initialize_fwk_components']) # SIMYAN: set up the runspaceInit component runspace_conf = {} @@ -569,10 +535,6 @@ def _initialize_fwk_components(self): self.sim_map[self.fwk_sim_name]) self.fwk_components.append(ftb_component_id) - # pytau.stop(self.timers['_initialize_fwk_components']) - # stop(self.timers['_initialize_fwk_components']) - - # @TauWrap(TIMERS['_initialize_sim']) def _initialize_sim(self, sim_data): """ Parses the configuration data (*sim_conf*) associated with a simulation @@ -580,8 +542,6 @@ def _initialize_sim(self, sim_data): Populate the *component_registry* with appropriate component and port mapping info. """ - # pytau.start(self.timers['_initialize_sim']) - # start(self.timers['_initialize_sim']) sim_conf = sim_data.sim_conf sim_name = sim_data.sim_name ports_config = sim_conf['PORTS'] @@ -627,8 +587,6 @@ def _initialize_sim(self, sim_data): except Exception: self.fwk.exception('Error accessing configuration section for ' + 'component %s in simulation %s', comp_ref, sim_name) - # pytau.stop(self.timers['_initialize_sim']) - # stop(self.timers['_initialize_sim']) sys.exit(1) conf_fields = set(comp_conf.keys()) @@ -659,8 +617,6 @@ def _initialize_sim(self, sim_data): self.fwk.exception('Error: missing required entries %s \ in simulation %s component %s configuration section', list(self.required_fields - conf_fields), sim_name, comp_ref) - # pytau.stop(self.timers['_initialize_sim']) - # stop(self.timers['_initialize_sim']) sys.exit(1) component_id = self._create_component(comp_conf, sim_data) sim_data.port_map[port] = component_id @@ -672,8 +628,6 @@ def _initialize_sim(self, sim_data): if (sim_data.driver_comp is None): self.fwk.error('Missing DRIVER specification in ' + 'config file for simulation %s', sim_data.sim_name) - # pytau.stop(self.timers['_initialize_sim']) - # stop(self.timers['_initialize_sim']) sys.exit(1) if (sim_data.init_comp is None): self.fwk.warning('Missing INIT specification in ' + @@ -702,19 +656,14 @@ def _initialize_sim(self, sim_data): # if (errno != 17): # self.fwk.exception('Error creating State directory %s : %d %s' , # statedir, errno, strerror) - # #pytau.stop(self.timers['_initialize_sim']) - # #stop(self.timers['_initialize_sim']) # #raise - # #pytau.stop(self.timers['_initialize_sim']) return - # @TauWrap(TIMERS['_create_component']) def _create_component(self, comp_conf, sim_data): """ Create component and populate it with the information from the component's configuration section. """ - # pytau.start(self.timers['_create_component']) sim_name = sim_data.sim_name fullpath = os.path.abspath(comp_conf['SCRIPT']) # originalpath= comp_conf['SCRIPT'] @@ -745,7 +694,6 @@ def _create_component(self, comp_conf, sim_data): self.fwk.error('Error in configuration file : NAME = %s SCRIPT = %s', comp_conf['NAME'], comp_conf['SCRIPT']) self.fwk.exception('Error instantiating IPS component %s From %s', class_name, script) - # pytau.stop(self.timers['_create_component']) raise # SIMYAN: removed else conditional, copying files in runspaceInit @@ -770,16 +718,13 @@ def _create_component(self, comp_conf, sim_data): p.start() sim_data.process_list.append(p) sim_data.all_comps.append(component_id) - # pytau.stop(self.timers['_create_component']) return component_id - # @TauWrap(TIMERS['get_component_map']) def get_component_map(self): """ Return a dictionary of simulation names and lists of component references. (May only be the driver, and init (if present)???) """ - # pytau.start(self.timers['get_component_map']) sim_comps = {} for sim_name in list(self.sim_map.keys()): if (sim_name == self.fwk_sim_name): @@ -805,32 +750,26 @@ def get_driver_components(self): """ Return a list of driver components, one for each sim. """ - # pytau.start(self.timers['get_driver_components']) driver_list = [] for sim in list(self.sim_map.values()): driver_list.append(sim.driver_comp) - # pytau.stop(self.timers['get_driver_components']) return driver_list def get_framework_components(self): """ Return list of framework components. """ - # pytau.start(self.timers['get_framework_components']) fwk_components = self.fwk_components[:] - # pytau.stop(self.timers['get_framework_components']) return fwk_components def get_init_components(self): """ Return list of init components. """ - # pytau.start(self.timers['get_init_components']) init_list = [] for sim_data in list(self.sim_map.values()): if (sim_data.init_comp): init_list.append(sim_data.init_comp) - # pytau.stop(self.timers['get_init_components']) return init_list def get_sim_parameter(self, sim_name, param): @@ -838,7 +777,6 @@ def get_sim_parameter(self, sim_name, param): Return value of *param* from simulation configuration file for *sim_name*. """ - # pytau.start(self.timers['get_sim_parameter']) try: sim_data = self.sim_map[sim_name] except KeyError: @@ -849,7 +787,6 @@ def get_sim_parameter(self, sim_name, param): except KeyError: val = self.platform_conf[param] self.fwk.debug('Returning value = %s for config parameter %s in simulation %s', val, param, sim_name) - # pytau.start(self.timers['get_sim_parameter']) return val def get_sim_names(self): @@ -863,14 +800,12 @@ def process_service_request(self, msg): Invokes public configuration manager method for a component. Return method's return value. """ - # pytau.start(self.timers['process_service_request']) self.fwk.debug('Configuration Manager received message: %s', str(msg.__dict__)) sim_name = msg.sender_id.get_sim_name() method = getattr(self, msg.target_method) self.fwk.debug('Configuration manager dispatching method %s on simulation %s', method, sim_name) retval = method(sim_name, *msg.args) - # pytau.start(self.timers['process_service_request']) return retval def create_simulation(self, sim_name, config_file, override, sub_workflow=False): @@ -973,10 +908,8 @@ def get_port(self, sim_name, port_name): implementing port *port_name*. """ # print sim_name, port_name - # pytau.start(self.timers['get_port']) sim_data = self.sim_map[sim_name] comp_id = sim_data.port_map[port_name] - # pytau.stop(self.timers['get_port']) return comp_id def get_config_parameter(self, sim_name, param): @@ -1016,16 +949,13 @@ def get_platform_parameter(self, param, silent=False): (default) ``None`` is returned when *param* not found, otherwise an exception is raised. """ - # pytau.start(self.timers['get_platform_parameter']) val = None try: val = self.platform_conf[param] except KeyError: if not silent: self.fwk.warning('CM: No platform data for %s ', param) - # pytau.stop(self.timers['get_platform_parameter']) raise - # pytau.stop(self.timers['get_platform_parameter']) return val def terminate_sim(self, sim_name): diff --git a/ipsframework/ips.py b/ipsframework/ips.py index 04446033..a6fb46dc 100755 --- a/ipsframework/ips.py +++ b/ipsframework/ips.py @@ -62,7 +62,7 @@ import fnmatch import optparse import multiprocessing -from . import platformspec, ipsutil, ipsTiming, checklist +from . import platformspec, ipsutil, checklist import shutil import zipfile import inspect @@ -84,27 +84,7 @@ from .configobj import ConfigObj -def make_timers(): - """ - Create TAU timers to be used to profile simulation execution. - """ - mypid = str(os.getpid()) - timer_funcs = ['__init__', '_dispatch_service_request', '_invoke_framework_comps', - 'run', '_send_monitor_event', 'terminate_all_sims'] - timer_dict = {} - for i in range(len(timer_funcs)): - timer_dict[timer_funcs[i]] = ipsTiming.create_timer("fwk", timer_funcs[i], mypid) - return timer_dict - - -TIMERS = make_timers() -""" A dictionary mapping method names in the `Framework`_ object to tau - timers. -""" - - class Framework: - # @ipsTiming.TauWrap(TIMERS['__init__']) # SIMYAN: added options for creating runspace, run-setup, and running, # added compset_list for list of components to load config files for def __init__(self, do_create_runspace, do_run_setup, do_run, @@ -156,8 +136,6 @@ def __init__(self, do_create_runspace, do_run_setup, do_run, verbose_debug: [boolean] A flag adding more verbose framework debugging (default = False) """ - # self.timers = make_timers() - # start(self.timers['__init__']) # SIMYAN: collect the steps to do in this invocation of the Framework self.ips_dosteps = {} @@ -235,11 +213,6 @@ def __init__(self, do_create_runspace, do_run_setup, do_run, self.resource_manager = ResourceManager(self) self.data_manager = DataManager(self) self.task_manager = TaskManager(self) - ipsTiming.instrument_object_with_tau('Fwk', self, exclude=['__init__']) - ipsTiming.instrument_object_with_tau('ConfigMgr', self.config_manager) - ipsTiming.instrument_object_with_tau('ResourceMgr', self.resource_manager) - ipsTiming.instrument_object_with_tau('EventMgr', self.event_manager) - ipsTiming.instrument_object_with_tau('DataMgr', self.data_manager) # define a Handler which writes INFO messages or higher to the sys.stderr logger = logging.getLogger("FRAMEWORK") self.log_level = logging.WARNING @@ -281,10 +254,8 @@ def __init__(self, do_create_runspace, do_run_setup, do_run, except Exception: self.exception("Problem initializing managers") self.terminate_all_sims(status=Message.FAILURE) - # stop(self.timers['__init__']) raise self.blocked_messages = [] - # stop(self.timers['__init__']) # SIMYAN: determine the sim_root for the Framework to use later fwk_comps = self.config_manager.get_framework_components() main_fwk_comp = self.comp_registry.getEntry(fwk_comps[0]) @@ -340,7 +311,6 @@ def _dispatch_service_request(self, msg): if self.verbose_debug: self.debug('Blocked message : %s', e.__str__()) self.blocked_messages.append(msg) - # stop(self.timers['_dispatch_service_request']) return except Exception as e: # self.exception('Exception handling service message: %s - %s', str(msg.__dict__), str(e)) @@ -441,7 +411,6 @@ def critical(self, *args): print('error in Framework.critical', args) raise - # @ipsTiming.TauWrap(TIMERS['_invoke_framework_comps']) def _invoke_framework_comps(self, fwk_comps, method_name): """ Invoke *method_name* on components in *fwk_comps* (list of component @@ -451,7 +420,6 @@ def _invoke_framework_comps(self, fwk_comps, method_name): are passed to the invoked methods. """ - # start(self.timers['_invoke_framework_comps']) outstanding_fwk_calls = [] for comp_id in fwk_comps: msg = ServiceRequestMessage(self.component_id, @@ -481,15 +449,12 @@ def _invoke_framework_comps(self, fwk_comps, method_name): else: if (msg.status == Message.FAILURE): self.terminate_all_sims(status=Message.FAILURE) - # stop(self.timers['_invoke_framework_comps']) raise msg.args[0] outstanding_fwk_calls.remove(msg.call_id) else: self.error('Framework received unexpected message : %s', str(msg.__dict__)) - # stop(self.timers['invoke_framework_comps']) - # @ipsTiming.TauWrap(TIMERS['run']) def run(self): """ Run the communication outer loop of the framework. @@ -522,7 +487,6 @@ def run(self): :py:meth:`Framework.terminate_sim` is called to trigger normal termination of all component processes. """ - # start(self.timers['run']) try: fwk_comps = self.config_manager.get_framework_components() sim_comps = self.config_manager.get_component_map() @@ -530,7 +494,6 @@ def run(self): except Exception: self.exception('encountered exception during fwk.run() initialization') self.terminate_all_sims(status=Message.FAILURE) - # stop(self.timers['run']) return False # SIMYAN: required fields for the checklist file @@ -644,7 +607,6 @@ def run(self): except Exception: self.exception('encountered exception during fwk.run() genration of call messages') self.terminate_all_sims(status=Message.FAILURE) - # stop(self.timers['run']) return False # send off first round of invocations... @@ -688,7 +650,6 @@ def run(self): except Exception: self.exception('Error dispatching service request message.') self.terminate_all_sims(status=Message.FAILURE) - # stop(self.timers['run']) return False continue elif (msg.__class__.__name__ == 'MethodResultMessage'): @@ -738,8 +699,6 @@ def run(self): self.terminate_all_sims(Message.SUCCESS) self.event_service._print_stats() - # stop(self.timers['run']) - # dumpAll() return True def initiate_new_simulation(self, sim_name): @@ -769,7 +728,6 @@ def initiate_new_simulation(self, sim_name): self.outstanding_calls_list.append(call_id) return - # @ipsTiming.TauWrap(TIMERS['_send_monitor_event']) def _send_monitor_event(self, sim_name='', eventType='', comment='', ok='True'): """ Publish a portal monitor event to the *_IPS_MONITOR* event topic. @@ -783,7 +741,6 @@ def _send_monitor_event(self, sim_name='', eventType='', comment='', ok='True'): whether the event indicates normal simulation execution, or an error condition. """ - # start(self.timers['_send_monitor_event']) if (self.verbose_debug): self.debug('_send_monitor_event(%s - %s)', sim_name, eventType) portal_data = {} @@ -848,8 +805,6 @@ def _send_monitor_event(self, sim_name='', eventType='', comment='', ok='True'): if (self.verbose_debug): self.debug('Publishing %s', str(event_body)) self.event_manager.publish(topic_name, 'IPS_SIM', event_body) - # stop(self.timers['_send_monitor_event']) - return def _send_ftb_event(self, eventType=''): """ @@ -860,7 +815,6 @@ def _send_ftb_event(self, eventType=''): ftb_data['eventtype'] = eventType topic_name = '_IPS_FTB' self.event_manager.publish(topic_name, 'IPS_SIM', ftb_data) - return def _send_dynamic_sim_event(self, sim_name='', event_type='', ok=True): self.debug('_send_dynamic_sim_event(%s:%s)', event_type, sim_name) @@ -871,7 +825,6 @@ def _send_dynamic_sim_event(self, sim_name='', event_type='', ok=True): topic_name = '_IPS_DYNAMIC_SIMULATION' self.debug('Publishing %s', str(event_data)) self.event_manager.publish(topic_name, 'IPS_DYNAMIC_SIM', event_data) - return def send_terminate_msg(self, sim_name, status=Message.SUCCESS): """ @@ -901,7 +854,6 @@ def terminate_all_sims(self, status=Message.SUCCESS): This method remotely invokes the method C{terminate()} on all componnets in the IPS simulation. """ - # start(self.timers['terminate_all_sims']) sim_names = self.config_manager.get_sim_names() # print 'Terminating ', sim_names for sim in sim_names: @@ -912,7 +864,6 @@ def terminate_all_sims(self, status=Message.SUCCESS): except Exception: self.exception('exception encountered while cleaning up config_manager') # sys.exit(status) - # stop(self.timers['terminate_sim']) # SIMYAN: method for modifying the config file with the given parameter to # the new value given @@ -1215,14 +1166,12 @@ def main(argv=None): compset_list, options.debug, options.ftb, options.verbose_debug, options.cmd_nodes, options.cmd_ppn) fwk.run() - ipsTiming.dumpAll('framework') else: fwk = Framework(options.do_create_runspace, options.do_run_setup, options.do_run, cfgFile_list, options.log_file, options.platform_filename, compset_list, options.debug, options.ftb, options.verbose_debug, options.cmd_nodes, options.cmd_ppn) fwk.run() - ipsTiming.dumpAll('framework') except Exception: raise diff --git a/ipsframework/ipsTiming.py b/ipsframework/ipsTiming.py deleted file mode 100755 index e0e5431e..00000000 --- a/ipsframework/ipsTiming.py +++ /dev/null @@ -1,158 +0,0 @@ -# ------------------------------------------------------------------------------- -# Copyright 2006-2012 UT-Battelle, LLC. See LICENSE for more information. -# ------------------------------------------------------------------------------- -""" -Experimental timing of the IPS using TAU -""" - -import os -import inspect -from types import MethodType - - -IPS_TIMING = False -try: - if os.environ['IPS_TIMING'] == '1': - try: - import pytau - except ImportError: - raise - IPS_TIMING = True -except KeyError: - pass - - -def create_timer(name, fnc, pid): - try: - if os.environ['IPS_TIMING'] == '1': - # import pytau - # print 'created a timer', name + '.' + fnc, ' - ', pid - return pytau.profileTimer(name + '.' + fnc, '', str(pid)) - # else: - # print 'timing not on' - except Exception: - # print "*********** NO TIMING *************" - # print e - return None - - -def start(timer): - if timer is not None: - # import pytau - pytau.start(timer) - else: - pass - - -def stop(timer): - if timer is not None: - # import pytau - pytau.stop(timer) - else: - pass - - -def dumpAll(label=""): - try: - if os.environ['IPS_TIMING'] == '1': - # import pytau - if label != "": - pytau.dbDump() - else: - pytau.dbDump(label) - # else: - # print 'timing not on' - except KeyError: - pass - except Exception: - print('something happened during dump') - raise - - -class TauWrap: - def __init__(self, timer): - self.timer = timer - - def __call__(self, func): - def wrapper(*arg, **keywords): - start(self.timer) - try: - res = func(*arg, **keywords) - except Exception: - stop(self.timer) -# dumpAll() - raise - else: - stop(self.timer) -# dumpAll() - return res - return wrapper - - -def weave_tau_timer(self, target): - - def wrapper(self, *args, **kwargs): - timers_dict_name = '_tau_timers_' + str(id(self)) - try: - timer = getattr(self, timers_dict_name)[target.__name__] - except KeyError: - print('weave_tau_timer: Key error : ', target.__name__) - return target(self, *args, **kwargs) -# print 'Starting timer for ', target.__name__, timer - start(timer) - try: - ret_val = target(self, *args, **kwargs) - except Exception: - stop(timer) - raise - stop(timer) -# print 'Stopped timer for ', target.__name__, timer - return ret_val - return wrapper - - -def instrument_object_with_tau(obj_name, obj, exclude=None): - if not IPS_TIMING: - return - if not exclude: - my_exclude = [] - else: - my_exclude = exclude - - timers_dict_name = '_tau_timers_' + str(id(obj)) - try: - timers_dict = getattr(obj, timers_dict_name) - except AttributeError: - timers_dict = {} - raw_method_dict_name = '_raw_method_' + str(id(obj)) - try: - raw_method_dict = getattr(obj, raw_method_dict_name) - except AttributeError: - raw_method_dict = {} - for name, value in obj.__class__.__dict__.items(): - if (inspect.ismethod(getattr(obj, name))): - raw_method_dict[name] = value - pid = os.getpid() - for name, value in obj.__class__.__dict__.items(): - if (name not in my_exclude): - if (callable(value)): - timers_dict[name] = create_timer(obj_name, name, pid) - - for name, method in raw_method_dict.items(): - if (name not in my_exclude): - wrapped_method = weave_tau_timer(obj, method) - method_obj = MethodType(wrapped_method, obj, obj.__class__) - setattr(obj, name, method_obj) - - setattr(obj, timers_dict_name, timers_dict) - setattr(obj, raw_method_dict_name, raw_method_dict) - return - - -""" -t1 = create_timer('test', 'a', str(os.getpid())) -start(t1) -time.sleep(3) -stop(t1) -dumpAll('blargh') -""" diff --git a/ipsframework/runspaceInitComponent.py b/ipsframework/runspaceInitComponent.py index 781b2cd6..f0a5cf0b 100755 --- a/ipsframework/runspaceInitComponent.py +++ b/ipsframework/runspaceInitComponent.py @@ -140,7 +140,6 @@ def init(self, timeStamp): # except OSError, (errno, strerror): # self.services.exception('Error creating directory %s : %s' , # workdir, strerror) -# #pytau.stop(timer) # raise # print 'curdir=', curdir @@ -210,7 +209,6 @@ def step(self, timestamp=0.0): if (errno != 17): self.services.exception('Error creating directory %s : %s', workdir, strerror) - # pytau.stop(timer) raise # copy the input files into the working directory @@ -258,7 +256,6 @@ def step(self, timestamp=0.0): if (errno != 17): self.services.exception('Error creating directory %s : %s', workdir, strerror) - # pytau.stop(timer) raise # print 'FINISHED RUNSPACEINIT' diff --git a/ipsframework/services.py b/ipsframework/services.py index 6efad9cc..37c4e57b 100755 --- a/ipsframework/services.py +++ b/ipsframework/services.py @@ -1,7 +1,7 @@ # ------------------------------------------------------------------------------- # Copyright 2006-2012 UT-Battelle, LLC. See LICENSE for more information. # ------------------------------------------------------------------------------- -from . import messages, ipsutil, ipsLogging, ipsTiming, component +from . import messages, ipsutil, ipsLogging, component import sys import queue import os @@ -90,55 +90,6 @@ def launch(binary, task_name, working_dir, *args, **keywords): return task_name, ret_val -def make_timers_parent(): - """ - Create a list of timers to be applied to methods executed before the new component - object is forked into its own separate process. - """ - pid = str(os.getpid()) - return {'__init__': ipsTiming.create_timer("services", "__init__", pid), - 'get_config_param': ipsTiming.create_timer("services", "get_config_param", pid), - '__initialize__': ipsTiming.create_timer("services", "__initialize__", pid)} - - -def make_timers_child(): - """ - Create a list of timers to be applied to methods executed after the new component - object is forked into its own separate process. - """ - pid = str(os.getpid()) - return {'_init_event_service': ipsTiming.create_timer("services", "_init_event_service", pid), - '_get_elapsed_time': ipsTiming.create_timer("services", "_get_elapsed_time", pid), - '_get_incoming_responses': ipsTiming.create_timer("services", "_get_incoming_responses", pid), - '_wait_msg_response': ipsTiming.create_timer("services", "_wait_msg_response", pid), - '_invoke_service': ipsTiming.create_timer("services", "invoke_service", pid), - '_get_service_response': ipsTiming.create_timer("services", "_get_service_response", pid), - '_send_monitor_event': ipsTiming.create_timer("services", "_send_monitor_event", pid), - 'get_port': ipsTiming.create_timer("services", "get_port", pid), - 'call_nonblocking': ipsTiming.create_timer("services", "call_nonblocking", pid), - 'call': ipsTiming.create_timer("services", "call", pid), - 'wait_call': ipsTiming.create_timer("services", "wait_call", pid), - 'wait_call_list': ipsTiming.create_timer("services", "wait_call_list", pid), - 'launch_task': ipsTiming.create_timer("services", "launch_task", pid), - 'kill_task': ipsTiming.create_timer("services", "kill_task", pid), - 'kill_all_tasks': ipsTiming.create_timer("services", "kill_all_tasks", pid), - 'wait_task_nonblocking': ipsTiming.create_timer("services", "wait_task_nonblocking", pid), - 'wait_task': ipsTiming.create_timer("services", "wait_task", pid), - 'wait_tasklist': ipsTiming.create_timer("services", "wait_tasklist", pid), - 'get_config_param': ipsTiming.create_timer("services", "get_config_param", pid), - 'get_time_loop': ipsTiming.create_timer("services", "get_time_loop", pid), - 'get_working_dir': ipsTiming.create_timer("services", "get_working_dir", pid), - 'stage_input_files': ipsTiming.create_timer("services", "stage_input_files", pid), - 'stage_data_files': ipsTiming.create_timer("services", "stage_data_files", pid), - 'stage_output_files': ipsTiming.create_timer("services", "stage_output_files", pid), - 'stage_nonPS_output_files': ipsTiming.create_timer("services", "stage_nonPS_output_files", pid), - 'stage_PS_output_files': ipsTiming.create_timer("services", "stage_PS_output_files", pid), - 'stage_plasma_state': ipsTiming.create_timer("services", "stage_plasma_state", pid), - 'update_plasma_state': ipsTiming.create_timer("services", "update_plasma_state", pid), - 'update_time_stamp': ipsTiming.create_timer("services", "update_time_stamp", pid), - 'setMonitorURL': ipsTiming.create_timer("services", "setMonitorURL", pid)} - - class ServicesProxy: def __init__(self, fwk, fwk_in_q, svc_response_q, sim_conf, log_pipe_name): @@ -197,16 +148,6 @@ def __init__(self, fwk, fwk_in_q, svc_response_q, sim_conf, log_pipe_name): self.binary_fullpath_cache = {} self.dask_preload = "dask_preload.py" - try: - if os.environ['IPS_TIMING'] == '1': - self.profile = True - except Exception: - pass - ipsTiming.instrument_object_with_tau('services', self, exclude=['__init__']) - - def _make_timers(self): - ipsTiming.instrument_object_with_tau('services', self, exclude=['__init__']) - def __initialize__(self, component_ref): """ Initialize the service proxy object, connecting it to its associated @@ -366,7 +307,6 @@ def _wait_msg_response(self, msg_id, block=True): # time to die! if r.__class__ == messages.ExitMessage: self.debug('%s Exiting', str(self.component_ref.component_id)) - self._cleanup() if r.status == messages.Message.SUCCESS: sys.exit(0) else: @@ -471,15 +411,6 @@ def _send_monitor_event(self, self.publish('_IPS_MONITOR', 'PORTAL_EVENT', event_data) return - def _cleanup(self): - """ - Clean up any state from the services. Called by the terminate method - in the base class for components. - """ - # add anything else to clean up in the services - if self.profile: - ipsTiming.dumpAll('component') - def get_port(self, port_name): """ Return a reference to the component implementing port *port_name*. diff --git a/tests/components/workers/XL_worker.py b/tests/components/workers/XL_worker.py index 48ea9e14..353642fe 100644 --- a/tests/components/workers/XL_worker.py +++ b/tests/components/workers/XL_worker.py @@ -6,40 +6,28 @@ class XL_worker(Component): def __init__(self, services, config): - # self.timer = pytau.profileTimer('XL_worker', "", str(os.getpid())) - # pytau.start(self.timer) Component.__init__(self, services, config) print('Created %s' % (self.__class__)) - # pytau.stop(self.timer) def init(self, timestamp): - # pytau.start(self.timer) print(self.__class__.__name__, ':', 'init() called') print('timestamp = ', timestamp) self.services.log('Initing Worker') - # pytau.stop(self.timer) return [self.__class__.__name__ + ':' + str(timestamp), 234] def step(self, timestamp): - # pytau.start(self.timer) sleep_time = 1 self.services.log('Stepping Worker boogity boogity', self.NPROC, self.BIN_PATH) pid = self.services.launch_task(int(self.NPROC), self.BIN_PATH, './parallel_sleep', str(sleep_time), logfile='my_out'+timestamp) retval = self.services.wait_task(pid) - # pytau.stop(self.timer) return retval def finalize(self, timestamp): - # pytau.start(self.timer) self.services.log('Finalizing Worker') - # pytau.stop(self.timer) def process_event(self, topicName, theEvent): print("Worker: processed ", (topicName, str(theEvent))) def terminate(self, status): - # pytau.start(self.timer) self.services.log('Really Calling terminate()') - # pytau.stop(self.timer) #need to stop the timer here because Component.terminate() will call sys.exit - # pytau.dbDumpIncr('worker') Component.terminate(self, status) diff --git a/tests/components/workers/large_worker.py b/tests/components/workers/large_worker.py index d22fd0ae..2d511ae3 100644 --- a/tests/components/workers/large_worker.py +++ b/tests/components/workers/large_worker.py @@ -6,40 +6,28 @@ class large_worker(Component): def __init__(self, services, config): - # self.timer = pytau.profileTimer('large_worker', "", str(os.getpid())) - # pytau.start(self.timer) Component.__init__(self, services, config) print('Created %s' % (self.__class__)) - # pytau.stop(self.timer) def init(self, timestamp): - # pytau.start(self.timer) print(self.__class__.__name__, ':', 'init() called') print('timestamp = ', timestamp) self.services.log('Initing Worker') - # pytau.stop(self.timer) return [self.__class__.__name__ + ':' + str(timestamp), 234] def step(self, timestamp): - # pytau.start(self.timer) sleep_time = 1 self.services.log('Stepping Worker boogity boogity', self.NPROC, self.BIN_PATH) pid = self.services.launch_task(int(self.NPROC), self.BIN_PATH, './parallel_sleep', str(sleep_time), logfile='my_out'+timestamp) retval = self.services.wait_task(pid) - # pytau.stop(self.timer) return retval def finalize(self, timestamp): - # pytau.start(self.timer) self.services.log('Finalizing Worker') - # pytau.stop(self.timer) def process_event(self, topicName, theEvent): print("Worker: processed ", (topicName, str(theEvent))) def terminate(self, status): - # pytau.start(self.timer) self.services.log('Really Calling terminate()') - # pytau.stop(self.timer) #need to stop the timer here because Component.terminate() will call sys.exit - # pytau.dbDumpIncr('worker') Component.terminate(self, status) diff --git a/tests/components/workers/medium_worker.py b/tests/components/workers/medium_worker.py index 8206a50f..37003855 100644 --- a/tests/components/workers/medium_worker.py +++ b/tests/components/workers/medium_worker.py @@ -6,40 +6,28 @@ class medium_worker(Component): def __init__(self, services, config): - # self.timer = pytau.profileTimer('medium_worker', "", str(os.getpid())) - # pytau.start(self.timer) Component.__init__(self, services, config) print('Created %s' % (self.__class__)) - # pytau.stop(self.timer) def init(self, timestamp): - # pytau.start(self.timer) print(self.__class__.__name__, ':', 'init() called') print('timestamp = ', timestamp) self.services.log('Initing Worker') - # pytau.stop(self.timer) return [self.__class__.__name__ + ':' + str(timestamp), 234] def step(self, timestamp): - # pytau.start(self.timer) sleep_time = 1 self.services.log('Stepping Worker boogity boogity', self.NPROC, self.BIN_PATH) pid = self.services.launch_task(int(self.NPROC), self.BIN_PATH, './parallel_sleep', str(sleep_time), logfile='my_out'+timestamp) retval = self.services.wait_task(pid) - # pytau.stop(self.timer) return retval def finalize(self, timestamp): - # pytau.start(self.timer) self.services.log('Finalizing Worker') - # pytau.stop(self.timer) def process_event(self, topicName, theEvent): print("Worker: processed ", (topicName, str(theEvent))) def terminate(self, status): - # pytau.start(self.timer) self.services.log('Really Calling terminate()') - # pytau.stop(self.timer) #need to stop the timer here because Component.terminate() will call sys.exit - # pytau.dbDumpIncr('worker') Component.terminate(self, status) diff --git a/tests/components/workers/small_worker.py b/tests/components/workers/small_worker.py index 7edfcd99..18a4073d 100644 --- a/tests/components/workers/small_worker.py +++ b/tests/components/workers/small_worker.py @@ -6,40 +6,28 @@ class small_worker(Component): def __init__(self, services, config): - # self.timer = pytau.profileTimer('small_worker', "", str(os.getpid())) - # pytau.start(self.timer) Component.__init__(self, services, config) print('Created %s' % (self.__class__)) - # pytau.stop(self.timer) def init(self, timestamp): - # pytau.start(self.timer) print(self.__class__.__name__, ':', 'init() called') print('timestamp = ', timestamp) self.services.log('Initing Worker') - # pytau.stop(self.timer) return [self.__class__.__name__ + ':' + str(timestamp), 234] def step(self, timestamp): - # pytau.start(self.timer) sleep_time = 1 self.services.log('Stepping Worker boogity boogity', self.NPROC, self.BIN_PATH) pid = self.services.launch_task(int(self.NPROC), self.BIN_PATH, './parallel_sleep', str(sleep_time), logfile='my_out'+timestamp) retval = self.services.wait_task(pid) - # pytau.stop(self.timer) return retval def finalize(self, timestamp): - # pytau.start(self.timer) self.services.log('Finalizing Worker') - # pytau.stop(self.timer) def process_event(self, topicName, theEvent): print("Worker: processed ", (topicName, str(theEvent))) def terminate(self, status): - # pytau.start(self.timer) self.services.log('Really Calling terminate()') - # pytau.stop(self.timer) #need to stop the timer here because Component.terminate() will call sys.exit - # pytau.dbDumpIncr('worker') Component.terminate(self, status)