windows-trace-log-to-dbgview-20050820
authorJeffrey Altman <jaltman@secure-endpoints.com>
Fri, 26 Aug 2005 14:39:31 +0000 (14:39 +0000)
committerJeffrey Altman <jaltman@secure-endpoints.com>
Fri, 26 Aug 2005 14:39:31 +0000 (14:39 +0000)
Added a new option for viewing the trace log data in real time

====================
This delta was composed from multiple commits as part of the CVS->Git migration.
The checkin message with each commit was inconsistent.
The following are the additional commit messages.
====================

Include the Thread ID in the output to make it usable for debugging
deadlocks.

====================

alter the afsd_init.log tag for the TraceOption to not be
Windows Event Log specific.

doc/txt/winnotes/registry.txt
src/WINNT/afsd/afsd_init.c
src/WINNT/client_osi/osilog.c
src/WINNT/client_osi/osilog.h

index 436bd0b..0dd7ca7 100644 (file)
@@ -284,13 +284,15 @@ Variable: HardDeadtimeout
 
 
 Value  : TraceOption
-Type   : DWORD {0, 1, 2, 3}
+Type   : DWORD {0-7}
 Default : 0
 
   Enables logging of debug output to the Windows Event Log.
   Bit 0 enables logging of "Logon Events" processed by the Network Provider
   and Winlogon Event Notification Handler.  
   Bit 1 enables logging of events captured by the AFS Client Service.
+  Bit 2 enables real-time viewing of "fs trace" logging with DbgView 
+  or similar tools.
 
 Value   : AllSubmount
 Type    : DWORD {0, 1}
index 03dacb7..151c289 100644 (file)
@@ -638,7 +638,7 @@ int afsd_InitCM(char **reasonP)
     dummyLen = sizeof(TraceOption);
     code = RegQueryValueEx(parmKey, "TraceOption", NULL, NULL,
                             (BYTE *) &TraceOption, &dummyLen);
