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

.

File:
1 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 
Note: See TracChangeset for help on using the changeset viewer.