axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From whitl...@apache.org
Subject cvs commit: ws-axis/c/src/common AxisTrace.cpp AxisTrace.h
Date Wed, 20 Oct 2004 16:27:05 GMT
whitlock    2004/10/20 09:27:05

  Modified:    c/src/common AxisTrace.cpp AxisTrace.h
  Log:
  Add better trace entry/exit methods
  
  Revision  Changes    Path
  1.33      +153 -0    ws-axis/c/src/common/AxisTrace.cpp
  
  Index: AxisTrace.cpp
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/common/AxisTrace.cpp,v
  retrieving revision 1.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- AxisTrace.cpp	14 Oct 2004 15:46:05 -0000	1.32
  +++ AxisTrace.cpp	20 Oct 2004 16:27:04 -0000	1.33
  @@ -22,9 +22,11 @@
   #include "AxisTrace.h"
   #include <time.h>
   #include <stdio.h>
  +#include <stdarg.h>
   #include "AxisUtils.h"
   #include <axis/server/GDefine.h>
   #include "AxisConfig.h"
  +#include <string>
   
   
   extern AXIS_CPP_NAMESPACE_PREFIX AxisConfig* g_pConfig;
  @@ -249,6 +251,157 @@
       m_fileTrace.filePuts(data);
       m_fileTrace.filePuts("\n");
       return;
  +}
  +
  +void AxisTrace::traceEntry(const char *className, const char *methodName, void *that, int
nParms, ...)
  +{
  +    if (!isTraceOn()) return;
  +
  +	try 
  +	{
  +		string line = "{ ";
  +		if (NULL!=className) {
  +			line += className;
  +			if (NULL!=that) {
  +				line += "(";
  +				char prim[32];
  +				sprintf(prim,"%p",that);
  +				line += prim;
  +				line += ")";
  +			}
  +			line += "::";
  +		}
  +
  +		if (NULL!=methodName)
  +			line += methodName;
  +		line += "(";
  +
  +		va_list args;
  +		va_start(args, nParms);
  +		for (int i=0; i<nParms; i++) 
  +		{
  +			AxisTraceType type = va_arg(args, AxisTraceType);
  +			unsigned len = va_arg(args, unsigned);
  +			void *value = va_arg(args, void*);
  +			if (0!=i) line += ", ";
  +			addParameter(line,type,len,value);
  +		}
  +
  +		line += ")";
  +		traceLine(line.c_str());
  +    } catch (...) {
  +        traceLine("Unknown exception caught during trace entry");
  +    }
  +}
  +
  +void AxisTrace::traceExit(const char *className, const char *methodName, 
  +						  AxisTraceType type, unsigned len, void *value)
  +{
  +    if (!isTraceOn()) return;
  +
  +	try 
  +	{
  +		string line = "} ";
  +		if (NULL!=className) {
  +			line += className;
  +			line += "::";
  +		}
  +		if (NULL!=methodName) 
  +			line += methodName;
  +		line += "(";
  +		if (TRACETYPE_UNKNOWN != type)
  +			addParameter(line,type,len,value);
  +		line += ")";
  +		traceLine(line.c_str());
  +    } catch (...) {
  +        traceLine("Unknown exception caught during trace exit");
  +    }
  +}
  +
  +void AxisTrace::traceCatch(const char *className, const char *methodName, 
  +						   AxisTraceType type, unsigned len, void *value)
  +{
  +    if (!isTraceOn()) return;
  +
  +	try 
  +	{
  +		string line;
  +		if (NULL!=className) {
  +			line += className;
  +			line += "::";
  +		}
  +		if (NULL!=methodName) 
  +			line += methodName;
  +		line += " caught ";
  +		if (TRACETYPE_UNKNOWN != type)
  +			addParameter(line,type,len,value);
  +		traceLine(line.c_str());
  +    } catch (...) {
  +        traceLine("Unknown exception caught during trace catch");
  +    }
  +}
  +
  +void AxisTrace::addParameter(string& line, AxisTraceType type, unsigned len, void *value)
  +{
  +	char prim[32]; // Plenty big enough to hold a primitive
  +	switch (type) 
  +	{
  +	case TRACETYPE_CHAR:	sprintf(prim,"%c" ,*((char  *)value));	line += prim;	break;
  +	case TRACETYPE_USHORT:	sprintf(prim,"%hu",*((short *)value));	line += prim;	break;
  +	case TRACETYPE_SHORT:	sprintf(prim,"%hd",*((short *)value));	line += prim;	break;
  +	case TRACETYPE_UINT:	sprintf(prim,"%u" ,*((int   *)value));	line += prim;	break;
  +	case TRACETYPE_INT:		sprintf(prim,"%d" ,*((int   *)value));	line += prim;	break;
  +	case TRACETYPE_ULONG:	sprintf(prim,"%lu",*((long  *)value));	line += prim;	break;
  +	case TRACETYPE_LONG:	sprintf(prim,"%ld",*((long  *)value));	line += prim;	break;
  +	case TRACETYPE_UDOUBLE:	sprintf(prim,"%Lu",*((double*)value));	line += prim;	break;
  +	case TRACETYPE_DOUBLE:	sprintf(prim,"%Ld",*((double*)value));	line += prim;	break;
  +	case TRACETYPE_FLOAT:	sprintf(prim,"%f" ,*((float *)value));	line += prim;	break;
  +
  +	/*
  +	 * This code only prints out the first 32 bytes of storage pointed at by a 
  +	 * pointer. This is to prevent huge blocks of atorage repeatedly being output
  +	 * to the trace file. 32 bytes seems quite a low limit. Maybe this limit 
  +	 * could be increased in the future. Large blocks of storage could be output
  +	 * in a more human-friendly format.
  +	 */
  +	case TRACETYPE_POINTER:	
  +		sprintf(prim,"%p ",value);	
  +		line += prim;	
  +		try {
  +			char *pcValue = (char*)value;
  +			line += "[";
  +			for (int i=0; i<len && i<32; i++) {
  +				int x = (int)(pcValue[i]);
  +				sprintf(prim,"%2.2X",x);
  +				line += prim;
  +			}
  +			line += "] <";
  +			for (int j=0; j<len && j<32; j++) {
  +				sprintf(prim,"%c",pcValue[j]);
  +				line += prim;
  +			}
  +			line += ">";
  +		} catch (...) {
  +			line += "<BADPOINTER>";
  +		}
  +		break;
  +
  +	case TRACETYPE_STRING:	
  +		try {
  +			line += "\"";	
  +			line += (char*)value;	
  +			line += "\"";	
  +		} catch (...) {
  +			line += "<BADPOINTER>";
  +		}
  +		break;
  +
  +	default:
  +		line += "<UNKNOWN TYPE";				
  +		line += type;
  +		line += ">";
  +		break;
  +	}
   }
   
   /*
  
  
  
  1.12      +35 -1     ws-axis/c/src/common/AxisTrace.h
  
  Index: AxisTrace.h
  ===================================================================
  RCS file: /home/cvs/ws-axis/c/src/common/AxisTrace.h,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- AxisTrace.h	14 Oct 2004 12:07:43 -0000	1.11
  +++ AxisTrace.h	20 Oct 2004 16:27:04 -0000	1.12
  @@ -25,6 +25,7 @@
   #define __AXISLOG_H_INCLUDED_
   
   #include "AxisFile.h"
  +#include <string>
   
   #if defined(ENABLE_AXISTRACE)  
     #define AXISTRACE1(X, Y) g_pAT->logaxis(X,Y,__FILE__,__LINE__);
  @@ -57,6 +58,22 @@
   
   AXIS_CPP_NAMESPACE_START
   
  +typedef enum {
  +	TRACETYPE_UNKNOWN=0,
  +	TRACETYPE_CHAR,
  +	TRACETYPE_USHORT,
  +	TRACETYPE_SHORT,
  +	TRACETYPE_UINT,
  +	TRACETYPE_INT,
  +	TRACETYPE_ULONG,
  +	TRACETYPE_LONG,
  +	TRACETYPE_UDOUBLE,
  +	TRACETYPE_DOUBLE,
  +	TRACETYPE_FLOAT,
  +	TRACETYPE_POINTER,
  +	TRACETYPE_STRING
  +} AxisTraceType;
  +
   class AxisTrace
   {
   public:
  @@ -179,6 +196,23 @@
        */  
       void traceLine(const char *data);
   
  +	/**
  +	 * Traces the entry to a method.
  +	 */
  +	void traceEntry(const char *className, const char *methodName, void* that, int nParms,
...);
  +
  +	/**
  +	 * Traces the exit to a method.
  +	 */
  +	void traceExit(const char *className, const char *methodName, 
  +		AxisTraceType type=TRACETYPE_UNKNOWN, unsigned len=0, void *value=0);
  +
  +	/**
  +	 * Traces something that has been caught
  +	 */
  +	void traceCatch(const char *className, const char *methodName, 
  +		AxisTraceType type=TRACETYPE_UNKNOWN, unsigned len=0, void *value=0);
  +
   private:
   	bool m_bLoggingOn;
       char m_acLine[4];
  @@ -187,7 +221,7 @@
   
       int setFilePerm(const char* pcFileName);
       int logthis(const char* pcLog, int level, char* arg2, int arg3);
  -
  +	void addParameter(std::string& line, AxisTraceType type, unsigned len, void *value);
   };
   
   /* static AxisTrace tracer; */
  
  
  

Mime
View raw message