version 1.51, 2008/06/26 18:32:39
|
version 1.56, 2008/10/22 08:11:24
|
|
|
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
#include <Pegasus/Common/Config.h> | #include <Pegasus/Common/Config.h> |
|
#include <Pegasus/Common/Constants.h> |
#include <Pegasus/Common/Tracer.h> | #include <Pegasus/Common/Tracer.h> |
#include <Pegasus/Common/TraceFileHandler.h> | #include <Pegasus/Common/TraceFileHandler.h> |
#include <Pegasus/Common/TraceLogHandler.h> | #include <Pegasus/Common/TraceLogHandler.h> |
|
#include <Pegasus/Common/TraceMemoryHandler.h> |
#include <Pegasus/Common/Thread.h> | #include <Pegasus/Common/Thread.h> |
#include <Pegasus/Common/System.h> | #include <Pegasus/Common/System.h> |
#include <Pegasus/Common/HTTPMessage.h> | #include <Pegasus/Common/HTTPMessage.h> |
|
#include <Pegasus/Common/StringConversion.h> |
|
#include <Pegasus/Common/FileSystem.h> |
| |
PEGASUS_USING_STD; | PEGASUS_USING_STD; |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
|
/** |
|
String constants for naming the various Trace components. |
|
These strings will used when turning on tracing for the respective |
|
components. The component list must be kept in sync with the |
|
TraceComponentId enumeration. |
|
|
|
The tracer uses the _traceComponentMask in form of a 64bit field to mask |
|
the user configured components. |
|
Please ensure that no more than 64 components are specified in the |
|
TRACE_COMPONENT_LIST. |
|
|
|
The following example shows the usage of trace component names. |
|
The setTraceComponents method is used to turn on tracing for the |
|
components: Config and Repository. The component names are passed as a |
|
comma separated list. |
|
|
|
Tracer::setTraceComponents("Config,Repository"); |
|
*/ |
|
static char const* TRACE_COMPONENT_LIST[] = |
|
{ |
|
"XmlParser", |
|
"XmlWriter", |
|
"XmlReader", |
|
"XmlIO", |
|
"Http", |
|
"CimData", |
|
"Repository", |
|
"Dispatcher", |
|
"OsAbstraction", |
|
"Config", |
|
"IndHandler", |
|
"Authentication", |
|
"Authorization", |
|
"UserManager", |
|
"Registration", |
|
"Shutdown", |
|
"Server", |
|
"IndicationService", |
|
"IndicationServiceInternal", |
|
"MessageQueueService", |
|
"ProviderManager", |
|
"ObjectResolution", |
|
"WQL", |
|
"CQL", |
|
"Thread", |
|
"IPC", |
|
"IndicationHandlerService", |
|
"CIMExportRequestDispatcher", |
|
"SSL", |
|
"ControlProvider", |
|
"CIMOMHandle", |
|
"BinaryMessageHandler", |
|
"L10N", |
|
"ExportClient", |
|
"Listener", |
|
"DiscardedData", |
|
"ProviderAgent", |
|
"IndicationFormatter", |
|
"StatisticalData", |
|
"CMPIProvider", |
|
"IndicationGeneration", |
|
"IndicationReceipt", |
|
"CMPIProviderInterface", |
|
"WsmServer", |
|
"LogMessages" |
|
}; |
|
|
| |
// Defines the value values for trace facilities | // Defines the value values for trace facilities |
// Keep the TRACE_FACILITY_LIST in sync with the TRACE_FACILITY_INDEX, | // Keep the TRACE_FACILITY_LIST in sync with the TRACE_FACILITY_INDEX, |
|
|
{ | { |
"File", | "File", |
"Log", | "Log", |
|
"Memory", |
0 | 0 |
}; | }; |
| |
|
|
| |
// Initialize public indicator of trace state | // Initialize public indicator of trace state |
Boolean Tracer::_traceOn = false; | Boolean Tracer::_traceOn = false; |
|
Uint32 Tracer::_traceLevelMask=0; |
|
Uint64 Tracer::_traceComponentMask=(Uint64)0; |
| |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
// Tracer constructor | // Tracer constructor |
|
|
// Single Instance of Tracer is maintained for each process. | // Single Instance of Tracer is maintained for each process. |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
Tracer::Tracer() | Tracer::Tracer() |
: _traceComponentMask(new Boolean[_NUM_COMPONENTS]), |
: _traceMemoryBufferSize(PEGASUS_TRC_DEFAULT_BUFFER_SIZE_KB), |
_traceFacility(TRACE_FACILITY_FILE), | _traceFacility(TRACE_FACILITY_FILE), |
_traceLevelMask(0), |
_runningOOP(false), |
_traceHandler(0) | _traceHandler(0) |
{ | { |
// Instantiate trace handler according to configured facility |
|
_traceHandler.reset( getTraceHandler(_traceFacility) ); |
|
| |
// Initialize ComponentMask array to false |
// The tracer uses a 64bit field to mask the user configured components. |
for (Uint32 index=0;index < _NUM_COMPONENTS; |
// This assert ensures that no more than 64 components are specified in the |
(_traceComponentMask.get())[index++]=false); |
// TRACE_COMPONENT_LIST. |
|
PEGASUS_ASSERT(_NUM_COMPONENTS <= 64); |
| |
// NO componets are set |
// Instantiate trace handler according to configured facility |
_componentsAreSet=false; |
_setTraceHandler(_traceFacility); |
} | } |
| |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
|
|
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
Tracer::~Tracer() | Tracer::~Tracer() |
{ | { |
|
delete _traceHandler; |
delete _tracerInstance; | delete _tracerInstance; |
} | } |
| |
|
|
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
//Factory function for the trace handler instances. | //Factory function for the trace handler instances. |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
TraceHandler* Tracer::getTraceHandler( Uint32 traceFacility ) |
void Tracer::_setTraceHandler( Uint32 traceFacility ) |
{ | { |
TraceHandler * trcHandler; |
TraceHandler * oldTrcHandler = _traceHandler; |
|
|
switch(traceFacility) | switch(traceFacility) |
{ | { |
case TRACE_FACILITY_LOG: | case TRACE_FACILITY_LOG: |
trcHandler = new TraceLogHandler(); |
_traceFacility = TRACE_FACILITY_LOG; |
|
_traceHandler = new TraceLogHandler(); |
|
break; |
|
|
|
case TRACE_FACILITY_MEMORY: |
|
_traceFacility = TRACE_FACILITY_MEMORY; |
|
_traceHandler = new TraceMemoryHandler(); |
break; | break; |
| |
case TRACE_FACILITY_FILE: | case TRACE_FACILITY_FILE: |
default: | default: |
trcHandler = new TraceFileHandler(); |
_traceFacility = TRACE_FACILITY_FILE; |
|
_traceHandler = new TraceFileHandler(); |
|
} |
|
delete oldTrcHandler; |
|
} |
|
|
|
//////////////////////////////////////////////////////////////////////////////// |
|
// Validates if a given file path if it is eligible for writing traces. |
|
//////////////////////////////////////////////////////////////////////////////// |
|
Boolean Tracer::_isValidTraceFile(String fileName) |
|
{ |
|
// Check if the file path is a directory |
|
FileSystem::translateSlashes(fileName); |
|
if (FileSystem::isDirectory(fileName)) |
|
{ |
|
return false; |
} | } |
| |
return trcHandler; |
// Check if the file exists and is writable |
|
if (FileSystem::exists(fileName)) |
|
{ |
|
return FileSystem::canWrite(fileName); |
|
} |
|
|
|
// Check if directory is writable |
|
Uint32 index = fileName.reverseFind('/'); |
|
|
|
if (index != PEG_NOT_FOUND) |
|
{ |
|
String dirName = fileName.subString(0,index); |
|
|
|
if (dirName.size() == 0) |
|
{ |
|
dirName = "/"; |
|
} |
|
|
|
if (!FileSystem::isDirectory(dirName)) |
|
{ |
|
return false; |
|
} |
|
|
|
return FileSystem::canWrite(dirName); |
|
} |
|
|
|
String currentDir; |
|
|
|
// Check if there is permission to write in the |
|
// current working directory |
|
FileSystem::getCurrentDirectory(currentDir); |
|
|
|
return FileSystem::canWrite(currentDir); |
} | } |
| |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
|
|
void Tracer::_trace( | void Tracer::_trace( |
const char* fileName, | const char* fileName, |
const Uint32 lineNum, | const Uint32 lineNum, |
const Uint32 traceComponent, |
const TraceComponentId traceComponent, |
const char* fmt, | const char* fmt, |
va_list argList) | va_list argList) |
{ | { |
|
|
//Traces the message in the given CIMException object. | //Traces the message in the given CIMException object. |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
void Tracer::_traceCIMException( | void Tracer::_traceCIMException( |
const Uint32 traceComponent, |
const TraceComponentId traceComponent, |
const CIMException& cimException) | const CIMException& cimException) |
{ | { |
// get the CIMException trace message string | // get the CIMException trace message string |
|
|
void Tracer::_traceMethod( | void Tracer::_traceMethod( |
const char* fileName, | const char* fileName, |
const Uint32 lineNum, | const Uint32 lineNum, |
const Uint32 traceComponent, |
const TraceComponentId traceComponent, |
const char* methodEntryExit, | const char* methodEntryExit, |
const char* method) | const char* method) |
{ | { |
|
|
delete [] message; | delete [] message; |
} | } |
| |
|
|
//////////////////////////////////////////////////////////////////////////////// |
|
//Checks if trace is enabled for the given component and level |
|
//////////////////////////////////////////////////////////////////////////////// |
|
Boolean Tracer::isTraceEnabled( |
|
const Uint32 traceComponent, |
|
const Uint32 traceLevel) |
|
{ |
|
Tracer* instance = _getInstance(); |
|
if (traceComponent >= _NUM_COMPONENTS) |
|
{ |
|
return false; |
|
} |
|
return (((instance->_traceComponentMask.get())[traceComponent]) && |
|
(traceLevel & instance->_traceLevelMask)); |
|
} |
|
|
|
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
//Called by all trace interfaces with variable arguments | //Called by all trace interfaces with variable arguments |
//to log message to trace file | //to log message to trace file |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
void Tracer::_trace( | void Tracer::_trace( |
const Uint32 traceComponent, |
const TraceComponentId traceComponent, |
const char* message, | const char* message, |
const char* fmt, | const char* fmt, |
va_list argList) | va_list argList) |
{ | { |
char* msgHeader; | char* msgHeader; |
|
Uint32 msgLen; |
|
Uint32 usec,sec; |
| |
// Get the current system time and prepend to message | // Get the current system time and prepend to message |
String currentTime = System::getCurrentASCIITime(); |
System::getCurrentTimeUsec(sec,usec); |
CString timeStamp = currentTime.getCString(); |
|
| |
// | // |
// Allocate messageHeader. | // Allocate messageHeader. |
|
|
// Construct the message header | // Construct the message header |
// The message header is in the following format | // The message header is in the following format |
// timestamp: <component name> [file name:line number] | // timestamp: <component name> [file name:line number] |
|
// |
|
// Format string length calculation: |
|
// 11(sec)+ 2('s-')+11(usec)+4('us: ')+1(' ')+1(\0) = 30 |
if (*message != '\0') | if (*message != '\0') |
{ | { |
// << Wed Jul 16 10:58:40 2003 mdd >> _STRLEN_MAX_PID_TID is not used |
|
// in this format string |
|
msgHeader = new char [strlen(message) + | msgHeader = new char [strlen(message) + |
strlen(TRACE_COMPONENT_LIST[traceComponent]) + |
strlen(TRACE_COMPONENT_LIST[traceComponent]) + 30]; |
strlen(timeStamp) + _STRLEN_MAX_PID_TID + 5]; |
|
| |
sprintf(msgHeader, "%s: %s %s", (const char*)timeStamp, |
msgLen = sprintf(msgHeader, "%us-%uus: %s %s", sec, usec, |
TRACE_COMPONENT_LIST[traceComponent], message); | TRACE_COMPONENT_LIST[traceComponent], message); |
} | } |
else | else |
{ | { |
// | // |
// Since the message is blank, form a string using the pid and tid |
|
// |
|
char* tmpBuffer; |
|
|
|
// |
|
// Allocate messageHeader. | // Allocate messageHeader. |
// Needs to be updated if additional info is added | // Needs to be updated if additional info is added |
// | // |
tmpBuffer = new char[2 * _STRLEN_MAX_PID_TID + 6]; |
// Format string length calculation: |
sprintf(tmpBuffer, "[%u:%s]: ", |
// 11(sec)+2('s-')+11(usec)+4('us: ')+ |
System::getPID(), Threads::id().buffer); |
// +2(' [')+1(':')+3(']: ')+1(\0) = 35 |
msgHeader = new char[strlen(timeStamp) + |
msgHeader = new char[2 * _STRLEN_MAX_PID_TID + |
strlen(TRACE_COMPONENT_LIST[traceComponent]) + |
strlen(TRACE_COMPONENT_LIST[traceComponent]) + 35]; |
strlen(tmpBuffer) + 1 + 5]; |
|
| |
sprintf(msgHeader, "%s: %s %s ", (const char*)timeStamp, |
msgLen = sprintf(msgHeader, "%us-%uus: %s [%u:%s]: ", sec, usec, |
TRACE_COMPONENT_LIST[traceComponent], tmpBuffer); |
TRACE_COMPONENT_LIST[traceComponent], |
delete [] tmpBuffer; |
System::getPID(), Threads::id().buffer); |
} | } |
| |
// Call trace file handler to write message | // Call trace file handler to write message |
_getInstance()->_traceHandler->handleMessage(msgHeader,fmt,argList); |
_getInstance()->_traceHandler->handleMessage(msgHeader,msgLen,fmt,argList); |
| |
delete [] msgHeader; | delete [] msgHeader; |
} | } |
|
|
//to log message to trace file | //to log message to trace file |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
void Tracer::_traceCString( | void Tracer::_traceCString( |
const Uint32 traceComponent, |
const TraceComponentId traceComponent, |
const char* message, | const char* message, |
const char* cstring) | const char* cstring) |
{ | { |
char* completeMessage; | char* completeMessage; |
|
Uint32 msgLen; |
|
Uint32 usec,sec; |
| |
// Get the current system time and prepend to message | // Get the current system time and prepend to message |
String currentTime = System::getCurrentASCIITime(); |
System::getCurrentTimeUsec(sec,usec); |
CString timeStamp = currentTime.getCString(); |
|
// | // |
// Allocate completeMessage. | // Allocate completeMessage. |
// Needs to be updated if additional info is added | // Needs to be updated if additional info is added |
|
|
// Construct the message header | // Construct the message header |
// The message header is in the following format | // The message header is in the following format |
// timestamp: <component name> [file name:line number] | // timestamp: <component name> [file name:line number] |
|
// |
|
// Format string length calculation: |
|
// 11(sec)+ 2('s-')+11(usec)+4('us: ')+1(' ')+1(\0) = 30 |
if (*message != '\0') | if (*message != '\0') |
{ | { |
// << Wed Jul 16 10:58:40 2003 mdd >> _STRLEN_MAX_PID_TID is not used |
|
// in this format string |
|
completeMessage = new char [strlen(message) + | completeMessage = new char [strlen(message) + |
strlen(TRACE_COMPONENT_LIST[traceComponent]) + | strlen(TRACE_COMPONENT_LIST[traceComponent]) + |
strlen(timeStamp) + _STRLEN_MAX_PID_TID + 5 + |
strlen(cstring) + 30]; |
strlen(cstring) ]; |
|
| |
sprintf(completeMessage, "%s: %s %s%s", (const char*)timeStamp, |
msgLen = sprintf(completeMessage, "%us-%uus: %s %s%s", sec, usec, |
TRACE_COMPONENT_LIST[traceComponent], message, cstring); | TRACE_COMPONENT_LIST[traceComponent], message, cstring); |
} | } |
else | else |
|
|
// Allocate messageHeader. | // Allocate messageHeader. |
// Needs to be updated if additional info is added | // Needs to be updated if additional info is added |
// | // |
tmpBuffer = new char[2 * _STRLEN_MAX_PID_TID + 6]; |
// Format string length calculation: |
sprintf(tmpBuffer, "[%u:%s]: ", |
// 11(sec)+2('s-')+11(usec)+4('us: ')+ |
System::getPID(), Threads::id().buffer); |
// +2(' [')+1(':')+3(']: ')+1(\0) = 35 |
|
completeMessage = new char[2 * _STRLEN_MAX_PID_TID + |
completeMessage = new char[strlen(timeStamp) + |
|
strlen(TRACE_COMPONENT_LIST[traceComponent]) + | strlen(TRACE_COMPONENT_LIST[traceComponent]) + |
strlen(tmpBuffer) + 1 + 5 + |
strlen(cstring) +35]; |
strlen(cstring)]; |
|
| |
sprintf(completeMessage, "%s: %s %s %s", (const char*)timeStamp, |
msgLen = sprintf(completeMessage, "%us-%uus: %s [%u:%s] %s", sec, usec, |
TRACE_COMPONENT_LIST[traceComponent], tmpBuffer, cstring); |
TRACE_COMPONENT_LIST[traceComponent], |
delete [] tmpBuffer; |
System::getPID(), Threads::id().buffer, |
|
cstring); |
} | } |
| |
// Call trace file handler to write message | // Call trace file handler to write message |
_getInstance()->_traceHandler->handleMessage(completeMessage); |
_getInstance()->_traceHandler->handleMessage(completeMessage,msgLen); |
| |
delete [] completeMessage; | delete [] completeMessage; |
} | } |
|
|
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
Boolean Tracer::isValidFileName(const char* filePath) | Boolean Tracer::isValidFileName(const char* filePath) |
{ | { |
String moduleName = _getInstance()->_moduleName; |
Tracer* instance = _getInstance(); |
if (moduleName == String::EMPTY) |
String testTraceFile(filePath); |
{ |
|
return |
if (instance->_runningOOP) |
_getInstance()->_traceHandler->isValidMessageDestination(filePath); |
|
} |
|
else |
|
{ | { |
String extendedFilePath = String(filePath) + "." + moduleName; |
testTraceFile.append("."); |
return _getInstance()->_traceHandler->isValidMessageDestination( |
testTraceFile.append(instance->_oopTraceFileExtension); |
extendedFilePath.getCString()); |
|
} | } |
|
|
|
return _isValidTraceFile(testTraceFile); |
} | } |
| |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
|
|
} | } |
| |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
//Set the name of the module being traced |
// Notify the trare running out of process and provide the trace file extension |
|
// for the out of process trace file. |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
void Tracer::setModuleName(const String& moduleName) |
void Tracer::setOOPTraceFileExtension(const String& oopTraceFileExtension) |
{ | { |
_getInstance()->_moduleName = moduleName; |
Tracer* instance = _getInstance(); |
|
instance->_oopTraceFileExtension = oopTraceFileExtension; |
|
instance->_runningOOP=true; |
|
instance->_traceMemoryBufferSize /= PEGASUS_TRC_BUFFER_OOP_SIZE_DEVISOR; |
|
|
} | } |
| |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
|
|
return 1; | return 1; |
} | } |
| |
String moduleName = _getInstance()->_moduleName; |
Tracer* instance = _getInstance(); |
if (moduleName == String::EMPTY) |
String newTraceFile(traceFile); |
|
|
|
if (instance->_runningOOP) |
|
{ |
|
newTraceFile.append("."); |
|
newTraceFile.append(instance->_oopTraceFileExtension); |
|
} |
|
|
|
if (_isValidTraceFile(newTraceFile)) |
{ | { |
return _getInstance()->_traceHandler->setMessageDestination(traceFile); |
instance->_traceFile = newTraceFile; |
|
instance->_traceHandler->configurationUpdated(); |
} | } |
else | else |
{ | { |
String extendedTraceFile = String(traceFile) + "." + moduleName; |
return 1; |
return _getInstance()->_traceHandler->setMessageDestination( |
|
extendedTraceFile.getCString()); |
|
} | } |
|
|
|
|
|
return 0; |
|
|
} | } |
| |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
|
|
switch (traceLevel) | switch (traceLevel) |
{ | { |
case LEVEL0: | case LEVEL0: |
_getInstance()->_traceLevelMask = 0x00; |
_traceLevelMask = 0x00; |
break; | break; |
| |
case LEVEL1: | case LEVEL1: |
_getInstance()->_traceLevelMask = 0x01; |
_traceLevelMask = 0x01; |
break; | break; |
| |
case LEVEL2: | case LEVEL2: |
_getInstance()->_traceLevelMask = 0x03; |
_traceLevelMask = 0x03; |
break; | break; |
| |
case LEVEL3: | case LEVEL3: |
_getInstance()->_traceLevelMask = 0x07; |
_traceLevelMask = 0x07; |
break; | break; |
| |
case LEVEL4: | case LEVEL4: |
_getInstance()->_traceLevelMask = 0x0F; |
_traceLevelMask = 0x0F; |
break; | break; |
| |
case LEVEL5: | case LEVEL5: |
_getInstance()->_traceLevelMask = 0x1F; |
_traceLevelMask = 0x1F; |
break; | break; |
| |
default: | default: |
_getInstance()->_traceLevelMask = 0x00; |
_traceLevelMask = 0x00; |
retCode = 1; | retCode = 1; |
} | } |
| |
if (_getInstance()->_componentsAreSet && |
// If one of the components was set for tracing and the traceLevel |
_getInstance()->_traceLevelMask ) |
// is not zero, then turn on tracing. |
{ |
_traceOn=((_traceComponentMask!=(Uint64)0)&&(_traceLevelMask!=LEVEL0)); |
_traceOn = true; |
|
} |
|
else |
|
{ |
|
_traceOn = false; |
|
} |
|
| |
return retCode; | return retCode; |
} | } |
|
|
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
void Tracer::setTraceComponents(const String& traceComponents) | void Tracer::setTraceComponents(const String& traceComponents) |
{ | { |
Tracer* instance = _getInstance(); |
|
|
|
// Check if ALL is specified | // Check if ALL is specified |
if (String::equalNoCase(traceComponents,"ALL")) | if (String::equalNoCase(traceComponents,"ALL")) |
{ | { |
for (Uint32 index = 0; index < _NUM_COMPONENTS; index++) |
// initialize ComponentMask bit array to true |
{ |
_traceComponentMask = (Uint64)-1; |
(instance->_traceComponentMask.get())[index] = true; |
|
} |
|
|
|
instance->_componentsAreSet=true; |
|
| |
// If tracing isn't turned off by a traceLevel of zero, let's | // If tracing isn't turned off by a traceLevel of zero, let's |
// turn on the flag that activates tracing. | // turn on the flag that activates tracing. |
_traceOn = (instance->_traceLevelMask != LEVEL0); |
_traceOn = (_traceLevelMask != LEVEL0); |
| |
return; | return; |
} | } |
| |
// initialize ComponentMask array to False |
// initialize ComponentMask bit array to false |
for (Uint32 index = 0; index < _NUM_COMPONENTS; index++) |
_traceComponentMask = (Uint64)0; |
{ |
|
(instance->_traceComponentMask.get())[index] = false; |
|
} |
|
_traceOn = false; | _traceOn = false; |
instance->_componentsAreSet=false; |
|
| |
if (traceComponents != String::EMPTY) | if (traceComponents != String::EMPTY) |
{ | { |
|
|
if (String::equalNoCase( | if (String::equalNoCase( |
componentName,TRACE_COMPONENT_LIST[index])) | componentName,TRACE_COMPONENT_LIST[index])) |
{ | { |
(instance->_traceComponentMask.get())[index] = true; |
_traceComponentMask=_traceComponentMask|((Uint64)1<<index); |
|
|
instance->_componentsAreSet=true; |
|
|
|
// Found component, break from the loop | // Found component, break from the loop |
break; | break; |
} | } |
|
|
index++; | index++; |
} | } |
} | } |
|
|
// Remove the searched componentname from the traceComponents | // Remove the searched componentname from the traceComponents |
componentStr.remove(0,position+1); | componentStr.remove(0,position+1); |
} | } |
|
|
// If one of the components was set for tracing and the traceLevel | // If one of the components was set for tracing and the traceLevel |
// is not zero, then turn on tracing. | // is not zero, then turn on tracing. |
_traceOn = (instance->_componentsAreSet && |
_traceOn=((_traceComponentMask!=(Uint64)0)&&(_traceLevelMask!=LEVEL0)); |
(instance->_traceLevelMask != LEVEL0)); |
|
} | } |
| |
return ; | return ; |
|
|
{ | { |
if (index != instance->_traceFacility) | if (index != instance->_traceFacility) |
{ | { |
instance->_traceFacility = index; |
instance->_setTraceHandler(index); |
instance->_traceHandler.reset( |
|
instance->getTraceHandler(instance->_traceFacility)); |
|
} | } |
retCode = 1; | retCode = 1; |
break; | break; |
|
|
return _getInstance()->_traceFacility; | return _getInstance()->_traceFacility; |
} | } |
| |
|
//////////////////////////////////////////////////////////////////////////////// |
|
// Set the size of the memory trace buffer |
|
//////////////////////////////////////////////////////////////////////////////// |
|
Boolean Tracer::setTraceMemoryBufferSize(Uint32 bufferSize) |
|
{ |
|
Tracer* instance = _getInstance(); |
|
if (instance->_runningOOP) |
|
{ |
|
// in OOP we reduce the trace memory buffer by factor |
|
// PEGASUS_TRC_BUFFER_OOP_SIZE_DEVISOR |
|
instance->_traceMemoryBufferSize = |
|
bufferSize / PEGASUS_TRC_BUFFER_OOP_SIZE_DEVISOR; |
|
} |
|
else |
|
{ |
|
instance->_traceMemoryBufferSize = bufferSize; |
|
} |
|
|
|
// If we decide to dynamically change the trace buffer size, |
|
// this is where it needs to be implemented. |
|
return true; |
|
} |
|
|
|
//////////////////////////////////////////////////////////////////////////////// |
|
// Flushes the trace buffer to traceFilePath. This method will only |
|
// have an effect when traceFacility=Memory. |
|
//////////////////////////////////////////////////////////////////////////////// |
|
void Tracer::flushTrace() |
|
{ |
|
_getInstance()->_traceHandler->flushTrace(); |
|
return; |
|
} |
|
|
|
|
void Tracer::traceEnter( | void Tracer::traceEnter( |
TracerToken& token, | TracerToken& token, |
const char* file, | const char* file, |
size_t line, | size_t line, |
Uint32 traceComponent, |
TraceComponentId traceComponent, |
const char* method) | const char* method) |
{ | { |
token.component = traceComponent; | token.component = traceComponent; |
|
|
void Tracer::traceCString( | void Tracer::traceCString( |
const char* fileName, | const char* fileName, |
const Uint32 lineNum, | const Uint32 lineNum, |
const Uint32 traceComponent, |
const TraceComponentId traceComponent, |
const char* cstring) | const char* cstring) |
{ | { |
char* message; | char* message; |
| |
|
Uint32 msgLen; |
|
Uint32 usec,sec; |
|
|
|
// Get the current system time |
|
System::getCurrentTimeUsec(sec,usec); |
|
|
// | // |
// Allocate memory for the message string | // Allocate memory for the message string |
// Needs to be updated if additional info is added | // Needs to be updated if additional info is added |
// | // |
message = new char[strlen(fileName) + | message = new char[strlen(fileName) + |
_STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8]; |
_STRLEN_MAX_UNSIGNED_INT + (_STRLEN_MAX_PID_TID * 2) + 8 + |
sprintf( |
strlen(TRACE_COMPONENT_LIST[traceComponent]) + |
message, |
strlen(cstring) + 30]; |
"[%u:%s:%s:%u]: ", |
|
|
msgLen = sprintf(message, "%us-%uus: %s [%u:%s:%s:%u]: %s", |
|
sec, |
|
usec, |
|
TRACE_COMPONENT_LIST[traceComponent], |
System::getPID(), | System::getPID(), |
Threads::id().buffer, | Threads::id().buffer, |
fileName, | fileName, |
lineNum); |
lineNum, |
|
cstring); |
|
|
|
// Call trace file handler to write message |
|
_getInstance()->_traceHandler->handleMessage(message,msgLen); |
| |
_traceCString(traceComponent, message, cstring); |
|
delete [] message; | delete [] message; |
} | } |
| |
void Tracer::traceCIMException( | void Tracer::traceCIMException( |
const Uint32 traceComponent, |
const TraceComponentId traceComponent, |
const Uint32 traceLevel, | const Uint32 traceLevel, |
const CIMException& cimException) | const CIMException& cimException) |
{ | { |