X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FContainer%2FComponent_i.cxx;h=cad8ba99c696dac43d93553e1368a4c16bf9d1ed;hb=1f742af859d50d34c63f9dc02f9a705089bf060e;hp=eeed8aed1cbadafd5ed1200199f722cf7306fb5a;hpb=61d4fc88c862e718985aa6e9b1bf72f055553eee;p=modules%2Fkernel.git diff --git a/src/Container/Component_i.cxx b/src/Container/Component_i.cxx index eeed8aed1..cad8ba99c 100644 --- a/src/Container/Component_i.cxx +++ b/src/Container/Component_i.cxx @@ -1,21 +1,42 @@ -using namespace std; -//============================================================================= -// File : Component_i.cxx -// Created : jeu jui 12 08:04:40 CEST 2001 -// Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA -// Project : SALOME -// Copyright : EDF 2001 - CEA 2001 -// $Header$ -//============================================================================= +// SALOME Container : implementation of container and engine for Kernel +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : Component_i.cxx +// Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA +// Module : SALOME +// $Header$ +using namespace std; #include "SALOME_Component_i.hxx" #include "RegistryConnexion.hxx" #include "OpUtil.hxx" #include #include +#include #include "utilities.h" extern bool _Sleeping ; +static Engines_Component_i * theEngines_Component ; Engines_Component_i::Engines_Component_i() { @@ -28,8 +49,10 @@ Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb, const char *instanceName, const char *interfaceName, bool notif) : - _instanceName(instanceName), _interfaceName(interfaceName), - _myConnexionToRegistry(0), _ThreadId(0) , _graphName("") , _nodeName("") { + _instanceName(instanceName), + _interfaceName(interfaceName), + _myConnexionToRegistry(0), + _ThreadId(0) , _ThreadCpuUsed(0) , _Executed(false) , _graphName("") , _nodeName("") { MESSAGE("Component constructor with instanceName "<< _instanceName); _orb = CORBA::ORB::_duplicate(orb); _poa = PortableServer::POA::_duplicate(poa); @@ -52,8 +75,7 @@ Engines_Component_i::Engines_Component_i(CORBA::ORB_ptr orb, : _instanceName(instanceName), _interfaceName(interfaceName), _myConnexionToRegistry(0), - _ThreadId(0) -{ + _ThreadId(0) , _ThreadCpuUsed(0) , _Executed(false) , _graphName("") , _nodeName("") { // MESSAGE("Component constructor with instanceName "<< _instanceName); _orb = CORBA::ORB::_duplicate(orb); _poa = PortableServer::POA::_duplicate(poa); @@ -113,11 +135,40 @@ PortableServer::ObjectId * Engines_Component_i::getId() return _id ; } +void Engines_Component_i::setProperties(const Engines::FieldsDict& dico) +{ + _fieldsDict.clear(); + for (CORBA::ULong i=0; ilength(_fieldsDict.size()); + map::iterator it; + CORBA::ULong i = 0; + for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++, i++) + { + std::string cle((*it).first); + copie[i].key = CORBA::string_dup(cle.c_str()); + copie[i].value = _fieldsDict[cle]; + } + return copie._retn(); +} + void Engines_Component_i::beginService(const char *serviceName) { - MESSAGE("Send BeginService notification for " << serviceName << endl + MESSAGE(pthread_self() << "Send BeginService notification for " << serviceName << endl << "Component instance : " << _instanceName << endl << endl); _ThreadId = pthread_self() ; + _StartUsed = 0 ; + _StartUsed = CpuUsed_impl() ; + _ThreadCpuUsed = 0 ; + _Executed = true ; _serviceName = serviceName ; if ( pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS , NULL ) ) { perror("pthread_setcanceltype ") ; @@ -127,15 +178,33 @@ void Engines_Component_i::beginService(const char *serviceName) perror("pthread_setcancelstate ") ; exit(0) ; } - MESSAGE("Return from BeginService for " << serviceName - << " ThreadId " << _ThreadId - << " _graphName " << _graphName << " _nodeName " << _nodeName ); +// MESSAGE(pthread_self() << " Return from BeginService for " << serviceName +// << " ThreadId " << _ThreadId << " StartUsed " << _StartUsed +// << " _graphName " << _graphName << " _nodeName " << _nodeName ); + + // --- for supervisor : all strings given with setProperties + // are set in environment + bool overwrite = true; + map::iterator it; + for (it = _fieldsDict.begin(); it != _fieldsDict.end(); it++) + { + std::string cle((*it).first); + if ((*it).second.type()->kind() == CORBA::tk_string) + { + const char* value; + (*it).second >>= value; + int ret = setenv(cle.c_str(), value, overwrite); + MESSAGE("--- setenv: "< 0 && pthread_self() != _ThreadId ) { RetVal = Killer( _ThreadId , 0 ) ; @@ -247,6 +316,71 @@ bool Engines_Component_i::Resume_impl() { } +void SetCpuUsed() { + theEngines_Component->SetCurCpu() ; +} +void Engines_Component_i::SetCurCpu() { + _ThreadCpuUsed = CpuUsed() ; +// MESSAGE(pthread_self() << " Engines_Component_i::SetCurCpu() _ThreadCpuUsed " << _ThreadCpuUsed) ; +} + +#include +#include +#include + +long Engines_Component_i::CpuUsed() { + long cpu = 0 ; + struct rusage usage ; + if ( _ThreadId || _Executed ) { + if ( getrusage( RUSAGE_SELF , &usage ) == -1 ) { + perror("Engines_Component_i::CpuUsed") ; + return 0 ; + } + cpu = usage.ru_utime.tv_sec - _StartUsed ; +// cout << pthread_self() << " Engines_Component_i::CpuUsed " << " " << _serviceName +// << usage.ru_utime.tv_sec << " - " << _StartUsed << " = " << cpu << endl ; + } + else { +// cout << pthread_self() << "Engines_Component_i::CpuUsed _ThreadId " << _ThreadId << " " << _serviceName +// << " _StartUsed " << _StartUsed << endl ; + } + return cpu ; +} + +long Engines_Component_i::CpuUsed_impl() { + long cpu = 0 ; + if ( _ThreadId || _Executed ) { + if ( _ThreadId > 0 ) { + if ( pthread_self() != _ThreadId ) { + if ( _Sleeping ) { + } + else { +// Get Cpu in the appropriate thread with that object !... + theEngines_Component = this ; + Killer( _ThreadId ,SIGUSR1 ) ; + } + cpu = _ThreadCpuUsed ; + } + else { + _ThreadCpuUsed = CpuUsed() ; + cpu = _ThreadCpuUsed ; +// cout << pthread_self() << " Engines_Component_i::CpuUsed_impl " << _serviceName << " " << cpu +// << endl ; + } + } + else { + cpu = _ThreadCpuUsed ; +// cout << pthread_self() << " Engines_Component_i::CpuUsed_impl " << _serviceName << " " << cpu +// << endl ; + } + } + else { +// cout << pthread_self() << "Engines_Component_i::CpuUsed_impl _ThreadId " << _ThreadId << " " +// << _serviceName << " _StartUsed " << _StartUsed << endl ; + } + return cpu ; +} + // Send message to event channel void Engines_Component_i::sendMessage(const char *event_type, const char *message) {