Windows: osi_Debug macros

The osi_Debug macros are like osi_Log macros except when used
the logged values are always printed using OutputDebugString().
This interface is meant only for temporary debugging.  No code
that uses osi_Debug should ever be committed to the upstream
repository.

Change-Id: I139c81aa0c745f4f03c6900a19f65c55c495ad33
Reviewed-on: http://gerrit.openafs.org/5415
Reviewed-by: Jeffrey Altman <jaltman@openafs.org>
Tested-by: Jeffrey Altman <jaltman@openafs.org>
This commit is contained in:
Jeffrey Altman 2011-08-02 18:33:06 -04:00 committed by Jeffrey Altman
parent bf2bf9a1fb
commit b5a4c81fe0
3 changed files with 58 additions and 31 deletions

View File

@ -73,3 +73,4 @@ EXPORTS
lock_ConvertRToW @66
osi_LogSaveStringW @67
osi_SetLockOrderValidation @68
osi_DebugAdd @69

View File

@ -166,63 +166,78 @@ void osi_LogFree(osi_log_t *logp)
}
/* add an element to a log */
void osi_LogAdd(osi_log_t *logp, char *formatp, size_t p0, size_t p1, size_t p2, size_t p3, size_t p4)
static void
osi_IntLogAdd(osi_log_t *logp, int debug, char *formatp, size_t p0, size_t p1, size_t p2, size_t p3, size_t p4)
{
osi_logEntry_t *lep;
long ix;
LARGE_INTEGER bigTime;
/* handle init races */
if (!logp) return;
if (!logp)
return;
/* do this w/o locking for speed; it is obviously harmless if we're off
* by a bit.
*/
if (!logp->enabled) return;
if (logp->enabled) {
thrd_EnterCrit(&logp->cs);
if (logp->nused < logp->alloc) logp->nused++;
else {
logp->first++;
if (logp->first >= logp->alloc) logp->first -= logp->alloc;
}
ix = logp->first + logp->nused - 1;
if (ix >= logp->alloc) ix -= logp->alloc;
thrd_EnterCrit(&logp->cs);
if (logp->nused < logp->alloc)
logp->nused++;
else {
logp->first++;
if (logp->first >= logp->alloc)
logp->first -= logp->alloc;
}
ix = logp->first + logp->nused - 1;
if (ix >= logp->alloc)
ix -= logp->alloc;
lep = logp->datap + ix; /* ptr arith */
lep->tid = thrd_Current();
lep = logp->datap + ix; /* ptr arith */
lep->tid = thrd_Current();
/* get the time, using the high res timer if available */
if (osi_logFreq) {
QueryPerformanceCounter(&bigTime);
lep->micros = (bigTime.LowPart / osi_logFreq) * osi_logTixToMicros;
}
else lep->micros = GetCurrentTime() * 1000;
/* get the time, using the high res timer if available */
if (osi_logFreq) {
QueryPerformanceCounter(&bigTime);
lep->micros = (bigTime.LowPart / osi_logFreq) * osi_logTixToMicros;
}
else lep->micros = GetCurrentTime() * 1000;
lep->formatp = formatp;
lep->parms[0] = p0;
lep->parms[1] = p1;
lep->parms[2] = p2;
lep->parms[3] = p3;
lep->parms[4] = p4;
lep->formatp = formatp;
lep->parms[0] = p0;
lep->parms[1] = p1;
lep->parms[2] = p2;
lep->parms[3] = p3;
lep->parms[4] = p4;
#ifdef NOTSERVICE
printf( "%9ld:", lep->micros );
printf( formatp, p0, p1, p2, p3, p4);
printf( "\n" );
printf( "%9ld:", lep->micros );
printf( formatp, p0, p1, p2, p3, p4);
printf( "\n" );
#endif
thrd_LeaveCrit(&logp->cs);
}
if(ISCLIENTDEBUGLOG(osi_TraceOption)) {
if (debug || (logp->enabled && ISCLIENTDEBUGLOG(osi_TraceOption))) {
char wholemsg[1024], msg[1000];
StringCbPrintfA(msg, sizeof(msg), formatp,
p0, p1, p2, p3, p4);
StringCbPrintfA(wholemsg, sizeof(wholemsg),
"tid[%d] %s\n",
lep->tid, msg);
thrd_Current(), msg);
OutputDebugStringA(wholemsg);
}
}
thrd_LeaveCrit(&logp->cs);
void osi_LogAdd(osi_log_t *logp, char *formatp, size_t p0, size_t p1, size_t p2, size_t p3, size_t p4)
{
osi_IntLogAdd(logp, FALSE, formatp, p0, p1, p2, p3, p4);
}
void osi_DebugAdd(osi_log_t *logp, char *formatp, size_t p0, size_t p1, size_t p2, size_t p3, size_t p4)
{
osi_IntLogAdd(logp, TRUE, formatp, p0, p1, p2, p3, p4);
}
void osi_LogPrint(osi_log_t *logp, FILE_HANDLE handle)

View File

@ -59,6 +59,8 @@ extern void osi_LogFree(osi_log_t *);
extern void osi_LogAdd(osi_log_t *, char *, size_t, size_t, size_t, size_t, size_t);
extern void osi_DebugAdd(osi_log_t *, char *, size_t, size_t, size_t, size_t, size_t);
extern void osi_LogReset(osi_log_t *);
extern long osi_LogFDCreate(osi_fdType_t *, osi_fd_t **);
@ -90,6 +92,15 @@ extern char *osi_HexifyString(char *s);
#define osi_Log4(l,f,a,b,c,d) do { if ((l) && (l)->enabled) osi_LogAdd((l), (f), (size_t) (a), (size_t) (b), (size_t) (c), (size_t) (d), 0); } while(0)
#define osi_Log5(l,f,a,b,c,d,e) do { if ((l) && (l)->enabled) osi_LogAdd((l), (f), (size_t) (a), (size_t) (b), (size_t) (c), (size_t) (d), (size_t) (e)); } while(0)
#define osi_Debug0(l,f) osi_DebugAdd((l), (f), 0, 0, 0, 0, 0)
#define osi_Debug1(l,f,a) osi_DebugAdd((l), (f), (size_t) (a), 0, 0, 0, 0)
#define osi_Debug2(l,f,a,b) osi_DebugAdd((l), (f), (size_t) (a), (size_t) (b), 0, 0, 0)
#define osi_Debug3(l,f,a,b,c) osi_DebugAdd((l), (f), (size_t) (a), (size_t) (b), (size_t) (c), 0, 0)
#define osi_Debug4(l,f,a,b,c,d) osi_DebugAdd((l), (f), (size_t) (a), (size_t) (b), (size_t) (c), (size_t) (d), 0)
#define osi_Debug5(l,f,a,b,c,d,e) osi_DebugAdd((l), (f), (size_t) (a), (size_t) (b), (size_t) (c), (size_t) (d), (size_t) (e))
#ifdef DEBUG_VERBOSE
#define DEBUG_EVENT1(a,b,c) {HANDLE h; char *ptbuf[1],buf[132];\
h = RegisterEventSource(NULL, a);\