Index: trunk/src/odinprof/profiler.cpp
===================================================================
--- trunk/src/odinprof/profiler.cpp	(revision 7421)
+++ trunk/src/odinprof/profiler.cpp	(revision 7423)
@@ -1,3 +1,3 @@
-/* $Id: profiler.cpp,v 1.1 2001-11-22 10:43:59 phaller Exp $ */
+/* $Id: profiler.cpp,v 1.2 2001-11-22 11:34:43 phaller Exp $ */
 /*
  * Project Odin Software License can be found in LICENSE.TXT
@@ -33,4 +33,5 @@
 #include <math.h>
 #include <direct.h>
+#include <process.h>
 
 #include "symfile.h"
@@ -397,4 +398,5 @@
   CHAR   szModule[260];                        /* buffer for the module name */
   ULONG  ulOffset;             /* offset within the object within the module */
+  ULONG  ulSymbolOffset;
   
   rc = DosQueryModFromEIP(&ulModule,
@@ -414,5 +416,6 @@
                                          ulOffset,
                                          szFunction,
-                                         sizeof(szFunction)) )
+                                         sizeof(szFunction),
+                                         &ulSymbolOffset) )
     {
       sprintf(szFunction,
@@ -450,4 +453,8 @@
     return ret;
   
+  USHORT sel = RestoreOS2FS();
+  // DosEnterCritSec();
+  
+  
   // "call _ProfileHook32" has 5 bytes, adjust here
   eip_function -= 5;
@@ -472,6 +479,4 @@
   if (NULL == pPE)
   {
-    USHORT sel = RestoreOS2FS();
-    
     pPE = (PPROFILEENTRY)malloc( sizeof(PROFILEENTRY) );
     
@@ -491,6 +496,4 @@
     // @@@PH need to synchronize access!
     pPB->pHashtable->addElement(eip_function, pPE);
-    
-    SetFS(sel);
   }
   
@@ -500,4 +503,7 @@
   // register call and skip to the next empty slot
   pPB->ulCalldepth++;
+  
+  // DosExitCritSec();
+  SetFS(sel);
   
   // get "compensated" timestamp
@@ -522,4 +528,7 @@
     return NULL;
   
+  USHORT sel = RestoreOS2FS();
+  // DosEnterCritSec();
+  
   // register call exit
   pPB->ulCalldepth--;
@@ -531,30 +540,26 @@
   if (pPE)
   {
-    // Note:
-    // we don't take the values for the 1st call since all the lookup values
-    // are virtually non-deterministic and cannot be compensated for.
-    if (pPE->ulCalls > 1)
-    {
-      ULONG ulDiffHi = time_hi - pPB->enterTimeHi[i];
-      ULONG ulDiffLo = time_lo - pPB->enterTimeLo[i];
-      
-      // test for wrap around
-      if (ulDiffHi)
-        ulDiffLo = ~ulDiffLo;
-      
-      // timestamps are in "cpu cycles"
-      // ULONG ulTime = (ulDiffHi >> 4) | (ulDiffLo << 28);
-      ULONG ulTime = ulDiffLo;
-      
-      if (pPE->ulTimeMinimum > ulTime)
-        pPE->ulTimeMinimum = ulTime;
-      
-      if (pPE->ulTimeMaximum < ulTime)
-        pPE->ulTimeMaximum = ulTime;
-      
-      pPE->ulTimeTotal += ulTime;
-    }
-  }
-
+    ULONG ulDiffHi = time_hi - pPB->enterTimeHi[i];
+    ULONG ulDiffLo = time_lo - pPB->enterTimeLo[i];
+    
+    // test for wrap around
+    if (ulDiffHi)
+      ulDiffLo = ~ulDiffLo;
+    
+    // timestamps are in "cpu cycles"
+    // ULONG ulTime = (ulDiffHi >> 4) | (ulDiffLo << 28);
+    ULONG ulTime = ulDiffLo;
+    
+    if (pPE->ulTimeMinimum > ulTime)
+      pPE->ulTimeMinimum = ulTime;
+    
+    if (pPE->ulTimeMaximum < ulTime)
+      pPE->ulTimeMaximum = ulTime;
+    
+    pPE->ulTimeTotal += ulTime;
+  }
+  
+  // DosExitCritSec();
+  SetFS(sel);
   
   // 2 - return saved return address
@@ -657,4 +662,15 @@
   
   return iAvg1 - iAvg2;
+}
+
+int _Optlink sortHashtableEntries4(const void *arg1,const void *arg2)
+{
+  PHASHTABLEENTRYID pHTE1 = (PHASHTABLEENTRYID)arg1;
+  PHASHTABLEENTRYID pHTE2 = (PHASHTABLEENTRYID)arg2;
+  
+  PPROFILEENTRY p1 = (PPROFILEENTRY)pHTE1->pObject;
+  PPROFILEENTRY p2 = (PPROFILEENTRY)pHTE2->pObject;
+  
+  return p1->EIP - p2->EIP;
 }
 
@@ -785,4 +801,29 @@
   
   
+  // sort the list by address
+  qsort(arrEntries,
+        iEntries,
+        sizeof( HASHTABLEENTRYID ),
+        sortHashtableEntries4);
+  
+  
+  // write to file
+  fprintf(file,
+          "Functions / symbols sorted by address\n"
+          "Address ----- Function / Symbol -------------------------------------------\n");
+  for(i = 0;
+      i < iEntries;
+      i++)
+  {
+    PPROFILEENTRY p = (PPROFILEENTRY)arrEntries[i].pObject;
+    if (p->ulCalls > 1)
+    fprintf(file,
+            "#%08xh %-9s %s\n",
+            p->EIP,
+            p->pszModule,
+            p->pszFunction);
+  }
+  
+
   ProfilerEnable(flagLock);
 }
@@ -794,6 +835,7 @@
   char szFilename[260];
   USHORT sel = RestoreOS2FS();
-
-  sprintf(szFilename, "%s\\perf.log", szWorkingDirectory);
+  int pid = _getpid();
+
+  sprintf(szFilename, "%s\\%d.prof", szWorkingDirectory, pid);
   _privateLogFile = fopen(szFilename, "w");
   
Index: trunk/src/odinprof/symfile.cpp
===================================================================
--- trunk/src/odinprof/symfile.cpp	(revision 7421)
+++ trunk/src/odinprof/symfile.cpp	(revision 7423)
@@ -1,3 +1,3 @@
-/* $Id: symfile.cpp,v 1.1 2001-11-22 10:44:00 phaller Exp $ */
+/* $Id: symfile.cpp,v 1.2 2001-11-22 11:34:43 phaller Exp $ */
 /*
  * Project Odin Software License can be found in LICENSE.TXT
@@ -17,6 +17,4 @@
    => verify against kernel32\exceptionstack.cpp
    (KERNEL32.SYM is not interpreted correctly)
- - try to demangle C++ names
- - fix weird duplicate lookups of same symbol (i. e. SetBkColor)
  */
 
@@ -204,8 +202,9 @@
 
 
-BOOL   LXSymbolFile::getSymbolName(ULONG objNr,
-                                   ULONG offset,
-                                   PSZ   pszNameBuffer,
-                                   ULONG ulNameBufferLength)
+BOOL   LXSymbolFile::getSymbolName(ULONG  objNr,
+                                   ULONG  offset,
+                                   PSZ    pszNameBuffer,
+                                   ULONG  ulNameBufferLength,
+                                   PULONG pulSymbolOffset)
 {
   PUCHAR    p = (PUCHAR)pSymbolRawData;
@@ -264,5 +263,5 @@
               // find nearest symbol to the given offset
               if (iCurrent > 0)
-                if (iClosest < iCurrent)
+                if (iClosest > iCurrent)
                   pSymClosest = pSymDef32;
             }
@@ -278,4 +277,5 @@
               // terminate the string in any case
               pszNameBuffer[iLen] = 0;
+              *pulSymbolOffset = 0;
               
               // OK, found
