- Timestamp:
- Nov 22, 2001, 12:34:44 PM (24 years ago)
- 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:59phaller Exp $ */1 /* $Id: profiler.cpp,v 1.2 2001-11-22 11:34:43 phaller Exp $ */ 2 2 /* 3 3 * Project Odin Software License can be found in LICENSE.TXT … … 33 33 #include <math.h> 34 34 #include <direct.h> 35 #include <process.h> 35 36 36 37 #include "symfile.h" … … 397 398 CHAR szModule[260]; /* buffer for the module name */ 398 399 ULONG ulOffset; /* offset within the object within the module */ 400 ULONG ulSymbolOffset; 399 401 400 402 rc = DosQueryModFromEIP(&ulModule, … … 414 416 ulOffset, 415 417 szFunction, 416 sizeof(szFunction)) ) 418 sizeof(szFunction), 419 &ulSymbolOffset) ) 417 420 { 418 421 sprintf(szFunction, … … 450 453 return ret; 451 454 455 USHORT sel = RestoreOS2FS(); 456 // DosEnterCritSec(); 457 458 452 459 // "call _ProfileHook32" has 5 bytes, adjust here 453 460 eip_function -= 5; … … 472 479 if (NULL == pPE) 473 480 { 474 USHORT sel = RestoreOS2FS();475 476 481 pPE = (PPROFILEENTRY)malloc( sizeof(PROFILEENTRY) ); 477 482 … … 491 496 // @@@PH need to synchronize access! 492 497 pPB->pHashtable->addElement(eip_function, pPE); 493 494 SetFS(sel);495 498 } 496 499 … … 500 503 // register call and skip to the next empty slot 501 504 pPB->ulCalldepth++; 505 506 // DosExitCritSec(); 507 SetFS(sel); 502 508 503 509 // get "compensated" timestamp … … 522 528 return NULL; 523 529 530 USHORT sel = RestoreOS2FS(); 531 // DosEnterCritSec(); 532 524 533 // register call exit 525 534 pPB->ulCalldepth--; … … 531 540 if (pPE) 532 541 { 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); 559 564 560 565 // 2 - return saved return address … … 657 662 658 663 return iAvg1 - iAvg2; 664 } 665 666 int _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; 659 675 } 660 676 … … 785 801 786 802 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 787 828 ProfilerEnable(flagLock); 788 829 } … … 794 835 char szFilename[260]; 795 836 USHORT sel = RestoreOS2FS(); 796 797 sprintf(szFilename, "%s\\perf.log", szWorkingDirectory); 837 int pid = _getpid(); 838 839 sprintf(szFilename, "%s\\%d.prof", szWorkingDirectory, pid); 798 840 _privateLogFile = fopen(szFilename, "w"); 799 841 -
trunk/src/odinprof/symfile.cpp
r7421 r7423 1 /* $Id: symfile.cpp,v 1. 1 2001-11-22 10:44:00phaller Exp $ */1 /* $Id: symfile.cpp,v 1.2 2001-11-22 11:34:43 phaller Exp $ */ 2 2 /* 3 3 * Project Odin Software License can be found in LICENSE.TXT … … 17 17 => verify against kernel32\exceptionstack.cpp 18 18 (KERNEL32.SYM is not interpreted correctly) 19 - try to demangle C++ names20 - fix weird duplicate lookups of same symbol (i. e. SetBkColor)21 19 */ 22 20 … … 204 202 205 203 206 BOOL LXSymbolFile::getSymbolName(ULONG objNr, 207 ULONG offset, 208 PSZ pszNameBuffer, 209 ULONG ulNameBufferLength) 204 BOOL LXSymbolFile::getSymbolName(ULONG objNr, 205 ULONG offset, 206 PSZ pszNameBuffer, 207 ULONG ulNameBufferLength, 208 PULONG pulSymbolOffset) 210 209 { 211 210 PUCHAR p = (PUCHAR)pSymbolRawData; … … 264 263 // find nearest symbol to the given offset 265 264 if (iCurrent > 0) 266 if (iClosest <iCurrent)265 if (iClosest > iCurrent) 267 266 pSymClosest = pSymDef32; 268 267 } … … 278 277 // terminate the string in any case 279 278 pszNameBuffer[iLen] = 0; 279 *pulSymbolOffset = 0; 280 280 281 281 // OK, found … … 293 293 { 294 294 CHAR szBuf[128]; 295 CHAR szBuf2[128];296 295 int iLen; 297 296 … … 301 300 { 302 301 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); 306 304 } 307 305 else 308 306 { 309 sprintf(szBuf 2, "%s:obj%d:%08xh", getName(), objNr, offset);310 iLen = min(strlen(szBuf 2), ulNameBufferLength);307 sprintf(szBuf, "%s:obj%d:%08xh", getName(), objNr, offset); 308 iLen = min(strlen(szBuf), ulNameBufferLength); 311 309 } 312 310 313 memcpy(pszNameBuffer, szBuf 2, iLen);311 memcpy(pszNameBuffer, szBuf, iLen); 314 312 pszNameBuffer[iLen] = 0; // terminate the string in any case 313 *pulSymbolOffset = offset - pSymClosest->wSymVal; 315 314 return TRUE; // at least something usable has been found! 316 315 } … … 386 385 387 386 388 BOOL SymbolFilePool::getSymbolName(PSZ pszModule, 389 ULONG objNr, 390 ULONG offset, 391 PSZ pszNameBuffer, 392 ULONG ulNameBufferLength) 387 BOOL SymbolFilePool::getSymbolName(PSZ pszModule, 388 ULONG objNr, 389 ULONG offset, 390 PSZ pszNameBuffer, 391 ULONG ulNameBufferLength, 392 PULONG pulSymbolOffset) 393 393 { 394 394 LXSymbolFile* pSym = (LXSymbolFile*)pHashModules->getElement(pszModule); … … 421 421 offset, 422 422 pszNameBuffer, 423 ulNameBufferLength); 423 ulNameBufferLength, 424 pulSymbolOffset); 424 425 425 426 if (rc == TRUE) … … 433 434 name->Text(), 434 435 ulNameBufferLength); 435 436 436 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); 437 450 } 438 451 } -
trunk/src/odinprof/symfile.h
r7421 r7423 1 /* $Id: symfile.h,v 1. 1 2001-11-22 10:44:00phaller Exp $ */1 /* $Id: symfile.h,v 1.2 2001-11-22 11:34:44 phaller Exp $ */ 2 2 /* 3 3 * Project Odin Software License can be found in LICENSE.TXT … … 135 135 PSZ getFileName(); 136 136 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); 141 142 142 143 protected: … … 157 158 158 159 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); 164 166 165 167 protected:
Note:
See TracChangeset
for help on using the changeset viewer.