📄 metrics.c
字号:
/**************************************************************************
* Name : metrics.c
* Author : BCB
* Created : 10/07/2003
*
* Copyright : 2003 by Imagination Technologies Limited. All rights reserved.
* : No part of this software, either material or conceptual
* : may be copied or distributed, transmitted, transcribed,
* : stored in a retrieval system or translated into any
* : human or computer language in any form by any means,
* : electronic, mechanical, manual or other-wise, or
* : disclosed to third parties without the express written
* : permission of Imagination Technologies Limited, Unit 8, HomePark
* : Industrial Estate, King's Langley, Hertfordshire,
* : WD4 8LZ, U.K.
*
* Platform : ANSI
*
* $Date: 2004/10/26 09:08:10 $ $Revision: 1.22 $
* $Log: metrics.c $
*
* --- Revision Logs Removed ---
**************************************************************************/
#define MODULE_ID MODID_METRICS
/* Exclude from non-Metrics builds */
#if defined (TIMING) || defined (DEBUG)
#ifdef _WIN32
#include <windows.h>
#else
#ifdef __linux__
#include <unistd.h>
#endif
#endif
#include "context.h"
#ifdef _WIN32
#define DPFMETRIC(x) DPFF(##x);\
DPFTIME(##x)
#else
#ifdef METRIC
#define DPFMETRIC(x) DPFF(x)
#else
#define DPFMETRIC(x) DPFTIME(x)
#endif
#endif
#if !defined(__SYMBIAN32__)
extern IMG_UINT32 ui32TextureMemHWM;
#endif
/***********************************************************************************
Function Name : GetFrameTime
Inputs : gc
Outputs : -
Returns : -
Description : Gets total time for a frame
************************************************************************************/
IMG_VOID GetFrameTime(GLESContext *gc)
{
IMG_UINT32 ui32TimeNow = GLESTimeNow(gc);
IMG_UINT32 ui32PreviousFrameTime = gc->ui32PrevTime;
IMG_FLOAT fTimeInFrame = (ui32TimeNow - ui32PreviousFrameTime) * gc->fCPUSpeed;
/* Don't include first frame time */
if(ui32PreviousFrameTime)
{
gc->asTimes[GLES_TIMER_TOTAL_FRAME_TIME].fStack += fTimeInFrame;
}
gc->ui32PrevTime = ui32TimeNow;
}
/***********************************************************************************
Function Name : MetricsInitiateTiming
Inputs : -
Outputs : -
Returns : -
Description : Resets metrics timers and finds CPU speed
************************************************************************************/
IMG_VOID MetricsInitiateTiming(GLESContext *gc)
{
IMG_UINT32 ui32Loop;
/* Set it to zero the first frame */
/* memset( &gc->asTimes, 0, GLES_NUM_TIMERS*sizeof(Temporal_Data) );*/
for(ui32Loop=0; ui32Loop < (GLES_NUM_TIMERS); ui32Loop++)
{
gc->asTimes[ui32Loop].ui32Total = 0;
gc->asTimes[ui32Loop].ui32Count = 0;
}
#if defined(__SH4__)
{
/* timer control register */
// clock / 1024 when TIMER_DIVISOR = 4
// underflow int disabled
// we get approx 38 uS per timer tick
TCR_2 = TIMER_DIVISOR;
/* reset the timer counter to 0 */
TCOR_2 = TCNT_2 = (unsigned int)0xffffffff;
/* start timer 2 */
TST_REG |= (unsigned char)0x04;
}
#endif
if(!gc->fCPUSpeed)
{
GET_TICK_FREQ(gc->fCPUSpeed);
if(!gc->fCPUSpeed)
{
DPFDEV((DBG_MESSAGE, "Failed to get CPU Frequence"));
}
else
{
gc->fCPUSpeed = 1000.0f/gc->fCPUSpeed;
}
}
}
/***********************************************************************************
Function Name : MetricsOutputTotals
Inputs : -
Outputs : -
Returns : -
Description : Outputs all collected metrics information
************************************************************************************/
IMG_VOID MetricsOutputTotals(GLESContext *gc)
{
IMG_FLOAT fCopyImgCall=0, fCopyImgFrame=0;
IMG_FLOAT fTexAllocateCall=0, fTexAllocateFrame=0;
IMG_FLOAT fTexTranslateCall=0, fTexTranslateFrame=0, fTexTranslateRate;
IMG_FLOAT fTexLoadGhostCall=0, fTexLoadGhostFrame=0;
IMG_FLOAT fTexReadbackCall=0, fTexReadbackFrame=0;
IMG_FLOAT fLoadCall=0, fLoadFrame=0, fLoadRate=0;
IMG_FLOAT fSubLoadCall=0, fSubLoadFrame=0, fSubLoadRate=0;
IMG_FLOAT fCompLoadCall=0, fCompLoadFrame=0, fCompLoadRate=0;
IMG_FLOAT fCompSubLoadCall=0, fCompSubLoadFrame=0, fCompSubLoadRate=0;
IMG_FLOAT fWaitForHW=0, fTotalDrawTime=0;
IMG_UINT32 ui32Frames, ui32TotalDrawCalls;
IMG_UINT32 ui32Loop;
IMG_FLOAT fSlavePortMB, fSlavePortSeconds;
IMG_FLOAT fTotalDriverTime;
for(ui32Loop=0; ui32Loop < GLES_NUM_TIMERS; ui32Loop++)
{
if(gc->asTimes[ui32Loop].ui32Count & 0x80000000L)
{
DPFMETRIC(("Warning: Timer %d in ON position", ui32Loop));
gc->asTimes[ui32Loop].ui32Count &= 0x7FFFFFFFL;
}
}
fTotalDriverTime = 0;
for(ui32Loop=GLES_TIMES_glActiveTexture; ui32Loop<=GLES_TIMES_glColorMaterial; ui32Loop++)
{
fTotalDriverTime += gc->asTimes[ui32Loop].ui32Total*gc->fCPUSpeed;
}
ui32Frames = gc->asTimes[GLES_TIMER_FLUSH_HW_TIME].ui32Count;
fWaitForHW = ( gc->asTimes[GLES_TIMER_WAITING_FOR_3D_TIME].ui32Total +
gc->asTimes[GLES_TIMES_WAIT_FOR_ACQUIRE].ui32Total)* gc->fCPUSpeed;
fTotalDrawTime = ( gc->asTimes[GLES_TIMER_POINTLIST_TIME].ui32Total +
gc->asTimes[GLES_TIMER_LINES_TIME].ui32Total +
gc->asTimes[GLES_TIMER_LINESTRIP_TIME].ui32Total +
gc->asTimes[GLES_TIMER_LINELOOP_TIME].ui32Total +
gc->asTimes[GLES_TIMER_TRILIST_TIME].ui32Total +
gc->asTimes[GLES_TIMER_TRISTRIP_TIME].ui32Total +
gc->asTimes[GLES_TIMER_TRIFAN_TIME].ui32Total)* gc->fCPUSpeed;
ui32TotalDrawCalls = gc->asTimes[GLES_TIMER_POINTLIST_TIME].ui32Count +
gc->asTimes[GLES_TIMER_LINES_TIME].ui32Count +
gc->asTimes[GLES_TIMER_LINESTRIP_TIME].ui32Count +
gc->asTimes[GLES_TIMER_LINELOOP_TIME].ui32Count +
gc->asTimes[GLES_TIMER_TRILIST_TIME].ui32Count +
gc->asTimes[GLES_TIMER_TRISTRIP_TIME].ui32Count +
gc->asTimes[GLES_TIMER_TRIFAN_TIME].ui32Count;
/* Dump out the data */
#define BROKEN_FLOAT_PRINTF 1
#if BROKEN_FLOAT_PRINTF
if(ui32Frames)
{
DPFMETRIC((" ******* ALL TIMES uS x 10 *******"));
DPFMETRIC((" Total Frames %10d", ui32Frames));
DPFMETRIC((" Average Elapsed Time per Frame (uSx10) %10d", (int)(10000.0f*gc->asTimes[GLES_TIMER_TOTAL_FRAME_TIME].fStack / ui32Frames)));
DPFMETRIC((" Average Driver Time per Frame (uSx10) %10d", (int)(10000.0f*fTotalDriverTime / ui32Frames)));
if(gc->asTimes[GLES_TIMER_TOTAL_FRAME_TIME].fStack)
DPFMETRIC((" Estimated FPS (x100) %10d",(int)(100000.0f*ui32Frames/gc->asTimes[GLES_TIMER_TOTAL_FRAME_TIME].fStack)));
DPFMETRIC((" Statistics per frame [Calls/Time(uSx10)]"));
DPFMETRIC((" Total Prepare to draw %10d/%10d", gc->asTimes[GLES_TIMER_PREPARE_TO_DRAW_TIME].ui32Count/ui32Frames, (int)(10000.0f*gc->asTimes[GLES_TIMER_PREPARE_TO_DRAW_TIME].ui32Total*gc->fCPUSpeed/ui32Frames)));
DPFMETRIC((" inc: Total Wait for HW %10d/%10d", gc->asTimes[GLES_TIMES_WAIT_FOR_ACQUIRE].ui32Count/ui32Frames, (int)(10000.0f*fWaitForHW/ui32Frames)));
DPFMETRIC((" Total Validates %10d/%10d", gc->asTimes[GLES_TIMER_VALIDATE_TIME].ui32Count/ui32Frames, (int)(10000.0f*gc->asTimes[GLES_TIMER_VALIDATE_TIME].ui32Total*gc->fCPUSpeed/ui32Frames)));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -