Changeset 7423 for trunk/src


Ignore:
Timestamp:
Nov 22, 2001, 12:34:44 PM (24 years ago)
Author:
phaller
Message:

.

Location:
trunk/src/odinprof
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/odinprof/profiler.cpp

    r7421 r7423  
    1 /* $Id: profiler.cpp,v 1.1 2001-11-22 10:43:59 phaller Exp $ */
     1/* $Id: profiler.cpp,v 1.2 2001-11-22 11:34:43 phaller Exp $ */
    22/*
    33 * Project Odin Software License can be found in LICENSE.TXT
     
    3333#include <math.h>
    3434#include <direct.h>
     35#include <process.h>
    3536
    3637#include "symfile.h"
     
    397398  CHAR   szModule[260];                        /* buffer for the module name */
    398399  ULONG  ulOffset;             /* offset within the object within the module */
     400  ULONG  ulSymbolOffset;
    399401 
    400402  rc = DosQueryModFromEIP(&ulModule,
     
    414416                                         ulOffset,
    415417                                         szFunction,
    416                                          sizeof(szFunction)) )
     418                                         sizeof(szFunction),
     419                                         &ulSymbolOffset) )
    417420    {
    418421      sprintf(szFunction,
     
    450453    return ret;
    451454 
     455  USHORT sel = RestoreOS2FS();
     456  // DosEnterCritSec();
     457 
     458 
    452459  // "call _ProfileHook32" has 5 bytes, adjust here
    453460  eip_function -= 5;
     
    472479  if (NULL == pPE)
    473480  {
    474     USHORT sel = RestoreOS2FS();
    475    
    476481    pPE = (PPROFILEENTRY)malloc( sizeof(PROFILEENTRY) );
    477482   
     
    491496    // @@@PH need to synchronize access!
    492497    pPB->pHashtable->addElement(eip_function, pPE);
    493    
    494     SetFS(sel);
    495498  }
    496499 
     
    500503  // register call and skip to the next empty slot
    501504  pPB->ulCalldepth++;
     505 
     506  // DosExitCritSec();
     507  SetFS(sel);
    502508 
    503509  // get "compensated" timestamp
     
    522528    return NULL;
    523529 
     530  USHORT sel = RestoreOS2FS();
     531  // DosEnterCritSec();
     532 
    524533  // register call exit
    525534  pPB->ulCalldepth--;
     
    531540  if (pPE)
    532541  {
    533     // Note:
    534     // we don't take the values for the 1st call since all the lookup values
    535     // are virtually non-deterministic and cannot be compensated for.
    536     if (pPE->ulCalls > 1)
    537     {
    538       ULONG ulDiffHi = time_hi - pPB->enterTimeHi[i];
    539       ULONG ulDiffLo = time_lo - pPB->enterTimeLo[i];
    540      
    541       // test for wrap around
    542       if (ulDiffHi)
    543         ulDiffLo = ~ulDiffLo;
    544      
    545       // timestamps are in "cpu cycles"
    546       // ULONG ulTime = (ulDiffHi >> 4) | (ulDiffLo << 28);
    547       ULONG ulTime = ulDiffLo;
    548      
    549       if (pPE->ulTimeMinimum > ulTime)
    550         pPE->ulTimeMinimum = ulTime;
    551      
    552       if (pPE->ulTimeMaximum < ulTime)
    553         pPE->ulTimeMaximum = ulTime;
    554      
    555       pPE->ulTimeTotal += ulTime;
    556     }
    557   }
    558 
     542    ULONG ulDiffHi = time_hi - pPB->enterTimeHi[i];
     543    ULONG ulDiffLo = time_lo - pPB->enterTimeLo[i];
     544   
     545    // test for wrap around
     546    if (ulDiffHi)
     547      ulDiffLo = ~ulDiffLo;
     548   
     549    // timestamps are in "cpu cycles"
     550    // ULONG ulTime = (ulDiffHi >> 4) | (ulDiffLo << 28);
     551    ULONG ulTime = ulDiffLo;
     552   
     553    if (pPE->ulTimeMinimum > ulTime)
     554      pPE->ulTimeMinimum = ulTime;
     555   
     556    if (pPE->ulTimeMaximum < ulTime)
     557      pPE->ulTimeMaximum = ulTime;
     558   
     559    pPE->ulTimeTotal += ulTime;
     560  }
     561 
     562  // DosExitCritSec();
     563  SetFS(sel);
    559564 
    560565  // 2 - return saved return address
     
    657662 
    658663  return iAvg1 - iAvg2;
     664}
     665
     666int _Optlink sortHashtableEntries4(const void *arg1,const void *arg2)
     667{
     668  PHASHTABLEENTRYID pHTE1 = (PHASHTABLEENTRYID)arg1;
     669  PHASHTABLEENTRYID pHTE2 = (PHASHTABLEENTRYID)arg2;
     670 
     671  PPROFILEENTRY p1 = (PPROFILEENTRY)pHTE1->pObject;
     672  PPROFILEENTRY p2 = (PPROFILEENTRY)pHTE2->pObject;
     673 
     674  return p1->EIP - p2->EIP;
    659675}
    660676
     
    785801 
    786802 
     803  // sort the list by address
     804  qsort(arrEntries,
     805        iEntries,
     806        sizeof( HASHTABLEENTRYID ),
     807        sortHashtableEntries4);
     808 
     809 
     810  // write to file
     811  fprintf(file,
     812          "Functions / symbols sorted by address\n"
     813          "Address ----- Function / Symbol -------------------------------------------\n");
     814  for(i = 0;
     815      i < iEntries;
     816      i++)
     817  {
     818    PPROFILEENTRY p = (PPROFILEENTRY)arrEntries[i].pObject;
     819    if (p->ulCalls > 1)
     820    fprintf(file,
     821            "#%08xh %-9s %s\n",
     822            p->EIP,
     823            p->pszModule,
     824            p->pszFunction);
     825  }
     826 
     827
    787828  ProfilerEnable(flagLock);
    788829}
     
    794835  char szFilename[260];
    795836  USHORT sel = RestoreOS2FS();
    796 
    797   sprintf(szFilename, "%s\\perf.log", szWorkingDirectory);
     837  int pid = _getpid();
     838
     839  sprintf(szFilename, "%s\\%d.prof", szWorkingDirectory, pid);
    798840  _privateLogFile = fopen(szFilename, "w");
    799841 
  • trunk/src/odinprof/symfile.cpp

    r7421 r7423  
    1 /* $Id: symfile.cpp,v 1.1 2001-11-22 10:44:00 phaller Exp $ */
     1/* $Id: symfile.cpp,v 1.2 2001-11-22 11:34:43 phaller Exp $ */
    22/*
    33 * Project Odin Software License can be found in LICENSE.TXT
     
    1717   => verify against kernel32\exceptionstack.cpp
    1818   (KERNEL32.SYM is not interpreted correctly)
    19  - try to demangle C++ names
    20  - fix weird duplicate lookups of same symbol (i. e. SetBkColor)
    2119 */
    2220
     
    204202
    205203
    206 BOOL   LXSymbolFile::getSymbolName(ULONG objNr,
    207                                    ULONG offset,
    208                                    PSZ   pszNameBuffer,
    209                                    ULONG ulNameBufferLength)
     204BOOL   LXSymbolFile::getSymbolName(ULONG  objNr,
     205                                   ULONG  offset,
     206                                   PSZ    pszNameBuffer,
     207                                   ULONG  ulNameBufferLength,
     208                                   PULONG pulSymbolOffset)
    210209{
    211210  PUCHAR    p = (PUCHAR)pSymbolRawData;
     
    264263              // find nearest symbol to the given offset
    265264              if (iCurrent > 0)
    266                 if (iClosest < iCurrent)
     265                if (iClosest > iCurrent)
    267266                  pSymClosest = pSymDef32;
    268267            }
     
    278277              // terminate the string in any case
    279278              pszNameBuffer[iLen] = 0;
     279              *pulSymbolOffset = 0;
    280280             
    281281              // OK, found
     
    293293        {
    294294          CHAR szBuf[128];
    295           CHAR szBuf2[128];
    296295          int  iLen;
    297296         
     
    301300          {
    302301            memcpy(szBuf, pSymClosest->achSymName, sizeof(szBuf));
    303             szBuf[ sizeof(szBuf) ] = 0;
    304             sprintf(szBuf2, "%s+%0xh", szBuf, offset - pSymClosest->wSymVal);
    305             iLen = min(pSymClosest->cbSymName, ulNameBufferLength);
     302            szBuf[ min(sizeof(szBuf), pSymClosest->cbSymName) ] = 0;
     303            iLen = min(strlen(szBuf), ulNameBufferLength);
    306304          }
    307305          else
    308306          {
    309             sprintf(szBuf2, "%s:obj%d:%08xh", getName(), objNr, offset);
    310             iLen = min(strlen(szBuf2), ulNameBufferLength);
     307            sprintf(szBuf, "%s:obj%d:%08xh", getName(), objNr, offset);
     308            iLen = min(strlen(szBuf), ulNameBufferLength);
    311309          }
    312310
    313           memcpy(pszNameBuffer, szBuf2, iLen);
     311          memcpy(pszNameBuffer, szBuf, iLen);
    314312          pszNameBuffer[iLen] = 0; // terminate the string in any case
     313          *pulSymbolOffset = offset - pSymClosest->wSymVal;
    315314          return TRUE;            // at least something usable has been found!
    316315        }
     
    386385
    387386 
    388 BOOL   SymbolFilePool::getSymbolName(PSZ   pszModule,
    389                                      ULONG objNr,
    390                                      ULONG offset,
    391                                      PSZ   pszNameBuffer,
    392                                      ULONG ulNameBufferLength)
     387BOOL   SymbolFilePool::getSymbolName(PSZ    pszModule,
     388                                     ULONG  objNr,
     389                                     ULONG  offset,
     390                                     PSZ    pszNameBuffer,
     391                                     ULONG  ulNameBufferLength,
     392                                     PULONG pulSymbolOffset)
    393393{
    394394  LXSymbolFile* pSym = (LXSymbolFile*)pHashModules->getElement(pszModule);
     
    421421                             offset,
    422422                             pszNameBuffer,
    423                              ulNameBufferLength);
     423                             ulNameBufferLength,
     424                             pulSymbolOffset);
    424425   
    425426    if (rc == TRUE)
     
    433434                name->Text(),
    434435                ulNameBufferLength);
    435      
    436436        delete name;
     437      }
     438
     439      // append symbol offsets
     440      if (*pulSymbolOffset != 0)
     441      {
     442        CHAR szBuf[256];
     443        sprintf(szBuf,
     444                "%s+%xh",
     445                pszNameBuffer,
     446                *pulSymbolOffset);
     447        strncpy(pszNameBuffer,
     448                szBuf,
     449                ulNameBufferLength);
    437450      }
    438451    }
  • trunk/src/odinprof/symfile.h

    r7421 r7423  
    1 /* $Id: symfile.h,v 1.1 2001-11-22 10:44:00 phaller Exp $ */
     1/* $Id: symfile.h,v 1.2 2001-11-22 11:34:44 phaller Exp $ */
    22/*
    33 * Project Odin Software License can be found in LICENSE.TXT
     
    135135    PSZ    getFileName();
    136136    PSZ    getName() { return pszName; }
    137     BOOL   getSymbolName(ULONG objNr,
    138                          ULONG offset,
    139                          PSZ   pszNameBuffer,
    140                          ULONG ulNameBufferLength);
     137    BOOL   getSymbolName(ULONG  objNr,
     138                         ULONG  offset,
     139                         PSZ    pszNameBuffer,
     140                         ULONG  ulNameBufferLength,
     141                         PULONG pulSymbolOffset);
    141142 
    142143  protected:
     
    157158 
    158159    APIRET searchModule(PSZ pszModule, PBYTE pBuffer, ULONG ulBufferLength);
    159     BOOL   getSymbolName(PSZ   pszModule,
    160                          ULONG objNr,
    161                          ULONG offset,
    162                          PSZ   pszNameBuffer,
    163                          ULONG ulNameBufferLength);
     160    BOOL   getSymbolName(PSZ    pszModule,
     161                         ULONG  objNr,
     162                         ULONG  offset,
     163                         PSZ    pszNameBuffer,
     164                         ULONG  ulNameBufferLength,
     165                         PULONG pulSymbolOffset);
    164166
    165167  protected:
Note: See TracChangeset for help on using the changeset viewer.