Changeset 7423 for trunk/src/odinprof/profiler.cpp
- Timestamp:
- Nov 22, 2001, 12:34:44 PM (24 years ago)
- 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: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
Note:
See TracChangeset
for help on using the changeset viewer.