@@ -293,5 +293,4 @@
         {
           CHAR szBuf[128];
-          CHAR szBuf2[128];
           int  iLen;
           
@@ -301,16 +300,16 @@
           {
             memcpy(szBuf, pSymClosest->achSymName, sizeof(szBuf));
-            szBuf[ sizeof(szBuf) ] = 0;
-            sprintf(szBuf2, "%s+%0xh", szBuf, offset - pSymClosest->wSymVal);
-            iLen = min(pSymClosest->cbSymName, ulNameBufferLength);
+            szBuf[ min(sizeof(szBuf), pSymClosest->cbSymName) ] = 0;
+            iLen = min(strlen(szBuf), ulNameBufferLength);
           }
           else
           {
-            sprintf(szBuf2, "%s:obj%d:%08xh", getName(), objNr, offset);
-            iLen = min(strlen(szBuf2), ulNameBufferLength);
+            sprintf(szBuf, "%s:obj%d:%08xh", getName(), objNr, offset);
+            iLen = min(strlen(szBuf), ulNameBufferLength);
           }
 
-          memcpy(pszNameBuffer, szBuf2, iLen);
+          memcpy(pszNameBuffer, szBuf, iLen);
           pszNameBuffer[iLen] = 0; // terminate the string in any case
+          *pulSymbolOffset = offset - pSymClosest->wSymVal;
           return TRUE;            // at least something usable has been found!
         }
@@ -386,9 +385,10 @@
 
   
-BOOL   SymbolFilePool::getSymbolName(PSZ   pszModule,
-                                     ULONG objNr,
-                                     ULONG offset,
-                                     PSZ   pszNameBuffer,
-                                     ULONG ulNameBufferLength)
+BOOL   SymbolFilePool::getSymbolName(PSZ    pszModule,
+                                     ULONG  objNr,
+                                     ULONG  offset,
+                                     PSZ    pszNameBuffer,
+                                     ULONG  ulNameBufferLength,
+                                     PULONG pulSymbolOffset)
 {
   LXSymbolFile* pSym = (LXSymbolFile*)pHashModules->getElement(pszModule);
@@ -421,5 +421,6 @@
                              offset,
                              pszNameBuffer,
-                             ulNameBufferLength);
+                             ulNameBufferLength,
+                             pulSymbolOffset);
     
     if (rc == TRUE)
@@ -433,6 +434,18 @@
                 name->Text(),
                 ulNameBufferLength);
-      
         delete name;
+      }
+
+      // append symbol offsets
+      if (*pulSymbolOffset != 0)
+      {
+        CHAR szBuf[256];
+        sprintf(szBuf,
+                "%s+%xh",
+                pszNameBuffer,
+                *pulSymbolOffset);
+        strncpy(pszNameBuffer,
+                szBuf,
+                ulNameBufferLength);
       }
     }
Index: trunk/src/odinprof/symfile.h
===================================================================
--- trunk/src/odinprof/symfile.h	(revision 7421)
+++ trunk/src/odinprof/symfile.h	(revision 7423)
@@ -1,3 +1,3 @@
-/* $Id: symfile.h,v 1.1 2001-11-22 10:44:00 phaller Exp $ */
+/* $Id: symfile.h,v 1.2 2001-11-22 11:34:44 phaller Exp $ */
 /*
  * Project Odin Software License can be found in LICENSE.TXT
@@ -135,8 +135,9 @@
     PSZ    getFileName();
     PSZ    getName() { return pszName; }
-    BOOL   getSymbolName(ULONG objNr,
-                         ULONG offset,
-                         PSZ   pszNameBuffer,
-                         ULONG ulNameBufferLength);
+    BOOL   getSymbolName(ULONG  objNr,
+                         ULONG  offset,
+                         PSZ    pszNameBuffer,
+                         ULONG  ulNameBufferLength,
+                         PULONG pulSymbolOffset);
   
   protected:
@@ -157,9 +158,10 @@
   
     APIRET searchModule(PSZ pszModule, PBYTE pBuffer, ULONG ulBufferLength);
-    BOOL   getSymbolName(PSZ   pszModule,
-                         ULONG objNr,
-                         ULONG offset,
-                         PSZ   pszNameBuffer,
-                         ULONG ulNameBufferLength);
+    BOOL   getSymbolName(PSZ    pszModule,
+                         ULONG  objNr,
+                         ULONG  offset,
+                         PSZ    pszNameBuffer,
+                         ULONG  ulNameBufferLength,
+                         PULONG pulSymbolOffset);
 
   protected:
