Changeset 7025


Ignore:
Timestamp:
Oct 12, 2001, 2:49:51 AM (24 years ago)
Author:
phaller
Message:

improvement of profiler

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/include/perfview.h

    r7010 r7025  
    1 /* $Id: perfview.h,v 1.1 2001-10-11 00:59:59 phaller Exp $ */
     1/* $Id: perfview.h,v 1.2 2001-10-12 00:49:51 phaller Exp $ */
    22
    33/*
     
    1818extern "C" {
    1919#endif
    20 
     20 
     21 
     22// calibrate the subsystem
     23void _Optlink PerfView_Initialize(void);
    2124
    2225// register a call to a function
  • TabularUnified trunk/src/kernel32/perfview.cpp

    r7021 r7025  
    1 /* $Id: perfview.cpp,v 1.1 2001-10-11 17:31:12 phaller Exp $ */
     1/* $Id: perfview.cpp,v 1.2 2001-10-12 00:49:24 phaller Exp $ */
    22
    33/*
     
    1818
    1919// insert "nullified" dummies here to save space in the executable image
     20void PerfView_Initialize(void) {}
    2021void PerfView_RegisterCall(char* pszFunctionName,
    2122                           unsigned long int nTicks) {}
     
    2728
    2829#include <ccollection.h>
    29 #include <win32type.h>
     30#include <winbase.h>
    3031
    3132// imported from the kernel loader (initterm)
     
    4041  unsigned long int nCalled;
    4142  unsigned long int nTotalTicks;
     43  unsigned long int nMinimumTicks;
     44  unsigned long int nMaximumTicks;
    4245} PERFVIEW_FUNCTION, *PPERFVIEW_FUNCTION;
    4346
     
    4649static CHashtableLookup* pProfileMap = new CHashtableLookup(1021);
    4750static BOOL flagLock = FALSE;
     51static unsigned long int tsCompensation = 0;
     52
     53
     54// measure the measurement overhead itself
     55void PerfView_Initialize(void)
     56{
     57#define CALIBRATION_RUNS 100
     58 
     59  LARGE_INTEGER liStart;
     60  LARGE_INTEGER liEnd;
     61  unsigned long ulElapsed;
     62 
     63  // initialize this
     64  tsCompensation = 0;
     65 
     66  for (int i = 0;
     67       i < CALIBRATION_RUNS;
     68       i++)
     69  {
     70    QueryPerformanceCounter(&liStart);
     71    QueryPerformanceCounter(&liEnd);
     72
     73    if (liStart.LowPart > liEnd.LowPart)
     74      ulElapsed = 0xFFFFFFFF - liStart.LowPart + liEnd.LowPart;
     75    else
     76      ulElapsed = liEnd.LowPart - liStart.LowPart;
     77 
     78    // save the determined amount of elapsed ticks
     79    // as compensatory factor
     80    tsCompensation += ulElapsed;
     81  }
     82
     83  // now calculate back to real value
     84  tsCompensation /= CALIBRATION_RUNS;
     85}
     86
    4887
    4988// register a call to a function
     
    5493  if (flagLock)
    5594    return;
     95 
     96  // subtract the measurement overhead factor.
     97  // Note: this should rather be done where the times are taken,
     98  // however this would spread the code just too far.
     99  nTicks -= tsCompensation;
    56100 
    57101  // check if that particular function is registered already
     
    64108    p->nCalled = 0;
    65109    p->nTotalTicks = 0;
     110    p->nMinimumTicks = 0xffffffff;
     111    p->nMaximumTicks = 0;
    66112   
    67113    // add to the hashtable
     
    72118  p->nCalled++;
    73119  p->nTotalTicks += nTicks;
     120 
     121  if (nTicks < p->nMinimumTicks)
     122    p->nMinimumTicks = nTicks;
     123 
     124  if (nTicks > p->nMaximumTicks)
     125    p->nMaximumTicks = nTicks;
    74126}
    75127
     
    134186  PHASHTABLEENTRY arrEntries = (PHASHTABLEENTRY)malloc( iEntries * sizeof(HASHTABLEENTRY) );
    135187  iEntries = pProfileMap->getElementMap(arrEntries);
     188 
     189  fprintf(file,
     190          "ODIN Performance Analysis\n"
     191          "%d entries available, compensated measure overhead is %d ticks.\n\n",
     192          iEntries,
     193          tsCompensation);
     194 
    136195 
    137196  // sort the list by function name
     
    144203  fprintf(file,
    145204          "Sorted by function name\n"
     205          "Ticks ---- Called --- Average -- Minimum -- Maximum -- Function -----------\n");
     206  for(int i = 0;
     207      i < iEntries;
     208      i++)
     209  {
     210    PPERFVIEW_FUNCTION p = (PPERFVIEW_FUNCTION)arrEntries[i].pObject;
     211    fprintf(file,
     212            "%10d %10d %10d %10d %10d %s\n",
     213            p->nTotalTicks,
     214            p->nCalled,
     215            p->nTotalTicks / p->nCalled,
     216            p->nMinimumTicks,
     217            p->nMaximumTicks,
     218            p->pszFunctionName);
     219  }
     220 
     221 
     222  // sort the list by nTotalTicks
     223  qsort(arrEntries,
     224        iEntries,
     225        sizeof( HASHTABLEENTRY ),
     226        sortHashtableEntries1);
     227 
     228  // write to file
     229  fprintf(file,
     230          "\nSorted by total call time\n"
    146231          "Ticks ---- Called --- Average -- Function ---------------------------------\n");
    147   for(int i = 0;
     232  for(i = 0;
    148233      i < iEntries;
    149234      i++)
     
    159244 
    160245 
    161   // sort the list by nTotalTicks
    162   qsort(arrEntries,
    163         iEntries,
    164         sizeof( HASHTABLEENTRY ),
    165         sortHashtableEntries1);
    166  
    167   // write to file
    168   fprintf(file,
    169           "\nSorted by total call time\n"
    170           "Ticks ---- Called --- Average -- Function ---------------------------------\n");
    171   for(i = 0;
    172       i < iEntries;
    173       i++)
    174   {
    175     PPERFVIEW_FUNCTION p = (PPERFVIEW_FUNCTION)arrEntries[i].pObject;
    176     fprintf(file,
    177             "%10d %10d %10d %s\n",
    178             p->nTotalTicks,
    179             p->nCalled,
    180             p->nTotalTicks / p->nCalled,
    181             p->pszFunctionName);
    182   }
    183  
    184  
    185246  // sort the list by nCalled
    186247  qsort(arrEntries,
  • TabularUnified trunk/src/kernel32/winexepeldr.cpp

    r5262 r7025  
    1 /* $Id: winexepeldr.cpp,v 1.15 2001-02-24 12:59:44 sandervl Exp $ */
     1/* $Id: winexepeldr.cpp,v 1.16 2001-10-12 00:49:23 phaller Exp $ */
    22
    33/*
     
    3939#define DBG_LOCALLOG    DBG_winexepeldr
    4040#include "dbglocal.h"
     41
     42
     43#ifdef PROFILE
     44#include <perfview.h>
     45#endif /* PROFILE */
     46
    4147
    4248extern char szErrorTitle[];
     
    141147  }
    142148  OS2UnsetExceptionHandler(&exceptFrame);
    143 
     149 
     150#ifdef PROFILE
     151  // Note: after this point, we might start collecting performance
     152  // information about the called functions.
     153  PerfView_Initialize();
     154#endif /* PROFILE */
     155 
     156 
    144157  WinExe->start();
    145158
  • TabularUnified trunk/src/kernel32/wprocess.cpp

    r7010 r7025  
    1 /* $Id: wprocess.cpp,v 1.135 2001-10-11 01:00:12 phaller Exp $ */
     1/* $Id: wprocess.cpp,v 1.136 2001-10-12 00:49:23 phaller Exp $ */
    22
    33/*
     
    4747#define DBG_LOCALLOG    DBG_wprocess
    4848#include "dbglocal.h"
     49
     50#ifdef PROFILE
     51#include <perfview.h>
     52#endif /* PROFILE */
     53
    4954
    5055ODINDEBUGCHANNEL(KERNEL32-WPROCESS)
Note: See TracChangeset for help on using the changeset viewer.