-    afsi_log("Event Log Tracing = %lX", TraceOption);
+    afsi_log("Trace Options = %lX", TraceOption);
 
     dummyLen = sizeof(traceBufSize);
     code = RegQueryValueEx(parmKey, "TraceBufferSize", NULL, NULL,
index 85672db..43561aa 100644 (file)
@@ -37,6 +37,14 @@ osi_log_t *osi_allLogsp;     /* all logs known; for use during panic */
 unsigned long osi_logFreq;     /* 0, or frequency of high perf counter */
 unsigned long osi_logTixToMicros;      /* mult. correction factor */
 
+#define TRACE_OPTION_EVENT 2
+#define TRACE_OPTION_DEBUGLOG 4
+
+#define ISCLIENTTRACE(v) ( ((v) & TRACE_OPTION_EVENT)==TRACE_OPTION_EVENT)
+#define ISCLIENTDEBUGLOG(v) (((v) & TRACE_OPTION_DEBUGLOG)==TRACE_OPTION_DEBUGLOG)
+
+DWORD osi_TraceOption=0;
+
 osi_fdOps_t osi_logFDOps = {
        osi_LogFDCreate,
 #ifndef DJGPP
@@ -94,9 +102,9 @@ osi_log_t *osi_LogCreate(char *namep, long size)
         logp->datap = malloc(size * sizeof(osi_logEntry_t));
 
        /* init strings array */
-       logp->maxstringindex = size/5;
+       logp->maxstringindex = size/3;
        logp->stringindex = 0;
-       logp->stringsp = malloc((size/5) * OSI_LOG_STRINGSIZE);
+       logp->stringsp = malloc(logp->maxstringindex * OSI_LOG_STRINGSIZE);
  
         /* and sync */
         thrd_InitCrit(&logp->cs);
@@ -208,17 +216,28 @@ void osi_LogAdd(osi_log_t *logp, char *formatp, long p0, long p1, long p2, long
         lep->parms[3] = p3;
 
 #ifdef NOTSERVICE
-               printf( "%9ld:", lep->micros );
-               printf( formatp, p0, p1, p2, p3);
-               printf( "\n" );
+        printf( "%9ld:", lep->micros );
+        printf( formatp, p0, p1, p2, p3);
+        printf( "\n" );
 #endif
 
+        if(ISCLIENTDEBUGLOG(osi_TraceOption)) {
+           char wholemsg[1024], msg[1000];
+
+           snprintf(msg, sizeof(msg), formatp,
+                    p0, p1, p2, p3);
+           snprintf(wholemsg, sizeof(wholemsg), 
+                    "tid[%d] %s\n",
+                    lep->tid, msg);
+            OutputDebugStringA(wholemsg);
+        }
+
        thrd_LeaveCrit(&logp->cs);
 }
 
 void osi_LogPrint(osi_log_t *logp, FILE_HANDLE handle)
 {
-       char wholemsg[1000], msg[1000];
+       char wholemsg[1024], msg[1000];
        int i, ix, ioCount;
        osi_logEntry_t *lep;
 
@@ -230,10 +249,11 @@ void osi_LogPrint(osi_log_t *logp, FILE_HANDLE handle)
             i < logp->nused;
             i++, ix++, (ix >= logp->alloc ? ix -= logp->alloc : 0)) {
                lep = logp->datap + ix;         /* pointer arithmetic */
-               sprintf(msg, lep->formatp,
+               snprintf(msg, sizeof(msg), lep->formatp,
                        lep->parms[0], lep->parms[1],
                        lep->parms[2], lep->parms[3]);
-               sprintf(wholemsg, "time %d.%06d, pid %d %s\n",
+               snprintf(wholemsg, sizeof(wholemsg),
+                        "time %d.%06d, tid %d %s\n",
                        lep->micros / 1000000,
                        lep->micros % 1000000,
                        lep->tid, msg);
@@ -251,19 +271,26 @@ void osi_LogPrint(osi_log_t *logp, FILE_HANDLE handle)
 
 char *osi_LogSaveString(osi_log_t *logp, char *s)
 {
-       char *saveplace = logp->stringsp[logp->stringindex];
+       char *saveplace;
 
        if (s == NULL) return NULL;
 
+        thrd_EnterCrit(&logp->cs);
+
+        saveplace = logp->stringsp[logp->stringindex];
+
        if (strlen(s) >= OSI_LOG_STRINGSIZE)
                sprintf(saveplace, "...%s",
                        s + strlen(s) - (OSI_LOG_STRINGSIZE - 4));
        else
                strcpy(saveplace, s);
        logp->stringindex++;
+
        if (logp->stringindex >= logp->maxstringindex)
            logp->stringindex = 0;
 
+        thrd_LeaveCrit(&logp->cs);
+
        return saveplace;
 }
 
@@ -342,11 +369,6 @@ void osi_LogDisable(osi_log_t *logp)
                logp->enabled = 0;
 }
 
-#define TRACE_OPTION_EVENT 2
-#define ISCLIENTTRACE(v) ( ((v) & TRACE_OPTION_EVENT)==TRACE_OPTION_EVENT)
-
-DWORD osi_TraceOption=0;
-
 void osi_InitTraceOption()
 {
        DWORD LSPtype, LSPsize;
index 6eefb0f..e2284d6 100644 (file)
@@ -91,6 +91,7 @@ extern char *osi_HexifyString(char *s);
 #define osi_Log2(l,f,a,b)      osi_LogAdd((l), (f), (long) (a), (long) (b), 0, 0)
 #define osi_Log3(l,f,a,b,c)    osi_LogAdd((l), (f), (long) (a), (long) (b), (long) (c), 0)
 #define osi_Log4(l,f,a,b,c,d)  osi_LogAdd((l), (f), (long) (a), (long) (b), (long) (c), (long) (d))
+#define osi_Log5(l,f,a,b,c,d,e)        osi_LogAdd((l), (f), (long) (a), (long) (b), (long) (c), (long) (d), (long) (e))
 
 #ifdef DEBUG_VERBOSE
 #define DEBUG_EVENT1(a,b,c) {HANDLE h; char *ptbuf[1],buf[132];\