/* $Source: runtime/gasnet/gasnet_trace.h $ * $Date: Tue, 09 Aug 2005 22:38:09 -0700 $ * $Revision: 1.20.1.9 $ * Description: GASNet Tracing Helpers (Internal code, not for client use) * Copyright 2002, Dan Bonachea * Terms of use are as specified in license.txt */ #ifndef _IN_GASNET_H #error This file is not meant to be included directly- clients should include gasnet.h #endif #ifndef _GASNET_TRACE_H #define _GASNET_TRACE_H #include BEGIN_EXTERNC /* ------------------------------------------------------------------------------------ */ /* Statistical collection & tracing See README for user-interface usage information */ #if GASNETI_STATS_OR_TRACE /* emit trace info and increment a stat ctr */ #define GASNETI_TRACE_EVENT(type, name) do { \ _GASNETI_STAT_EVENT (type, name); \ _GASNETI_TRACE_EVENT(type, name); \ } while (0) /* emit trace info and accumulate an integer stat value */ #define GASNETI_TRACE_EVENT_VAL(type, name, val) do { \ gasneti_statctr_t _val = (val); \ _GASNETI_STAT_EVENT_VAL (type, name, _val); \ _GASNETI_TRACE_EVENT_VAL(type, name, _val); \ } while (0) /* emit trace info and accumulate a time stat value */ #define GASNETI_TRACE_EVENT_TIME(type, name, time) do { \ gasneti_stattime_t _time = (time); \ _GASNETI_STAT_EVENT_TIME(type, name, _time); \ _GASNETI_TRACE_EVENT_TIME(type, name, _time); \ } while (0) #else #define GASNETI_TRACE_EVENT(type, name) #define GASNETI_TRACE_EVENT_VAL(type, name, val) #define GASNETI_TRACE_EVENT_TIME(type, name, time) #endif #if GASNET_TRACE /* like GASNETI_TRACE_EVENT_VAL, but allow *_LOCAL values to be suppressed in the tracefile */ #define GASNETI_TRACE_EVENT_VAL_LOCAL(type, name, val) do { \ gasneti_statctr_t _val = (val); \ _GASNETI_STAT_EVENT_VAL (type, name, _val); \ if (GASNETI_TRACE_ENABLED(type) && !gasneti_trace_suppresslocal) \ _GASNETI_TRACE_EVENT_VAL(type, name, _val); \ } while (0) #else #define GASNETI_TRACE_EVENT_VAL_LOCAL GASNETI_TRACE_EVENT_VAL #endif #if GASNET_TRACE /* print a string on the trace Ex: GASNETI_TRACE_MSG(C, "init complete") */ #define GASNETI_TRACE_MSG(type, string) \ GASNETI_TRACE_PRINTF(type, ("%s",(string))) /* print a formatted string on output Ex: GASNETI_TRACE_PRINTF(C, ("%i buffers free", numbufs)) (note the extra parentheses around arg) */ #define GASNETI_TRACE_PRINTF(type, args) do { \ if (GASNETI_TRACE_ENABLED(type)) { \ char *_msg = gasneti_dynsprintf args; \ gasneti_trace_output(#type, _msg, 1); \ } \ } while(0) #else #define GASNETI_TRACE_MSG(type, string) #define GASNETI_TRACE_PRINTF(type, args) #endif #if GASNET_STATS /* print an arbitrary string of statistical output on the trace Ex: GASNETI_STATS_MSG(C, "init complete") */ #define GASNETI_STATS_MSG(type, string) \ GASNETI_STATS_PRINTF(type, ("%s",(string))) /* print a formatted string of statistical output on the trace Ex: GASNETI_STATS_PRINTF(C, ("%i buffers free", numbufs)) (note the extra parentheses around arg) */ #define GASNETI_STATS_PRINTF(type, args) do { \ if (GASNETI_STATS_ENABLED(type)) { \ char *_msg = gasneti_dynsprintf args; \ gasneti_stats_output(#type, _msg, 0); \ } \ } while(0) #else #define GASNETI_STATS_MSG(type, string) #define GASNETI_STATS_PRINTF(type, args) #endif /* allow for final output of conduit-specific statistics */ #ifndef GASNETC_TRACE_FINISH #define GASNETC_TRACE_FINISH() #endif #ifndef GASNETI_STATS_ECHOED_TO_TRACEFILE #define GASNETI_STATS_ECHOED_TO_TRACEFILE 1 #endif #if GASNET_TRACE /* GASNETI_TRACE_SETSOURCELINE(filename, linenum): set the current "high-level" source file and line for the current thread to the given value. This information is used to dump out current line information into the tracefile along with each trace message. Passing a NULL filename implies no change to the current filename GASNETI_TRACE_GETSOURCELINE(pfilename, plinenum): fetch the current "high-level" source file and line for the current thread into *pfilename and *plinenum. no-op when tracing is off. */ #if GASNETI_CLIENT_THREADS extern void gasneti_trace_setsourceline(const char *filename, unsigned int linenum); extern void gasneti_trace_getsourceline(const char **pfilename, unsigned int *plinenum); extern void gasneti_trace_freezesourceline(); extern void gasneti_trace_unfreezesourceline(); #else extern const char *gasneti_srcfilename; extern unsigned int gasneti_srclinenum; extern unsigned int gasneti_srcfreeze; GASNET_INLINE_MODIFIER(gasneti_trace_setsourceline) void gasneti_trace_setsourceline(const char *filename, unsigned int linenum) { if_pt (gasneti_srcfreeze == 0) { if_pt (filename != NULL) gasneti_srcfilename = filename; gasneti_srclinenum = linenum; } } GASNET_INLINE_MODIFIER(gasneti_trace_getsourceline) void gasneti_trace_getsourceline(const char **pfilename, unsigned int *plinenum) { *pfilename = gasneti_srcfilename; *plinenum = gasneti_srclinenum; } GASNET_INLINE_MODIFIER(gasneti_trace_freezesourceline) void gasneti_trace_freezesourceline() { gasneti_srcfreeze++; } GASNET_INLINE_MODIFIER(gasneti_trace_unfreezesourceline) void gasneti_trace_unfreezesourceline() { gasneti_assert(gasneti_srcfreeze > 0); gasneti_srcfreeze--; } #endif #define GASNETI_TRACE_SETSOURCELINE(filename, linenum) \ (GASNETI_TRACE_ENABLED(N) ? gasneti_trace_setsourceline(filename, linenum) : ((void)0)) #define GASNETI_TRACE_GETSOURCELINE(pfilename, plinenum) \ (GASNETI_TRACE_ENABLED(N) ? gasneti_trace_getsourceline(pfilename, plinenum) : ((void)0)) #define GASNETI_TRACE_FREEZESOURCELINE() \ (GASNETI_TRACE_ENABLED(N) ? gasneti_trace_freezesourceline() : ((void)0)) #define GASNETI_TRACE_UNFREEZESOURCELINE() \ (GASNETI_TRACE_ENABLED(N) ? gasneti_trace_unfreezesourceline() : ((void)0)) #else #define GASNETI_TRACE_SETSOURCELINE(filename, linenum) ((void)0) #define GASNETI_TRACE_GETSOURCELINE(pfilename, plinenum) ((void)0) #define GASNETI_TRACE_FREEZESOURCELINE() #define GASNETI_TRACE_UNFREEZESOURCELINE() #endif /* ------------------------------------------------------------------------------------ */ /* misc helpers for specific tracing scenarios */ #ifdef GASNETI_PTR32 #define GASNETI_LADDRFMT "0x%08x" #define GASNETI_LADDRSTR(ptr) ((unsigned int)(uintptr_t)(ptr)) #define GASNETI_RADDRFMT "(%i,0x%08x)" #define GASNETI_RADDRSTR(node,ptr) ((int)(node)),GASNETI_LADDRSTR(ptr) #else #define GASNETI_LADDRFMT "0x%08x %08x" #define GASNETI_LADDRSTR(ptr) GASNETI_HIWORD(ptr), GASNETI_LOWORD(ptr) #define GASNETI_RADDRFMT "(%i,0x%08x %08x)" #define GASNETI_RADDRSTR(node,ptr) ((int)(node)),GASNETI_LADDRSTR(ptr) #endif #define GASNETI_TRACE_EVENT_VAL_NONLOCAL GASNETI_TRACE_EVENT_VAL #define GASNETI_TRACE_GET_NAMED(name,locality,dest,node,src,nbytes) do { \ GASNETI_TRACE_EVENT_VAL_##locality(G,name,(nbytes)); \ GASNETI_TRACE_PRINTF(D,(#name ": "GASNETI_LADDRFMT" <- "GASNETI_RADDRFMT" (%llu bytes)", \ GASNETI_LADDRSTR(dest), GASNETI_RADDRSTR((node),(src)), \ (unsigned long long)(nbytes))); \ } while (0) #define GASNETI_TRACE_PUT_NAMED(name,locality,node,dest,src,nbytes) do { \ GASNETI_TRACE_EVENT_VAL_##locality(P,name,(nbytes)); \ GASNETI_TRACE_PRINTF(D,(#name ": "GASNETI_RADDRFMT" <- "GASNETI_LADDRFMT" (%llu bytes): %s", \ GASNETI_RADDRSTR((node),(dest)), GASNETI_LADDRSTR(src), \ (unsigned long long)(nbytes), gasneti_formatdata((src),(nbytes)))); \ } while (0) #define GASNETI_TRACE_MEMSET_NAMED(name,locality,node,dest,val,nbytes) do { \ GASNETI_TRACE_EVENT_VAL_##locality(P,name,(nbytes)); \ GASNETI_TRACE_PRINTF(D,(#name": "GASNETI_RADDRFMT" val=%02x nbytes=%llu", \ GASNETI_RADDRSTR((node),(dest)), (val), \ (unsigned long long)(nbytes))); \ } while (0) /* tracing for remote gets/puts */ #define GASNETI_TRACE_GET(variety,dest,node,src,nbytes) \ GASNETI_TRACE_GET_NAMED(GET_##variety,NONLOCAL,dest,node,src,nbytes) #define GASNETI_TRACE_PUT(variety,node,dest,src,nbytes) \ GASNETI_TRACE_PUT_NAMED(PUT_##variety,NONLOCAL,node,dest,src,nbytes) #define GASNETI_TRACE_MEMSET(variety,node,dest,val,nbytes) \ GASNETI_TRACE_MEMSET_NAMED(MEMSET_##variety,NONLOCAL,node,dest,val,nbytes) /* tracing for local gets/puts (separation allows suppression of trace output) */ #define GASNETI_TRACE_GET_LOCAL(variety,dest,node,src,nbytes) \ GASNETI_TRACE_GET_NAMED(GET_##variety##_LOCAL,LOCAL,dest,node,src,nbytes) #define GASNETI_TRACE_PUT_LOCAL(variety,node,dest,src,nbytes) \ GASNETI_TRACE_PUT_NAMED(PUT_##variety##_LOCAL,LOCAL,node,dest,src,nbytes) #define GASNETI_TRACE_MEMSET_LOCAL(variety,node,dest,val,nbytes) \ GASNETI_TRACE_MEMSET_NAMED(MEMSET_##variety##_LOCAL,LOCAL,node,dest,val,nbytes) /*------------------------------------------------------------------------------------*/ #define GASNETI_TRACE_TRYSYNC(name,success) \ GASNETI_TRACE_EVENT_VAL(S,name,((success) == GASNET_OK?1:0)) #if GASNETI_STATS_OR_TRACE #define GASNETI_TRACE_WAITSYNC_BEGIN() \ gasneti_stattime_t _waitstart = GASNETI_STATTIME_NOW_IFENABLED(S) #else #define GASNETI_TRACE_WAITSYNC_BEGIN() \ static char _dummy_WAITSYNC = (char)sizeof(_dummy_WAITSYNC) #endif #if GASNET_STATS typedef void (*gasnett_stats_callback_t)(void (*)(const char *, ...)); extern gasnett_stats_callback_t gasnett_stats_callback; #endif #define GASNETI_TRACE_WAITSYNC_END(name) \ GASNETI_TRACE_EVENT_TIME(S,name,GASNETI_STATTIME_NOW_IFENABLED(S) - _waitstart) /*------------------------------------------------------------------------------------*/ /* AM Request/Reply tracing helpers */ #define _GASNETI_TRACE_GATHERARGS(numargs) \ char argstr[256]; \ do { \ int i; \ va_list _argptr; \ *argstr='\0'; \ va_start(_argptr, numargs); /* assumes last arg was numargs */ \ for (i=0;i