From e992efceda1b288c6bc7a719ab6ec747c27ca6b0 Mon Sep 17 00:00:00 2001 From: Anthony Geay Date: Mon, 18 Sep 2023 08:33:37 +0200 Subject: [PATCH] [EDF28561] : Set of toolkit to ease performance measures --- idl/SALOME_ContainerManager.idl | 2 -- src/Container/SALOME_ContainerManager.cxx | 15 ----------- src/Container/SALOME_ContainerManager.hxx | 3 --- src/Launcher_SWIG/Launcher.i | 33 +++++++++++++++++++++-- src/ResourcesManager/ResourcesManager.cxx | 5 ++++ src/ResourcesManager/ResourcesManager.hxx | 2 ++ 6 files changed, 38 insertions(+), 22 deletions(-) diff --git a/idl/SALOME_ContainerManager.idl b/idl/SALOME_ContainerManager.idl index 207b0ed9f..9251df6ab 100644 --- a/idl/SALOME_ContainerManager.idl +++ b/idl/SALOME_ContainerManager.idl @@ -97,8 +97,6 @@ interface ContainerManager void SetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond(in long timeInMS); - void MakeThisProcessAServer() raises (SALOME::SALOME_Exception); - void SetOverrideEnvForContainers(in KeyValDict env); KeyValDict GetOverrideEnvForContainers(); diff --git a/src/Container/SALOME_ContainerManager.cxx b/src/Container/SALOME_ContainerManager.cxx index 23788a1fd..adff087e5 100644 --- a/src/Container/SALOME_ContainerManager.cxx +++ b/src/Container/SALOME_ContainerManager.cxx @@ -227,21 +227,6 @@ void SALOME_ContainerManager::SetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSeco this->_delta_time_ns_lookup_in_ms = timeInMS; } -/*! - * Launch a this->_orb->run() in order to respond to CORBA requests from the outside. - */ -void SALOME_ContainerManager::MakeThisProcessAServer() -{ - if(_server_thread_launched) - { - THROW_SALOME_CORBA_EXCEPTION("orb.run() thread has already been launched. You are not supposed to launch it more than once",SALOME::BAD_PARAM); - } - _server_thread_launched = true; - auto ORBRunLauncher = [](CORBA::ORB_var orb) { MESSAGE("[SALOME_ContainerManager::MakeThisProcessAServer] ORB is running in a thread ...."); orb->run(); }; - std::thread t(ORBRunLauncher,this->_orb); - t.detach(); -} - //============================================================================= //! Loop on all the containers listed in naming service, ask shutdown on each /*! CORBA Method: diff --git a/src/Container/SALOME_ContainerManager.hxx b/src/Container/SALOME_ContainerManager.hxx index 5f8388e51..67a333482 100644 --- a/src/Container/SALOME_ContainerManager.hxx +++ b/src/Container/SALOME_ContainerManager.hxx @@ -69,8 +69,6 @@ public: void SetDeltaTimeBetweenNSLookupAtLaunchTimeInMilliSecond(CORBA::Long timeInMS) override; - void MakeThisProcessAServer(); - static const char *_ContainerManagerNameInNS; protected: @@ -214,6 +212,5 @@ private: std::vector< std::pair > _override_env; int _time_out_in_second; int _delta_time_ns_lookup_in_ms; - bool _server_thread_launched = false; }; #endif diff --git a/src/Launcher_SWIG/Launcher.i b/src/Launcher_SWIG/Launcher.i index b3c3401aa..f01e3126e 100644 --- a/src/Launcher_SWIG/Launcher.i +++ b/src/Launcher_SWIG/Launcher.i @@ -173,7 +173,7 @@ public: ResourcesManager_cpp(const char *xmlFilePath); std::vector GetFittingResources(const resourceParams& params); void WriteInXmlFile(std::string xml_file); - + void DeleteAllResourcesInCatalog(); %extend { ResourceDefinition_cpp GetResourceDefinition(const std::string& name) @@ -336,9 +336,38 @@ def ResourceDefinition_cpp_repr(self): def ResourcesManager_cpp_GetList(self): return {name:self.GetResourceDefinition(name) for name in self.GetListOfEntries()} +def ResourcesManager_cpp___getitem__(self,name): + return self.GetResourceDefinition(name) + +def ResourcesManager_cpp___repr__(self): + return str( self.GetList() ) + +def RetrieveRMCppSingleton(): + import KernelLauncher + return HandleToLocalInstance( KernelLauncher.RetrieveInternalInstanceOfLocalCppResourcesManager() ) + +def GetPlayGroundInsideASlurmJob(): + import subprocess as sp + cont = sp.check_output(["srun","hostname"]) + nodesMul = [elt for elt in cont.decode().split("\n") if elt != ""] + from collections import defaultdict + d = defaultdict(int) + for elt in nodesMul: + d[elt]+=1 + return d + +def BuildCatalogFromScratch(protocol): + import os + d = GetPlayGroundInsideASlurmJob() + rmcpp = RetrieveRMCppSingleton() + rmcpp.DeleteAllResourcesInCatalog() + for k,v in d.items(): + contRes = CreateContainerResource(hostname=k,applipath=os.environ["APPLI"],protocol=protocol,nbOfNodes=v) + rmcpp.AddResourceInCatalog(contRes) ResourceDefinition_cpp.repr = ResourceDefinition_cpp_repr ResourceDefinition_cpp.__repr__ = ResourceDefinition_cpp_repr ResourcesManager_cpp.GetList = ResourcesManager_cpp_GetList - +ResourcesManager_cpp.__getitem__ = ResourcesManager_cpp___getitem__ +ResourcesManager_cpp.__repr__ = ResourcesManager_cpp___repr__ %} diff --git a/src/ResourcesManager/ResourcesManager.cxx b/src/ResourcesManager/ResourcesManager.cxx index 6e8535a7e..fa528d523 100644 --- a/src/ResourcesManager/ResourcesManager.cxx +++ b/src/ResourcesManager/ResourcesManager.cxx @@ -355,6 +355,11 @@ ResourcesManager_cpp::AddResourceInCatalog(const ParserResourcesType & new_resou _resourcesList[new_resource.Name] = new_resource; } +void ResourcesManager_cpp::DeleteAllResourcesInCatalog() +{ + _resourcesList.clear(); +} + //============================================================================= /*! * Deletes a resource from the catalog diff --git a/src/ResourcesManager/ResourcesManager.hxx b/src/ResourcesManager/ResourcesManager.hxx index d72308f25..95e13c541 100644 --- a/src/ResourcesManager/ResourcesManager.hxx +++ b/src/ResourcesManager/ResourcesManager.hxx @@ -82,6 +82,8 @@ class RESOURCESMANAGER_EXPORT ResourcesManager_cpp std::string Find(const std::string& policy, const std::vector& listOfResources) const; void AddResourceInCatalog (const ParserResourcesType & new_resource); + + void DeleteAllResourcesInCatalog(); void DeleteResourceInCatalog(const char * name); -- 2.39.2