Index: engine/cvm_call.c =================================================================== RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvm_call.c,v retrieving revision 1.84 diff -u -r1.84 cvm_call.c --- engine/cvm_call.c 28 Feb 2005 11:25:10 -0000 1.84 +++ engine/cvm_call.c 28 Feb 2005 12:53:43 -0000 @@ -59,6 +59,49 @@ #define FFI_RAW_CALL(cif,fn,rvalue,avalue) #endif + +/* Macros for simple profiling support. + * + * These macros get called whenever a function gets called and when it is left, + * respectivly. They record the time a function needed to execute INCLUDING + * CHILD FUNCTIONS. It's very dump and simple but better than no time profiling + * at all ;-) + */ +#ifdef HAVE_GETTIMEOFDAY +#define DO_PROFILE_START(xyz) \ + if ((callFrame) && ((ILCoderGetFlags (thread->process->coder) & IL_CODER_FLAG_METHOD_PROFILE) != 0)) \ + { \ + gettimeofday (&callFrame->profileTime, 0); \ + } + +#define DO_PROFILE_STOP(xyz) \ + if ((callFrame) && ((ILCoderGetFlags (thread->process->coder) & IL_CODER_FLAG_METHOD_PROFILE) != 0)) \ + { \ + struct timeval endTime; \ + time_t seconds; \ + suseconds_t micros; \ + \ + gettimeofday (&endTime, 0); \ + \ + if (endTime.tv_usec < callFrame->profileTime.tv_usec) \ + { \ + seconds = endTime.tv_sec - callFrame->profileTime.tv_sec - 1; \ + micros = (suseconds_t) ((1000000 + endTime.tv_usec) - callFrame->profileTime.tv_usec); \ + } \ + else \ + { \ + seconds = endTime.tv_sec - callFrame->profileTime.tv_sec; \ + micros = endTime.tv_usec - callFrame->profileTime.tv_usec; \ + } \ + \ + method->time += micros + (seconds * 1000000); \ + } +#else +#define DO_PROFILE_START(xyz) +#define DO_PROFILE_STOP(xyz) +#endif + + /* * Allocate a new call frame. */ @@ -612,6 +655,7 @@ callFrame->frame = frame; callFrame->exceptHeight = thread->exceptHeight; callFrame->permissions = 0; + DO_PROFILE_START(); /* Pass control to the new method */ pc = (unsigned char *)(methodToCall->userData); @@ -645,6 +689,7 @@ callFrame->frame = thread->frame; callFrame->exceptHeight = thread->exceptHeight; callFrame->permissions = 0; + DO_PROFILE_START(); /* Restore the state information and jump to the new method */ RESTORE_STATE_FROM_THREAD(); @@ -702,6 +747,7 @@ callFrame->frame = frame; callFrame->exceptHeight = thread->exceptHeight; callFrame->permissions = 0; + DO_PROFILE_START(); /* Pass control to the new method */ pc = ((unsigned char *)(methodToCall->userData)) - CVM_CTOR_OFFSET; @@ -734,6 +780,7 @@ callFrame->frame = thread->frame; callFrame->exceptHeight = thread->exceptHeight; callFrame->permissions = 0; + DO_PROFILE_START(); /* Restore the state information and jump to the new method */ RESTORE_STATE_FROM_THREAD(); @@ -946,6 +993,7 @@ callFrame->frame = frame; callFrame->exceptHeight = thread->exceptHeight; callFrame->permissions = 0; + DO_PROFILE_START(); /* Pass control to the new method */ pc = (unsigned char *)(methodToCall->userData); @@ -979,6 +1027,7 @@ callFrame->frame = thread->frame; callFrame->exceptHeight = thread->exceptHeight; callFrame->permissions = 0; + DO_PROFILE_START(); /* Restore the state information and jump to the new method */ RESTORE_STATE_FROM_THREAD(); @@ -1066,6 +1115,7 @@ callFrame->frame = frame; callFrame->exceptHeight = thread->exceptHeight; callFrame->permissions = 0; + DO_PROFILE_START(); /* Pass control to the new method */ pc = (unsigned char *)(methodToCall->userData); @@ -1099,6 +1149,7 @@ callFrame->frame = thread->frame; callFrame->exceptHeight = thread->exceptHeight; callFrame->permissions = 0; + DO_PROFILE_START(); /* Restore the state information and jump to the new method */ RESTORE_STATE_FROM_THREAD(); @@ -1179,6 +1230,8 @@ popFrame: CHECK_MANAGED_BARRIER(); + + DO_PROFILE_STOP(); callFrame = &(thread->frameStack[--(thread->numFrames)]); methodToCall = callFrame->method; @@ -1479,6 +1532,7 @@ callFrame->frame = frame; callFrame->exceptHeight = thread->exceptHeight; callFrame->permissions = 0; + DO_PROFILE_START(); /* Pass control to the new method */ pc = (unsigned char *)(methodToCall->userData); @@ -1512,6 +1566,7 @@ callFrame->frame = thread->frame; callFrame->exceptHeight = thread->exceptHeight; callFrame->permissions = 0; + DO_PROFILE_START(); /* Restore the state information and jump to the new method */ RESTORE_STATE_FROM_THREAD(); @@ -1571,6 +1626,7 @@ callFrame->frame = thread->frame; callFrame->exceptHeight = thread->exceptHeight; callFrame->permissions = 0; + DO_PROFILE_START(); /* Restore the state information and jump to the new method */ RESTORE_STATE_FROM_THREAD(); @@ -1638,6 +1694,7 @@ callFrame->frame = thread->frame; callFrame->exceptHeight = thread->exceptHeight; callFrame->permissions = 0; + DO_PROFILE_START(); /* Restore the state information and jump to the new method */ RESTORE_STATE_FROM_THREAD(); Index: engine/cvmc.c =================================================================== RCS file: /cvsroot/dotgnu-pnet/pnet/engine/cvmc.c,v retrieving revision 1.45 diff -u -r1.45 cvmc.c --- engine/cvmc.c 9 Jun 2004 03:39:21 -0000 1.45 +++ engine/cvmc.c 28 Feb 2005 12:53:43 -0000 @@ -308,13 +308,21 @@ /* Print the method information */ haveCounts = 0; temp = list; +#if HAVE_GETTIMEOFDAY + printf (" Count Total Average\n time time\n"); +#endif while((method = *temp++) != 0) { if(!(method->count)) { continue; } - printf("%8lu ", (unsigned long)(method->count)); +#if HAVE_GETTIMEOFDAY + printf("%8lu %8lu %8lu ", (unsigned long)(method->count), + (unsigned long)(method->time), (unsigned long)(method->time) / (unsigned long)(method->count)); +#else + printf("%8lu ", (unsigned long)(method->count)); +#endif ILDumpMethodType(stdout, ILProgramItem_Image(method), ILMethod_Signature(method), 0, ILMethod_Owner(method), ILMethod_Name(method), 0); Index: engine/engine.h =================================================================== RCS file: /cvsroot/dotgnu-pnet/pnet/engine/engine.h,v retrieving revision 1.101 diff -u -r1.101 engine.h --- engine/engine.h 23 Oct 2004 03:24:24 -0000 1.101 +++ engine/engine.h 28 Feb 2005 12:53:43 -0000 @@ -30,6 +30,9 @@ #include "il_utils.h" #include "cvm.h" #include "interrupt.h" +#ifdef HAVE_GETTIMEOFDAY +#include +#endif #ifdef __cplusplus extern "C" { @@ -264,7 +267,9 @@ CVMWord *frame; /* Base of the local variable frame */ CVMWord *exceptHeight; /* Height of the frame for exceptions */ void *permissions; /* Permissions for this stack frame */ - +#ifdef HAVE_GETTIMEOFDAY + struct timeval profileTime; +#endif } ILCallFrame; #define IL_INVALID_PC ((unsigned char *)(ILNativeInt)(-1)) Index: image/program.h =================================================================== RCS file: /cvsroot/dotgnu-pnet/pnet/image/program.h,v retrieving revision 1.21 diff -u -r1.21 program.h --- image/program.h 29 Jul 2004 04:37:27 -0000 1.21 +++ image/program.h 28 Feb 2005 12:53:43 -0000 @@ -352,7 +352,9 @@ void *userData; /* User data for the runtime engine */ ILUInt32 index; /* Data added by the runtime engine */ ILUInt32 count; /* Profile count for the engine */ - +#ifdef HAVE_GETTIMEOFDAY + ILUInt32 time; /* Profile time counter for the engine */ +#endif }; /*