Annotation of mstools/samples/sdktools/capview/timer.cpp, revision 1.1

1.1     ! root        1: #include       <afxwin.h>
        !             2: #include       <afxdlgs.h>
        !             3: #include       <afxcoll.h>
        !             4: #include       <string.h>
        !             5: 
        !             6: #include "types.h"
        !             7: #include "ranges.h"
        !             8: #include "dispobj.h"
        !             9: #include "timer.h"
        !            10: 
        !            11: extern "C" char * UnDName(char *);
        !            12: 
        !            13: 
        !            14: TIMER::TIMER(char * pchDll, char * pchFunction, int cCalls, TIMETYPE timeTotal,
        !            15:           TIMETYPE timeThisFunc) :
        !            16:       strDllName(pchDll), strFunctName(pchFunction), rtDisplay(0, 0, 10, 10)
        !            17:     {
        !            18:         NumCalls = cCalls;
        !            19:         TotalTime = timeTotal;
        !            20:         TimeThisFunction = timeThisFunc;
        !            21: 
        !            22:         /*
        !            23:          * Correct these values on an open
        !            24:          */
        !            25: 
        !            26:         strDisplay = "";
        !            27:         
        !            28:     }
        !            29: 
        !            30:     void TIMER::DoForeground(CDC * cdc, BOOL fZoom, RANGESTRUCT * prs)
        !            31:     {
        !            32:         CRect   rtTmp = rtDisplay;
        !            33:        int     i;
        !            34:        int     j;
        !            35: 
        !            36:        if (fXYZ && IsOpen()) {
        !            37:            i = iBrush[1 + fTotal*2];
        !            38:            j = iBrush[0 + fTotal*2];
        !            39:        } else {
        !            40:            i = iBrush[0 + fTotal*2];
        !            41:            j = iBrush[0 + fTotal*2];
        !            42:        }
        !            43: 
        !            44:         CBrush cBrushI( prs->BackColor[i] );
        !            45:         CBrush cBrushJ( prs->BackColor[j] );
        !            46: 
        !            47: 
        !            48:         DoBackground(cdc, &cBrushI, &cBrushJ);
        !            49: 
        !            50:        if (!fZoom) {
        !            51:            rtTmp.OffsetRect(rtArea.TopLeft());
        !            52: 
        !            53:            cdc->SetTextColor(prs->TextColor[i] * RGB(255, 255, 255));
        !            54: 
        !            55:            cdc->DrawText(strDisplay, -1, &rtTmp, DT_NOCLIP|DT_EXPANDTABS);
        !            56:             
        !            57:        }
        !            58:         return;
        !            59:     }
        !            60: 
        !            61: void TIMER::DoSetPercents(TIMETYPE progTime)
        !            62: {
        !            63:     TIMER * p = Parent();
        !            64:     TIMETYPE    parentTotal;
        !            65: 
        !            66:     if (p == NULL) {
        !            67:         parentTotal = TotalTime;
        !            68:     } else {
        !            69:         parentTotal = p->TotalTime;
        !            70:     }
        !            71: 
        !            72:     perCent[0] = (int) TotalTime.PerCent(parentTotal);
        !            73:     perCent[1] = (int) TimeThisFunction.PerCent(TotalTime);
        !            74:     perCent[2] = (int) TotalTime.PerCent(progTime);
        !            75:     perCent[3] = (int) TimeThisFunction.PerCent(progTime);
        !            76:     return;
        !            77: }                               /* TIMER::DoSetPercents() */
        !            78: 
        !            79: void TIMER::DoSetColors(RANGESTRUCT * prs)
        !            80: {
        !            81:     int         i;
        !            82:     int         j;
        !            83: 
        !            84:     for (i=0; i<4; i++) {
        !            85:         for (j=0; j<prs->cRanges-1; j++) {
        !            86:             if ((prs->Above[j] <= perCent[i]) &&
        !            87:                 (perCent[i] < prs->Above[j+1])) {
        !            88:                 break;
        !            89:             }
        !            90:         }
        !            91:         iBrush[i] = j;
        !            92:     }
        !            93: 
        !            94:     if ((iBrush[2] == 0) && prs->fPrune) {
        !            95:         fPrune = TRUE;
        !            96:     } else {
        !            97:         fPrune = FALSE;
        !            98:     }
        !            99: 
        !           100:     return;
        !           101: }                               /* TIMER::DoSetColors() */
        !           102: 
        !           103: 
        !           104: void TIMER::DoSetString()
        !           105: {
        !           106:     char        rgch[256];
        !           107: 
        !           108:     strDisplay = strDllName + "\n" + strFunctName;
        !           109:     sprintf(rgch, "\n%d\n%3d%%\t%3d%%\t", NumCalls, perCent[1], perCent[3]);
        !           110:     strDisplay += rgch;
        !           111:     strDisplay += TimeThisFunction.format(rgch);
        !           112:     sprintf(rgch, "\n%3d%%\t%3d%%\t", perCent[0], perCent[2]);
        !           113:     strDisplay += rgch;
        !           114:     strDisplay += TotalTime.format(rgch);
        !           115: 
        !           116:     return;
        !           117: }                               /* TIMER::DoSetString() */
        !           118:       
        !           119:     
        !           120: 
        !           121: void TIMER::DoAssignSize(CDC * pcdc)
        !           122: {
        !           123:     rtDisplay.SetRect(4, 4, 10, 10);
        !           124:     pcdc->DrawText(strDisplay, -1, &rtDisplay, DT_CALCRECT|DT_EXPANDTABS);
        !           125:     return;
        !           126: }                               /* TIMER::DoAssignSize() */
        !           127: 
        !           128: 
        !           129: void TIMERROOT::AddTiming(int iDepth, char * szModule, char * szName, int cCalls, TIMETYPE timeTotal, TIMETYPE timeFunction)
        !           130: {
        !           131:     TIMER * pTimer = new TIMER( szModule, szName, cCalls, timeTotal, timeFunction);
        !           132: 
        !           133:     if (pRoot == NULL) {
        !           134:         pTimerCur = pRoot = new TIMER( "APP", "***", 0, 0, 0);
        !           135:         level = -1;
        !           136:     }
        !           137: 
        !           138:     pRoot->AddTime(timeFunction);
        !           139: 
        !           140:     if (iDepth == level) {
        !           141:         pTimerCur->AddSibling(pTimer);
        !           142:     } else if (iDepth == level + 1) {
        !           143:         pTimerCur->AddChild( pTimer );
        !           144:         level = iDepth;
        !           145:     } else  {
        !           146:         while (level != iDepth) {
        !           147:             pTimerCur = pTimerCur->Parent();
        !           148:             level -= 1;
        !           149:         }
        !           150:         pTimerCur->AddSibling(pTimer);
        !           151:     }
        !           152:     pTimerCur = pTimer;
        !           153:     return;
        !           154: }                               /* TIMERROOT::AddTiming() */
        !           155: 
        !           156: void TIMERROOT::SetProperties(int flags, BOOL fZoom, RANGESTRUCT * prs, CDC * pcdc)
        !           157: {
        !           158:     BOOL        fLoc = flags & SET_LOCATION;
        !           159:     int         i;
        !           160: 
        !           161:     if (fLoc) {
        !           162:         flags |= SET_LOCATIONPREP;
        !           163:         flags &= ~SET_LOCATION;
        !           164:         rgLoc.RemoveAll();
        !           165:     }
        !           166:     pRoot->SetProperties(flags, prs, pcdc, fZoom, pRoot->timeTotal());
        !           167: 
        !           168:     if (fLoc) {
        !           169:         rgLoc[0].left = spaceHorizontal;
        !           170:         rgLoc[0].y = 0;
        !           171:         for (i=1; i<rgLoc.GetSize(); i++) {
        !           172:             rgLoc[i].left = rgLoc[i-1].left + rgLoc[i-1].width + spaceHorizontal;
        !           173:             rgLoc[i].y = 0;
        !           174:         }
        !           175:     
        !           176:         pRoot->SetProperties(SET_LOCATION, prs, pcdc, fZoom);
        !           177:     }
        !           178: 
        !           179:     return;
        !           180: }
        !           181: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.