⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 perf.cpp

📁 自己动手写操作系统源代码,不可多得的代码
💻 CPP
字号:
//***********************************************************************/
//    Author                    : Garry
//    Original Date             : Sep,16 2005
//    Module Name               : PERF.CPP
//    Module Funciton           : 
//                                This module countains the performance mesuring mechanism's 
//                                implementation.
//                                The performance mesuring mechanism is used to mesure one
//                                segment of code's performance,in CPU clock circle.
//    Last modified Author      :
//    Last modified Date        :
//    Last modified Content     :
//                                1.
//                                2.
//    Lines number              :
//***********************************************************************/

#ifndef __STDAFX_H__
#include "..\INCLUDE\StdAfx.h"
#endif

//
//The implementation of PerfBeginRecord routine.
//This routine records the current CPU clock circle counter into u64Start member of
//lpPr object.
//

VOID PerfBeginRecord(__PERF_RECORDER* lpPr)
{
	__U64*           lpStart    = NULL;

	if(NULL == lpPr)    //Parameter check.
		return;
	lpStart = &lpPr->u64Start;

#ifdef __I386__
	__asm{
		push eax
        push ebx
        push edx
        mov ebx,lpStart
        rdtsc                       //Read time stamp counter.
        mov dword ptr [ebx],eax     //Save low part
        mov dword ptr [ebx + 4],edx //Save high part.
        pop edx
        pop ebx
        pop eax
	}
#else
#endif
}

//
//The implementation of PerfEndRecord routine.
//This routine record the current CPU clock circle counter into u64End member of
//lpPr object.
//

VOID PerfEndRecord(__PERF_RECORDER* lpPr)
{
	__U64*         lpEnd            = NULL;

	if(NULL == lpPr)  //Parameter check.
		return;
	lpEnd = &lpPr->u64End;

#ifdef __I386__
	__asm{
        push eax
        push ebx
        push edx
        mov ebx,lpEnd
        rdtsc                        //Read time stamp counter.
        mov dword ptr [ebx],eax      //Save low part
        mov dword ptr [ebx + 4],edx  //Save high part.
        pop edx
        pop ebx
        pop  eax
	}
#else
#endif
}

//
//The following routine calculates the clock circle counter of the current test.
//It subtract u64Start from u64End of lpPr object,and save the result into
//u64Result member.
//

VOID PerfCommit(__PERF_RECORDER* lpPr)
{
	if(NULL == lpPr)    //Parameter check.
		return;
	u64Sub(&lpPr->u64End,&lpPr->u64Start,&lpPr->u64Result);  //Performance a subtraction.
	if(MoreThan(&lpPr->u64Result,&lpPr->u64Max)) //The current max is less than this
		                                         //result.
	{
		lpPr->u64Max = lpPr->u64Result;          //Update the current max value.
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -