#include "YacsTrace.hxx"
#include <cstdlib>
+#include <chrono>
+#include <iomanip>
+#include <ctime>
+
#ifdef WIN32
#include <process.h>
#define getpid _getpid
#include <unistd.h>
#endif
-namespace YACS{
- int traceLevel=0;
+namespace YACS {
+ int traceLevel = 0;
+}
+
+void YACS::AppendTimeClock(std::ostream& os)
+{
+ auto now = std::chrono::system_clock::now();
+ auto duration = now.time_since_epoch();
+ auto timestamp = std::chrono::system_clock::to_time_t(now);
+ std::tm *local_time = std::localtime(×tamp);
+ auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
+ os << std::setfill('0') << std::setw(2) << local_time->tm_hour << ":"
+ << std::setw(2) << local_time->tm_min << ":"
+ << std::setw(2) << local_time->tm_sec << "." << std::setw(3) << millis % 1000 << " - ";
}
void AttachDebugger()
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
-#ifndef __YACSTRACE_HXX__
-#define __YACSTRACE_HXX__
+#pragma once
#include "YACSBasesExport.hxx"
#include "Exception.hxx"
#include <sstream>
#ifdef _DEVDEBUG_
-#define DEBTRACE(msg) {std::cerr<<std::flush<<__FILE__<<" ["<<__LINE__<<"] : "<<msg<<std::endl<<std::flush;}
+#define DEBTRACE(msg) { std::cerr << std::flush << __FILE__ << " [" << __LINE__ << "] : " << msg << std::endl << std::flush; }
#else
#define DEBTRACE(msg)
#endif
-namespace YACS{
-extern YACSBASES_EXPORT int traceLevel;
+namespace YACS
+{
+ extern YACSBASES_EXPORT int traceLevel;
+ void AppendTimeClock(std::ostream& os);
}
//! YACSTRACE macro for dynamic trace: print only if YACS_TRACELEVEL environment variable is set and level is less than its value
-#define YACSTRACE(level,msg) {if(YACS::traceLevel >=level)std::cerr<<__FILE__<<" ["<<__LINE__<<"] : "<<msg<<std::endl;}
+#define YACSTRACE(level,msg) { if(YACS::traceLevel >=level) \
+ { \
+ AppendTimeClock(std::cerr); \
+ std::cerr << __FILE__ << " [" << __LINE__ << "] : " << msg << std::endl; \
+ } }
+
+#define ERROR_YACSTRACE(msg) YACSTRACE(0,msg)
+
+#define WARNING_YACSTRACE(msg) YACSTRACE(1,msg)
+
+#define INFO_YACSTRACE(msg) YACSTRACE(2,msg)
+
+#define DEBUG_YACSTRACE(msg) YACSTRACE(7,msg)
+
+#define GURU_YACSTRACE(msg) YACSTRACE(99,msg)
//! YASSERT macro is always defined, used like assert, but throw a YACS::Exception instead of abort
-#define YASSERT(val) {if(!(val)){std::stringstream mess; mess<<__FILE__<<" ["<<__LINE__<<"] : assertion "<<#val<<" failed"; throw YACS::Exception(mess.str());}}
+#define YASSERT(val) { if( !(val) ) { std::ostringstream mess; mess << __FILE__ << " [" <<__LINE__<< "] : assertion " << #val << " failed"; throw YACS::Exception(mess.str()); } }
void AttachDebugger();
-
-#endif
DEBTRACE("nbOfElts=" << nbOfElts);
DEBTRACE("nbOfBr=" << nbOfBr);
+ INFO_YACSTRACE("nbOfBr (" << getName() << ") = " << nbOfBr);
if(nbOfEltsToDo==0)
{
if (isDestructible())
{
Node* node = _dataPort->getNode();
- YASSERT(node);
ElementaryNode * father = dynamic_cast<ElementaryNode*>(node);
if (father)
{
throw Exception("In DistributedPythonNode the ref in NULL ! ");
- DEBTRACE( "---------------End PyfuncSerNode::load function---------------" );
+ DEBUG_YACSTRACE( "---------------End PyfuncSerNode::load function---------------" );
}
}
void DistributedPythonNode::execute()
{
- YACSTRACE(1,"+++++++++++++++++ DistributedPythonNode::execute: " << getName() << " " << getFname() << " +++++++++++++++++" );
+ GURU_YACSTRACE("+++++++++++++++++ DistributedPythonNode::execute: " << getName() << " " << getFname() << " +++++++++++++++++" );
//////
PyObject* ob;
if(!_pyfuncSer)
{
AutoGIL agil;
- DEBTRACE( "---------------DistributedPythonNode::inputs---------------" );
+ GURU_YACSTRACE( "---------------DistributedPythonNode::inputs---------------" );
args = PyTuple_New(getNumberOfInputPorts()) ;
int pos=0;
for(list<InputPort *>::iterator iter2 = _setOfInputPort.begin(); iter2 != _setOfInputPort.end(); iter2++,pos++)
Py_DECREF(serializationInput);
}
//serializationInputCorba[serializationInputC.length()]='\0';
- DEBTRACE( "-----------------DistributedPythonNode starting remote python invocation-----------------" );
+ DEBUG_YACSTRACE( "-----------------DistributedPythonNode starting remote python invocation-----------------" );
Engines::pickledArgs *resultCorba;
try
{
_errorDetails=msg;
throw Exception(msg);
}
- DEBTRACE( "-----------------DistributedPythonNode end of remote python invocation-----------------" );
+ DEBUG_YACSTRACE( "-----------------DistributedPythonNode end of remote python invocation-----------------" );
//
delete serializationInputCorba;
char *resultCorbaC=new char[resultCorba->length()+1];
delete [] resultCorbaC;
PyTuple_SetItem(args,0,resultPython);
PyObject *finalResult=PyObject_CallObject(_pyfuncUnser,args);
- DEBTRACE( "-----------------DistributedPythonNode::outputs-----------------" );
+ GURU_YACSTRACE( "-----------------DistributedPythonNode::outputs-----------------" );
if(finalResult == NULL)
{
std::stringstream msg;
for(list<OutputPort *>::iterator iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); iter++, pos++)
{
OutputPyPort *p=(OutputPyPort *)*iter;
- DEBTRACE( "port name: " << p->getName() );
- DEBTRACE( "port kind: " << p->typeName() );
- DEBTRACE( "port pos : " << pos );
+ GURU_YACSTRACE( "port name: " << p->getName() );
+ GURU_YACSTRACE( "port kind: " << p->typeName() );
+ GURU_YACSTRACE( "port pos : " << pos );
if(PyTuple_Check(finalResult))ob=PyTuple_GetItem(finalResult,pos) ;
else ob=finalResult;
- DEBTRACE( "ob refcnt: " << ob->ob_refcnt );
+ GURU_YACSTRACE( "ob refcnt: " << ob->ob_refcnt );
p->put(ob);
}
}
throw;
}
}
- DEBTRACE( "++++++++++++++ End DistributedPythonNode::execute: " << getName() << " ++++++++++++++++++++" );
+ GURU_YACSTRACE( "++++++++++++++ End DistributedPythonNode::execute: " << getName() << " ++++++++++++++++++++" );
}
std::string DistributedPythonNode::getEffectiveKindOfServer() const
{
if( exc )
{
- DEBTRACE( "An exception was thrown!" );
- DEBTRACE( "The raised exception is of Type:" << exc->_name() );
+ GURU_YACSTRACE( "An exception was thrown!" );
+ GURU_YACSTRACE( "The raised exception is of Type:" << exc->_name() );
CORBA::SystemException* sysexc;
sysexc=CORBA::SystemException::_downcast(exc);
if(sysexc != NULL)
{
// It's a SystemException
- DEBTRACE( "minor code: " << sysexc->minor() );
- DEBTRACE( "completion code: " << sysexc->completed() );
+ GURU_YACSTRACE( "minor code: " << sysexc->minor() );
+ GURU_YACSTRACE( "completion code: " << sysexc->completed() );
std::string text="Execution problem: ";
std::string excname=sysexc->_name();
if(excname == "BAD_OPERATION")
}
else
{
- DEBTRACE(sysexc->NP_minorString() );
+ GURU_YACSTRACE(sysexc->NP_minorString() );
text=text+"System Exception "+ excname;
}
_errorDetails=text;
const SALOME::SALOME_Exception* salexc;
if(anyExcept >>= salexc)
{
- DEBTRACE("SALOME_Exception: "<< salexc->details.sourceFile);
- DEBTRACE("SALOME_Exception: "<<salexc->details.lineNumber);
+ GURU_YACSTRACE("SALOME_Exception: "<< salexc->details.sourceFile);
+ GURU_YACSTRACE("SALOME_Exception: "<<salexc->details.lineNumber);
_errorDetails=salexc->details.text;
throw Exception("Execution problem: Salome Exception occurred" + getErrorDetails() );
}
{
//pass outargsname and dict serialized
SALOME::SenderByte_var serializationInputRef = serializationInputCorba->_this();
+ DEBUG_YACSTRACE("Before execute first of " << getId());
_pynode->executeFirst(serializationInputRef);
//serializationInput and serializationInputCorba are no more needed for server. Release it.
serializationInput.set(nullptr);
resultCorba.reset( _pynode->executeSecond(myseq) );
+ DEBUG_YACSTRACE("After execute second of " << getId());
}
catch( const SALOME::SALOME_Exception& ex )
{
for(iter = _setOfOutputPort.begin(); iter != _setOfOutputPort.end(); ++iter)
{
OutputPyPort *p=(OutputPyPort *)*iter;
+ DEBUG_YACSTRACE("Start of dealing with output " << p->getName() << " of "<< getId());
DEBTRACE( "port name: " << p->getName() );
DEBTRACE( "port kind: " << p->edGetType()->kind() );
DEBTRACE( "port pos : " << pos );
throw YACS::ENGINE::ConversionException(msg.str());
}
UnlinkOnDestructorIfProxy(ob);
+ DEBUG_YACSTRACE("Assign PyObj output " << p->getName() << " of "<< getId());
p->put( ob );
+ DEBUG_YACSTRACE("End of assign PyObj output " << p->getName() << " of "<< getId());
}
pos++;
}
freeKernelPynode();
bool dummy;
Engines::Container_var cont(GetContainerObj(this,dummy));
- cont->removePyScriptNode(getName().c_str());
+ cont->removePyScriptNode(getId().c_str());
}
DEBTRACE( "++++++++++++++ ENDOF PyNode::executeRemote: " << getName() << " ++++++++++++++++++++" );
}
if(isUsingPythonCache())
return "DEFAULT_NAME_FOR_UNIQUE_PYTHON_NODE_ENTRY";
else
- return getName();
+ return getId();
}
bool PythonNode::isUsingPythonCache()const
#include "SALOME_NamingService_Wrapper.hxx"
#include "SALOME_ResourcesManager.hxx"
#include "SALOME_ContainerManager.hxx"
+
#include "Container.hxx"
#include "AutoLocker.hxx"
void SalomeContainerTools::setProperty(const std::string& name, const std::string& value)
{
- //DEBTRACE("SalomeContainer::setProperty : " << name << " ; " << value);
+ //DEBUG_YACSTRACE("SalomeContainer::setProperty : " << name << " ; " << value);
// Container Part
if (name == "container_name")
_params.container_name = CORBA::string_dup(value.c_str());
bool isEmptyName;
std::string str(sct.getNotNullContainerName(cont,askingNode,isEmptyName));
- DEBTRACE("SalomeContainer::start " << str <<";"<< sct.getHostName() );
+ DEBUG_YACSTRACE("SalomeContainer::start " << str <<";"<< sct.getHostName() );
// Finalize parameters with components found in the container
myparams.mode="get";
try
{
- DEBTRACE("GiveContainer " << str << " mode " << myparams.mode);
+ DEBUG_YACSTRACE("GiveContainer " << str << " mode " << myparams.mode);
trueCont=contManager->GiveContainer(myparams);
}
catch( const SALOME::SALOME_Exception& ex )
std::string msg="SalomeContainer::start : no existing container : ";
msg += '\n';
msg += ex.details.text.in();
- DEBTRACE( msg );
+ DEBUG_YACSTRACE( msg );
}
catch(...)
{
if(!CORBA::is_nil(trueCont))
{
shutdownLevel=3;
- DEBTRACE( "container found: " << str << " " << shutdownLevel );
+ DEBUG_YACSTRACE( "container found: " << str << " " << shutdownLevel );
}
else
{
shutdownLevel=2;
myparams.mode="start";
- DEBTRACE( "container not found: " << str << " " << shutdownLevel);
+ DEBUG_YACSTRACE( "container not found: " << str << " " << shutdownLevel);
}
}
{
// --- GiveContainer is used in batch mode to retreive launched containers,
// and is equivalent to StartContainer when not in batch.
- DEBTRACE("GiveContainer " << str << " mode " << myparams.mode);
+ DEBUG_YACSTRACE("GiveContainer " << str << " mode " << myparams.mode);
trueCont=contManager->GiveContainer(myparams);
}
catch( const SALOME::SALOME_Exception& ex )
catch(CORBA::COMM_FAILURE&)
{
//std::cerr << "SalomeContainer::start : CORBA Comm failure detected. Make another try!" << std::endl;
- DEBTRACE("SalomeContainer::start :" << str << " :CORBA Comm failure detected. Make another try!");
+ DEBUG_YACSTRACE("SalomeContainer::start :" << str << " :CORBA Comm failure detected. Make another try!");
nbTries++;
if(nbTries > 5)
throw Exception("SalomeContainer::start : Unable to launch container in Salome : CORBA Comm failure detected");
CORBA::String_var containerName(trueCont->name()),hostName(trueCont->getHostName());
//std::cerr << "SalomeContainer launched : " << containerName << " " << hostName << " " << trueCont->getPID() << std::endl;
- DEBTRACE("SalomeContainer launched : " << containerName << " " << hostName << " " << trueCont->getPID() );
+ DEBUG_YACSTRACE("SalomeContainer launched : NS entry : " << containerName << " PID : " << trueCont->getPID() );
}
CORBA::Object_ptr SalomeContainerToolsBase::LoadComponent(SalomeContainerHelper *launchModeType, Container *cont, Task *askingNode)
{
- DEBTRACE("SalomeContainer::loadComponent ");
+ DEBUG_YACSTRACE("SalomeContainer::loadComponent ");
const ComponentInstance *inst(askingNode?askingNode->getComponent():0);
{
YACS::BASES::AutoLocker<Container> alck(cont);//To be sure
int item=0;
for(itm = properties.begin(); itm != properties.end(); ++itm, item++)
{
- DEBTRACE("envname="<<itm->first<<" envvalue="<< itm->second);
+ DEBUG_YACSTRACE("envname="<<itm->first<<" envvalue="<< itm->second);
env[item].key= CORBA::string_dup(itm->first.c_str());
env[item].value <<= itm->second.c_str();
}
throw YACS::ENGINE::ConversionException(msg.str());
}
int length=PySequence_Size(o);
- DEBTRACE("length: " << length );
+ GURU_YACSTRACE("convertToYacsSequence : length = " << length);
v.resize(length);
for(int i=0;i<length;i++)
{
PyObject *item=PySequence_ITEM(o,i);
+ GURU_YACSTRACE("convertToYacsSequence : analyze if proxy");
bool somthingToDo = YACS::ENGINE::PythonEntry::IsProxy(item);
if( somthingToDo )
{
+ GURU_YACSTRACE("convertToYacsSequence : it s proxy -> unlink");
YACS::ENGINE::PythonEntry::UnlinkOnDestructorIfProxy(item);
+ GURU_YACSTRACE("convertToYacsSequence : it s proxy -> incrRef");
YACS::ENGINE::PythonEntry::IfProxyDoSomething(item,"incrRef");
}
#ifdef _DEVDEBUG_
{
//It's a python pickled object, unpickled it
PyObject* mod=PyImport_ImportModule("pickle");
+ GURU_YACSTRACE("convertFromYacsObjref : unpickling...");
PyObject *ob=PyObject_CallMethod(mod,(char *)"loads",(char *)"y#",o.c_str(),o.length());
+ GURU_YACSTRACE("convertFromYacsObjref : unpickling done...");
DEBTRACE(PyObject_Repr(ob));
Py_DECREF(mod);
+ GURU_YACSTRACE("convertFromYacsObjref : Analyze if it's a proxy");
bool somthingToDo = YACS::ENGINE::PythonEntry::IsProxy(ob);
if( somthingToDo )
{
// no incrRef here because the incrRef has been done before dumps that construct o.
+ GURU_YACSTRACE("convertFromYacsObjref : It's a proxy -> activate on deletion");
YACS::ENGINE::PythonEntry::UnlinkOnDestructorIfProxy(ob);
}
if(ob==NULL)